Skip to content

Instantly share code, notes, and snippets.

@davidkaneda
Created April 1, 2012 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidkaneda/2279058 to your computer and use it in GitHub Desktop.
Save davidkaneda/2279058 to your computer and use it in GitHub Desktop.
Noise in Canvas + JS
var canvas = document.getElementById("acanvas");
var w = canvas.width = 200;
var h = canvas.height = 200;
var context = canvas.getContext("2d");
for(i=0;i<w;i++) {
for(j=0;j<h;j++) {
var num = Math.floor(Math.random()*255);
context.fillStyle = "rgb(" + num + "," + num + "," + num + ")";
context.fillRect(i, j, 0.1, 1);
}
}
$("#adiv").css ( {
"background": "url("+canvas.toDataURL()+")"
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment