-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathparticle.js
49 lines (45 loc) · 1.2 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
39
40
41
42
43
44
45
46
47
48
49
class Particle {
constructor(x, y, color) {
this.x = x;
this.y = y;
this.size = random(1, 4 * sizeSlider.value());
this.speed = random(-speedSlider.value(), speedSlider.value());
this.color = color;
this.len = 64;
}
updateStatic() {
var theta =
noise(this.x / noiseScale.value(), this.y / noiseScale.value()) *
noiseStrength.value();
this.x += cos(theta) * this.speed;
this.y += sin(theta) * this.speed;
vertex(this.x, this.y);
}
displayStatic() {
noFill();
strokeWeight(this.size);
stroke(this.color);
beginShape();
for (let i = 0; i < this.len * speedSlider.value(); i++) {
var theta =
noise(this.x / noiseScale.value(), this.y / noiseScale.value()) *
noiseStrength.value();
this.x += cos(theta) * this.speed;
this.y += sin(theta) * this.speed;
vertex(this.x, this.y);
}
endShape();
}
show() {
strokeWeight(this.size);
stroke(this.color);
point(this.x, this.y);
}
update() {
var theta =
noise(this.x / noiseScale.value(), this.y / noiseScale.value()) *
noiseStrength.value();
this.x += cos(theta) * this.speed;
this.y += sin(theta) * this.speed;
}
}