xxxxxxxxxx
48
class Photon {
constructor(x, y, xSpeed, ySpeed,photonColour,trail,trailColour,trailRes) {
this.position = createVector(x, y)
this.velocity = createVector(xSpeed,ySpeed)
this.velocity.setMag(c)
this.mass = 0.5
//0.39269943999
this.draw = 0
this.photonColour = photonColour
this.trail = trail
this.trailColour = trailColour
this.trailRes = trailRes
this.history = []
}
show() {
if (this.draw == 0 && this.position.x > 0 && this.position.x < width && this.position.y > 0 && this.position.y < height) {
strokeWeight(2)
stroke(this.photonColour)
point(this.position.x, this.position.y)
}
if (((this.trail == 'On') || (this.trail == 'After' && this.draw == 2))) {
strokeWeight(1)
stroke(this.trailColour,75)
noFill()
beginShape()
for (let i = 0; i < this.history.length - 1; i += 2) {
vertex(this.history[i].x,this.history[i].y)
}
endShape()
}
}
update() {
if (this.draw == 0) {
if (frameCount % 2 == 0 && this.position.x > -15 && this.position.x < width + 15 && this.position.y > -15 && this.position.y < height + 15) {
this.history.push(this.position.copy())
}
let dV = this.velocity.copy()
dV.mult(dt)
this.position.add(dV)
}
}
}