aboutsummaryrefslogtreecommitdiff
path: root/sketch.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 /sketch.js
parent1c2acd3320963884821d52530b24637abd88354f (diff)
Some bouncy lines
Diffstat (limited to 'sketch.js')
-rw-r--r--sketch.js18
1 files changed, 14 insertions, 4 deletions
diff --git a/sketch.js b/sketch.js
index 2c6b9d3..ce3d1d1 100644
--- a/sketch.js
+++ b/sketch.js
@@ -13,6 +13,11 @@ function setup() {
function draw() {
background(0);
+ stroke(255);
+ strokeWeight(4);
+ line(0, 0.75*hei, 0.25*wid, hei);
+ line(0.75*wid, hei, wid, 0.75*hei);
+
for(var i = ps.length - 1; i >= 0; i--) {
ps[i].applyForce(gravity);
ps[i].applyDrag(air_resistance);
@@ -22,17 +27,22 @@ function draw() {
strokeWeight(ps[i].mass);
ps[i].show();
- if (ps[i].gone()) {
- ps.splice(i, 1);
+ if (ps[i].online(0, 0.75*hei, 0.25*wid, hei)) {
+ ps[i].reflect(createVector(0.25*wid, 0.25*hei), 5);
+ } else if (ps[i].online(0.75*wid, hei, wid, 0.75*hei)) {
+ ps[i].reflect(createVector(0.25*wid, -0.25*hei), 5);
}
+
+ if (ps[i].pos.y >= hei)
+ ps.splice(i, 1);
}
if (mouseIsPressed) {
var p = new Particle(
- mouseX, mouseY, random(2, 8),
+ mouseX, mouseY, random(2, 10),
color(random(0, 360), random(90, 100), random(50, 100))
);
- p.applyForce(createVector(random(-200, 200), random(-400, 0)));
+ p.applyForce(createVector(random(-250, 250), random(-500, 0)));
ps.push(p);
}
}