-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStar.js
41 lines (35 loc) · 808 Bytes
/
Star.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
class Star {
x = 0;
y = 0;
z = 0;
pz = 0;
constructor() {
this.x = random(-width, width);
this.y = random(-height, height);
this.z = random(width);
this.pz = this.z;
}
update() {
this.z -= speed;
if (this.z < 1) {
this.x = random(-width, width);
this.y = random(-height, height);
this.z = width;
this.pz = this.z;
}
}
show() {
fill(255);
noStroke();
let sx = map(this.x / this.z, 0, 1, 0, width);
let sy = map(this.y / this.z, 0, 1, 0, height);
let r = map(this.z, 0, width, 5, 0);
ellipse(sx, sy, r, r);
let px = map(this.x / this.pz, 0, 1, 0, width);
let py = map(this.y / this.pz, 0, 1, 0, height);
this.pz = this.z;
stroke(255);
strokeWeight(r);
line(px, py, sx, sy);
}
}