-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpartical.js
52 lines (46 loc) · 1.15 KB
/
partical.js
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
function Partical(x, y, hu, isFirework) {
this.pos = createVector(x, y);
this.lifespan = 255;
this.hu = hu
this.isFirework = isFirework
if (this.isFirework) {
this.vel = createVector(0, random(-12, -8));
} else {
this.vel = p5.Vector.random2D()
this.vel.mult(random(1,10))
}
this.acc = createVector(0, 0);
this.applyForce = function(force) {
this.acc.add(force)
}
this.update = function() {
if (!this.isFirework) {
this.vel.mult(0.87)
this.lifespan -= 4
}
this.vel.add(this.acc)
this.pos.add(this.vel)
this.acc.mult(0)
}
this.done = function () {
if (this.lifespan < 0) {
return true
} else {
return false
}
}
this.show = function() {
colorMode(HSB)
if (!this.isFirework) {
strokeWeight(2)
stroke(hu, 255, 255, this.lifespan)
} else {
strokeWeight(4)
stroke(hu, 255, 255)
}
point(this.pos.x, this.pos.y)
}
this.isOffbound = function () {
return this.pos.x < -1
}
}