-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathParticle.pde
85 lines (72 loc) · 2.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
class Particle {
PVector velocity;
float lifespan = 70;
PShape part;
float partSize;
color[] part_colors = {color(255,0,0), color(0,255,0), color(0,0,255), color(0,0,255)};
color part_color_id;
PVector gravity = new PVector(0,0.3);
public Particle() {
partSize = random(20,200);
part_color_id = 0;
PShape part1 = createShape();
part1.beginShape(QUAD);
part1.noStroke();
part1.texture(sprite);
part1.fill(0);
part1.emissive(part_colors[part_color_id]);
part1.normal(0, 0, 1);
part1.vertex(-partSize/2, -partSize/2, 0, 0);
part1.vertex(+partSize/2, -partSize/2, sprite.width, 0);
part1.vertex(+partSize/2, +partSize/2, sprite.width, sprite.height);
part1.vertex(-partSize/2, +partSize/2, 0, sprite.height);
part1.endShape();
PShape part2 = createShape();
part2.beginShape(QUAD);
part2.noStroke();
part2.texture(sprite);
part2.fill(0);
part2.emissive(part_colors[part_color_id]);
part2.normal(0, 0, 1);
part2.vertex(0, -partSize/2, -partSize/2, 0, 0);
part2.vertex(0, +partSize/2, -partSize/2, sprite.width, 0);
part2.vertex(0, +partSize/2, +partSize/2, sprite.width, sprite.height);
part2.vertex(0, -partSize/2, +partSize/2, 0, sprite.height);
part2.endShape();
part = createShape(GROUP);
part.addChild(part1);
part.addChild(part2);
rebirth(0,0,0);
lifespan = random(255);
}
public PShape getShape() {
return part;
}
public void rebirth(float x, float y, float z) {
float a = random(TWO_PI);
float b = random(TWO_PI);
float speed = random(0.5,2);
velocity = new PVector(cos(a), sin(a), cos(b));
velocity.mult(speed);
lifespan = 255;
part.resetMatrix();
part.translate(x, y, z);
}
boolean isDead() {
if (lifespan < 0) {
return true;
} else {
return false;
}
}
public void changeColor() {
part_color_id = (part_color_id+1) % part_colors.length;
}
public void update() {
lifespan = lifespan - 1;
velocity.add(gravity);
color c = part_colors[part_color_id];
part.setTint(color(red(c),green(c),blue(c),lifespan));
part.translate(velocity.x, velocity.y, velocity.z);
}
}