-
Notifications
You must be signed in to change notification settings - Fork 0
/
Particle.pde
59 lines (52 loc) · 1.2 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
54
55
56
57
58
59
// A simple Particle class, renders the particle as an image
class Particle {
PVector loc;
PVector vel;
PVector acc;
float lifespan;
PImage img;
Particle(PVector l, PImage img_) {
acc = new PVector(0, 0);
float vx = randomGaussian()*0.3;
float vy = randomGaussian()*0.3;
vel = new PVector(vx, vy);
loc = l.copy();
lifespan = 70.0;
img = img_;
}
void run() {
update();
render();
}
// Method to apply a force vector to the Particle object
// Note we are ignoring "mass" here
void applyForce(PVector f) {
acc.add(f);
}
// Method to update position
void update() {
vel.add(acc);
loc.add(vel);
lifespan -= 2.5;
acc.mult(0); // clear Acceleration
}
// Method to display
void render() {
imageMode(CENTER);
tint(255, lifespan);
image(img, loc.x+OFFSETX, loc.y+OFFSETY);
noTint();
// Drawing a circle instead
// fill(255,lifespan);
// noStroke();
// ellipse(loc.x,loc.y,img.width,img.height);
}
// Is the particle still useful?
boolean isDead() {
if (lifespan <= 0.0) {
return true;
} else {
return false;
}
}
}