Skip to content

Instantly share code, notes, and snippets.

@JavaScript-Packer
Last active August 29, 2015 14:27
Show Gist options
  • Save JavaScript-Packer/2792badbb05344bada9f to your computer and use it in GitHub Desktop.
Save JavaScript-Packer/2792badbb05344bada9f to your computer and use it in GitHub Desktop.
THE ALWAYS CHANGING BACKGROUND EFFECT, CHANGES EVERYTIME YOU RELOAD THE PAGE. Demo on http://codepen.io/samples/full/LVKmxg/
<body><h1>www.WHAK.com</h1>
<canvas id='c' style="position:fixed;top:0;left:0;z-index:-420;width:100%;height:100%"></canvas>
THE ALWAYS CHANGING BACKGROUND EFFECT<P>CHANGES EVERYTIME YOU RELOAD THE PAGE</P>
<script>
var rate=(Math.floor(Math.random() * 20) + 4);
function a() {
var u, n, e, r = 0;
for (u = 0; d > u; u++) {
for (n = 0; g > n; n++) {
e = .5 < Math.random() ? 255 : 0, h.data[r] = e, h.data[r + 1] = e, h.data[r + 2] = e,
r += 4;
}
}
k.putImageData(h, 0, 0), l++, setTimeout(a, 100);
}
var h, n, p, q, t = document.getElementById("c"), k = t.getContext("2d"), d = t.width = 640, g = t.height = 480, m = new Date().getTime(), l = 0;
for (h = k.createImageData(d, g), p = n = 0; d > p; p++) {
for (q = 0; g > q; q++) {
h.data[n + 3] = 50, n += rate;
}
}
a();
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment