18. function simulate() {
var now = new Date(),
interval = (now - lastSim) / 1000;
// loop over every particle in the scene
for(var i=0; i < scene.length; i++) {
scene[i].advanceSimulationBy(interval);
}
lastSim = now;
};
21. (function spawn() {
// Make a new particle
var p = new Particle();
p.fill = cycleColour();
p.radius = cycleSize();
p.dx = (Math.random() - 0.5) * initialVelocity;
p.dy = (Math.random() + 1.0) * initialVelocity / -2;
// Add it to the scene
scene.push(p);
// Do it again in 100ms
setTimeout(spawn, 100);
// Limit the scene size
if(scene.length > maxParticles) {
scene.shift();
}
})();