-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparticle.js
38 lines (36 loc) · 1.03 KB
/
particle.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
function Particle(spos, angle, a, b, c) {
this.pos = createVector(spos.x, spos.y);
this.vel = p5.Vector.fromAngle(angle);
this.vel.mult(random(1, 10));
this.h = random(100, 250);
this.lastPos = [];
this.opacity = 100;
this.rot = random(-PI / 15, PI / 15);
this.update = function() {
this.lastPos.push(createVector(this.pos.x, this.pos.y));
if (this.lastPos.length > 8) {
this.lastPos.splice(0, 1);
}
this.pos.add(this.vel);
this.vel.mult(0.7);
this.vel.rotate(this.rot);
this.opacity -= 5;
}
this.render = function() {
push();
colorMode(RGB);
strokeWeight(2);
for (var i = this.lastPos.length - 1; i > 0; i--) {
stroke(a, b, c);
if (i === 0) {
line(this.lastPos[i].x, this.lastPos[i].y, this.pos.x, this.pos.y);
} else {
line(this.lastPos[i].x, this.lastPos[i].y, this.lastPos[i - 1].x, this.lastPos[i - 1].y);
}
}
stroke(150, 100, 255);
//stroke(this.h, 100, this.opacity);
//point(this.pos.x, this.pos.y);
pop();
}
}