aboutsummaryrefslogtreecommitdiff
path: root/sketch.js
blob: 3cce527f3cc8e7c232a1de988f97d82a6efad973 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var ps = [];
var gravity;
var wid = 800;
var hei = 600;

function setup() {
  createCanvas(wid, hei);
  colorMode(HSL);
  gravity = createVector(0, 5);
}

function draw() {
  background(0);

  for(var i = ps.length - 1; i >= 0; i--) {
    ps[i].applyForce(gravity);
    ps[i].update();

    stroke(ps[i].colour);
    strokeWeight(ps[i].mass);
    ps[i].show();

    if (ps[i].gone()) {
     ps.splice(i, 1);
    }
  }

  if (mouseIsPressed) {
    var p = new Particle(
          mouseX, mouseY, random(2, 8),
          color(random(0, 360), random(90, 100), random(50, 100))
        );
    p.applyForce(createVector(random(-40, 40), random(-150, 0)));
    ps.push(p);
  }
}