From 993442813dbee7805ef18146113872cae5892e99 Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Tue, 27 Jun 2017 14:43:16 +0100 Subject: Initial Commit --- particle.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 particle.js (limited to 'particle.js') 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; + } +} -- cgit v1.2.1