fps = 30,
lastFrame = 0,
speed = 1,
- size = 5 + rand(10);
+ size = 5 + rand(10),
+ r = Math.random,
+ pi = Math.PI;
- var clear = !!(Math.random() > 0.5);
- var changeColor = !!(Math.random() > 0.5);
+ var clear = !!(r() > 0.5);
+ var changeColor = !!(r() > 0.5);
var items = Array(rand(10) + 6).fill(null).map(() => ({
x: rand(64),
y: rand(64),
- angle: Math.random() * 2 * Math.PI,
+ angle: r() * 2 * pi,
color: Array(3).fill(rand(256))
}));
var shapes = [square, circle, heart, chaos, lineChaos];
var position = positions[rand(positions.length)];
function rand (x) {
- return Math.floor(Math.random() * x);
+ return Math.floor(r() * x);
}
function square(item) {
var p = position(item);
context.beginPath();
- context.arc(p.x, p.y, size / 2, 0, 2 * Math.PI);
+ context.arc(p.x, p.y, size / 2, 0, 2 * pi);
context.fill();
}
context.fillRect(p.x, p.y, size, size);
context.beginPath();
- context.arc(p.x + size / 2, p.y, size / 2, 0, 2 * Math.PI, false);
+ context.arc(p.x + size / 2, p.y, size / 2, 0, 2 * pi, false);
context.fill();
context.closePath();
context.beginPath();
- context.arc(p.x + size, p.y + size / 2, size / 2, 0, 2 * Math.PI, false);
+ context.arc(p.x + size, p.y + size / 2, size / 2, 0, 2 * pi, false);
context.fill();
context.closePath();
}