aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNat Lasseter <Nat Lasseter nathan@bytemark.co.uk>2017-06-29 10:57:11 +0100
committerNat Lasseter <Nat Lasseter nathan@bytemark.co.uk>2017-06-29 10:57:11 +0100
commit66d0a0b2e2531b61ef513b68c41128aa2df4a95e (patch)
tree3b9c2e162fa57b1b4c02058e0e4f09794d8c8bd2
parent8273006bf3923acf35490e2fa35e8da437cc5751 (diff)
start of work on p-p collisionsHEADmaster
-rw-r--r--particle.js8
-rw-r--r--sketch.js5
2 files changed, 13 insertions, 0 deletions
diff --git a/particle.js b/particle.js
index bfafa87..fc7d249 100644
--- a/particle.js
+++ b/particle.js
@@ -49,4 +49,12 @@ function Particle(x, y, m, c) {
dist(x1, y1, x2, y2)
) < 2;
}
+
+ this.collide = function(otherp) {
+ var dist = function(x1, y1, x2, y2) {
+ return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
+ };
+
+ return dist(this.pos.x, this.pos.y, otherp.pos.x, otherp.pos.y) < this.mass + otherp.mass;
+ }
}
diff --git a/sketch.js b/sketch.js
index 473c192..34fb7b5 100644
--- a/sketch.js
+++ b/sketch.js
@@ -32,6 +32,11 @@ function draw() {
ps[i].reflect(createVector(0.25*wid, -0.25*hei), 5);
}
+ for(var j = ps.length - 1; j >= 0; j--) {
+ if(i != j && ps[i].collide(ps[j]))
+ console.log("COLLIDE" + ps[i] + ps[j]);
+ }
+
if (ps[i].pos.y >= hei)
ps.splice(i, 1);
}