var w, h, ctx, tot = 41; function reset() { w = window.innerWidth; h = window.innerHeight; c.width = w; c.height = h; ctx = c.getContext('2d'); tot=(Math.max(w, h)/40)|0 } var colors=['#ff0000', '#ff7f00', '#ffff00', '#00ff00', '#0000ff', '#4b0082', '#8b00ff']; reset(); function anim() { window.requestAnimationFrame(anim); ctx.fillStyle = 'rgba(0, 0, 0, 0.02)'; ctx.fillRect(0, 0, w, h); for (var i = 0; i < tot; ++i) { var x = (Math.random() * w) | 0; var y = (Math.random() * h) | 0; var r = (Math.random() * i) | 0 + 3; ctx.fillStyle = colors[i % colors.length]; ctx.beginPath(); ctx.arc(x, y, r, 0, Math.PI * 2); ctx.fill(); ctx.closePath(); ctx.fillStyle = 'rgba(0, 0, 0, 0.6)'; ctx.beginPath(); ctx.arc(x, y, r - 2, 0, Math.PI * 2); ctx.fill(); ctx.closePath(); } } anim(); window.onresize = reset;