-
Notifications
You must be signed in to change notification settings - Fork 3
/
Particle.pde
51 lines (39 loc) · 1.05 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
class Particle extends Mover {
int diameter = 5;
float lifespan;
PVector initialPosition;
float intensity;
Particle (PVector loc) {
location = loc.copy();
acceleration = new PVector (0f, 0.05f);
intensity = 1;
velocity = new PVector (randomGaussian() * intensity, random (-2, 0) * 3);
initialPosition = location.copy();
lifespan = random (200, 255);
strokeColor = 255;
fillColor = color (200, 0, 0);
}
void update (int delta) {
velocity.add (acceleration);
location.add (velocity);
lifespan -= 2.0;
}
void display() {
stroke (strokeColor, lifespan);
fill (fillColor, lifespan);
pushMatrix();
translate (location.x, location.y);
ellipse (0, 0, diameter, diameter);
popMatrix();
}
boolean isDead () {
return lifespan <= 0.0;
}
void reset () {
location.x = initialPosition.x;
location.y = initialPosition.y;
velocity.x = randomGaussian() * intensity;
velocity.y = random (-2, 0);
lifespan = random (200, 255);
}
}