-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathParticle.pde
48 lines (40 loc) · 952 Bytes
/
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
//----------------------------------------------------------
// Particle class
//----------------------------------------------------------
import java.util.Random;
class Particle {
float x, y, size, fade, lifeSpan;
color c;
PVector pos, vel;
Particle(float x, float y, float size, float fade, color[] colors){
this.x = x;
this.y = y;
this.size = size;
this.fade = fade;
lifeSpan = 255.0;
pos = new PVector(x, y);
vel = new PVector(random(-2.2, 2.2), random(-2.2, 2.2));
Random generator = new Random();
int randomIndex = generator.nextInt(colors.length);
c = colors[randomIndex];
}
void update(){
pos.add(vel);
lifeSpan-=fade;
}
void display(){
fill(c,lifeSpan);
ellipse(pos.x, pos.y, size, size);
}
void execute(){
update();
display();
}
boolean isDead() {
if(lifeSpan<0){
return true;
} else {
return false;
}
}
}