body {
background: #333;
}
canvas {
position: relative;
margin: 0 auto;
display: block;
}
var rc = 0,
seed = 30,
MAX_RAND = 0xffffff;
function idxRand(nth) {
if (nth != null) rc = nth;
rc++;
return Math.abs(Math.sin(seed * rc) * MAX_RAND);
}
var firstFour = [idxRand(), idxRand(), idxRand(), idxRand()],
second = idxRand(1),
fourth = idxRand(3);
console.log(firstFour);
console.log(second);
console.log(fourth);
var canvas = document.createElement("canvas"),
c = canvas.getContext("2d");
canvas.width = 400;
canvas.height = 300;
c.fillStyle = "black";
c.fillRect(0, 0, canvas.width, canvas.height);
document.body.appendChild(canvas);
for (var i = 0; i < 300; i++) {
c.fillStyle = "red";
c.fillRect(idxRand() % 200, i, 4, 4);
c.fillStyle = "green";
c.fillRect(200 + Math.random() * 200, i, 4, 4);
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.