diff options
Diffstat (limited to 'particle.js')
-rw-r--r-- | particle.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/particle.js b/particle.js new file mode 100644 index 0000000..66f4f6e --- /dev/null +++ b/particle.js @@ -0,0 +1,30 @@ +function Particle(x, y, m, c) { + this.pos = createVector(x, y); + this.vel = createVector(0, 0); + this.acc = createVector(0, 0); + this.colour = c; + this.mass = m; + + this.applyForce = function(force) { + this.acc.add(p5.Vector.div(force, this.mass)); + } + + this.update = function() { + this.vel.add(this.acc); + this.pos.add(this.vel); + this.acc.mult(0); + + if (this.pos.x <= 0 || this.pos.x >= wid) + this.vel.x = -this.vel.x; + if (this.pos.y <= 0) + this.vel.y = -this.vel.y; + } + + this.show = function() { + point(this.pos.x, this.pos.y); + } + + this.gone = function() { + return this.pos.y >= hei; + } +} |