-
Notifications
You must be signed in to change notification settings - Fork 0
/
photon.js
57 lines (50 loc) · 1.04 KB
/
photon.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
55
56
57
class Photon {
constructor(x, y) {
this.pos = createVector(x, y);
this.startPos = createVector(x, y);
this.vel = createVector(-c, 0);
this.history = [];
this.stopped = false;
this.theta = PI;
}
stop() {
this.stopped = true;
}
update() {
if (!this.stopped) {
//if (frameCount % 5 == 0) {
this.history.push(this.pos.copy());
//}
const deltaV = this.vel.copy();
deltaV.mult(dt);
this.pos.add(deltaV);
}
if (this.history.length > 1000) {
this.history.splice(0, 1);
}
if (
this.pos.x < 0 ||
this.pos.x > width ||
this.pos.y < 0 ||
this.pos.y > height
) {
this.stop();
}
}
show(end) {
strokeWeight(4);
if (this.startPos.y > end && this.startPos.y < windowHeight - end) {
stroke(0);
} else {
stroke(255, 255, 128);
}
point(this.pos.x, this.pos.y);
strokeWeight(2);
noFill();
beginShape();
for (let v of this.history) {
vertex(v.x, v.y);
}
endShape();
}
}