This repository has been archived by the owner on Oct 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdot.js
54 lines (54 loc) · 1.5 KB
/
dot.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
53
54
class Dot {
constructor() {
this.x = random(0, width);
this.y = random(0, height);
this.h = floor(random(0, 359));
this.vel = createVector(0, 0);
this.color = color("hsl(" + this.h + ", 100%, 50%)");
}
show() {
this.color = color("hsl(" + this.h + ", 100%, 50%)");
stroke(this.color);
strokeWeight(4);
point(this.x, this.y);
this.x += this.vel.x;
this.y += this.vel.y;
if (sound && sound.isPlaying()) {
this.vel.x += seq[change][0]
this.vel.y += seq[change][1]
}
if (this.h <= 0) {
this.h += 360;
} else if (this.h >= 360) {
this.h -= 360;
}
if (this.x > width) {
this.x -= width;
} else if (this.x < 0) {
this.x += width;
}
if (this.y > height) {
this.y -= height;
} else if (this.y < 0) {
this.y += height;
}
if (mouseButton == LEFT && mouseIsPressed) {
this.dx = mouseX - this.x;
this.dy = mouseY - this.y;
this.ds = Math.hypot(this.dx, this.dy);
this.vel.x += this.dx / this.ds;
this.vel.y += this.dy / this.ds;
} else if (mouseButton == RIGHT && mouseIsPressed) {
this.dx = mouseX - this.x;
this.dy = mouseY - this.y;
this.ds = Math.hypot(this.dx, this.dy);
this.vel.x -= this.dx / this.ds;
this.vel.y -= this.dy / this.ds;
}
let s = parseInt(driftSpeed.value()) * 0.01;
this.vel.x += (Math.random() - 0.5) * s;
this.vel.y += (Math.random() - 0.5) * s;
this.vel.x *= drag;
this.vel.y *= drag;
}
}