xxxxxxxxxx
35
// The Nature of Code
// Daniel Shiffman
// http://natureofcode.com
let stuff = [];
function setup() {
createCanvas(420, 320);
for (let i = 0; i < 20; i++) {
let x = random(width);
let y = random(height);
if (random(1) < 0.5) {
stuff.push(new Particle(x,y));
} else {
stuff.push(new Square(x,y));
}
}
}
function draw() {
background(0);
for (let i = 0; i < stuff.length; i++) {
let thing = stuff[i];
let gravity = createVector(0, 0.1);
thing.applyForce(gravity);
if (mouseIsPressed) {
let wind = createVector(0.1, 0);
thing.applyForce(wind);
}
thing.update();
thing.checkEdges();
thing.display();
}
}