-
Notifications
You must be signed in to change notification settings - Fork 0
/
Particle.pde
64 lines (53 loc) · 1.41 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
class Particle extends Node {
PVector size;
float rotation;
PShape shape;
PImage image;
PVector velocity;
color colorTint;
float opacity;
Particle(PVector origin, PVector velocity, PVector size, float rotation, PShape shape) {
this(origin, velocity, size, rotation, shape, null);
}
Particle(PVector origin, PVector velocity, PVector size, float rotation, PImage image) {
this(origin, velocity, size, rotation, null, image);
}
Particle(PVector origin, PVector velocity, PVector size, float rotation, PShape shape, PImage image) {
this.origin = origin;
this.velocity = velocity;
this.size = size;
this.rotation = rotation;
this.shape = shape;
this.image = image;
this.colorTint = color(#ffffff);
this.opacity = 1.0;
this.updateBoundingBox();
}
void spawn() {
super.spawn();
particles.add(this);
}
void delete() {
super.delete();
particles.remove(this);
}
void updateBoundingBox() {
this.boundingBox = this.getBoundingBoxForRadius(max(this.size.x, this.size.y) / 2.0);
}
void OnTick() {
this.origin.add(this.velocity);
};
void OnDraw() {
noStroke();
translate(this.origin.x, this.origin.y);
rotate(this.rotation);
if (this.shape != null) {
fill(this.colorTint, this.opacity);
shape(this.shape, 0, 0, this.size.x, this.size.y);
}
if (this.image != null) {
tint(this.colorTint, this.opacity);
image(this.image, 0, 0, this.size.x, this.size.y);
}
}
}