Skip to content

Instantly share code, notes, and snippets.

@DavidQL
Created February 2, 2011 23:51
Show Gist options
  • Save DavidQL/808762 to your computer and use it in GitHub Desktop.
Save DavidQL/808762 to your computer and use it in GitHub Desktop.
backgroundNoise: function() {
// Fancy noisy background with canvas
if (!!!document.createElement('canvas').getContext) {
return;
}
var canvas = document.createElement("canvas");
canvas.width = 100;
canvas.height = 100;
var ctx = canvas.getContext("2d");
var x, y;
for (x=0; x<canvas.width; x += 1) {
for (y=0; y<canvas.height; y += 1) {
var r = Math.floor(Math.random() * 150);
var g = Math.floor(Math.random() * 150);
var b = Math.floor(Math.random() * 150);
ctx.fillStyle = "rgba("+r+","+g+","+b+",0.1)";
ctx.fillRect(x, y, 1, 1);
}
}
$('body').css({'background-image': "url("+canvas.toDataURL("image/png")+")"});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment