aboutsummaryrefslogtreecommitdiff
path: root/particle.js
diff options
context:
space:
mode:
authorNat Lasseter <Nat Lasseter nathan@bytemark.co.uk>2017-06-27 14:43:16 +0100
committerNat Lasseter <Nat Lasseter nathan@bytemark.co.uk>2017-06-27 14:43:16 +0100
commit993442813dbee7805ef18146113872cae5892e99 (patch)
treea5994824818eabc55765ac995a8262d0ef2be62f /particle.js
Initial Commit
Diffstat (limited to 'particle.js')
-rw-r--r--particle.js30
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;
+ }
+}