aboutsummaryrefslogtreecommitdiff
path: root/particle.js
diff options
context:
space:
mode:
authorNat Lasseter <Nat Lasseter nathan@bytemark.co.uk>2017-06-28 21:11:50 +0100
committerNat Lasseter <Nat Lasseter nathan@bytemark.co.uk>2017-06-28 21:11:50 +0100
commit7757f565bf0f7694c6de57a2795117521c92e5a7 (patch)
tree167f7c52c37bd25cf5119282111939a626c1a97a /particle.js
parent1c2acd3320963884821d52530b24637abd88354f (diff)
Some bouncy lines
Diffstat (limited to 'particle.js')
-rw-r--r--particle.js20
1 files changed, 18 insertions, 2 deletions
diff --git a/particle.js b/particle.js
index c62dd47..b6b116c 100644
--- a/particle.js
+++ b/particle.js
@@ -30,7 +30,23 @@ function Particle(x, y, m, c) {
point(this.pos.x, this.pos.y);
}
- this.gone = function() {
- return this.pos.y >= hei;
+ this.reflect = function(surface_vector, elastic_coeff) {
+ var normal = surface_vector
+ .copy()
+ .normalize()
+ .rotate(PI/2);
+ this.vel = this.vel.sub(p5.Vector.mult(normal, 2 * this.vel.dot(normal))).mult(elastic_coeff);
+ }
+
+ this.online = function(x1, y1, x2, y2) {
+ var dist = function(x1, y1, x2, y2) {
+ return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
+ };
+
+ return Math.abs(
+ dist(x1, y1, this.pos.x, this.pos.y) +
+ dist(this.pos.x, this.pos.y, x2, y2) -
+ dist(x1, y1, x2, y2)
+ ) < 1;
}
}