-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParticle.pde
53 lines (46 loc) · 1.42 KB
/
Particle.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
class Particle
{
PVector location; // current location
PVector destination; // destination
PVector repel; // repel vector
float rotS, rotC; // rotation spped sin/cos
float velocity; // velocity
float size; // size of the particle
boolean inTransit = false; // movement state of the particle
Particle(float x, float y)
{
location = new PVector(x,y);
destination = new PVector(width/2, height/2); // travelling to center of the screen
velocity = 0.0; // velocity
size = random(1, 4);
repel = new PVector();
}
void explode(float maxSpeed, float rotSpeed)
{
repel.set(random(-maxSpeed,+maxSpeed), random(-maxSpeed,+maxSpeed));
rotSpeed = radians(rotSpeed);
rotS = sin(rotSpeed);
rotC = cos(rotSpeed);
}
void update()
{
//tempV = PVector.lerp(location, destination, velocity);
//location.set(tempV);
location.lerp(destination, velocity);
// add repel vector, which will get smaller and smaller
location.add(repel);
repel.mult(0.9);
//repel.rotate(0.1);
// "manual" rotation
float xn = repel.x * rotC - repel.y * rotS;
float yn = repel.x * rotS + repel.y * rotC;
repel.set(xn, yn);
}
void display()
{
stroke(255);
int sizeScale = (int)random(1,2.5);
strokeWeight(2 * sizeScale);
point(location.x, location.y);
}
}