Created
April 1, 2012 21:56
-
-
Save davidkaneda/2279058 to your computer and use it in GitHub Desktop.
Noise in Canvas + JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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