Image noise: Difference between revisions

Content deleted Content added
No edit summary
Line 345: Line 345:
var frame_count = 0;
var frame_count = 0;
ctx.font = 'normal 400 24px/2 Unknown Font, sans-serif';
ctx.font = 'normal 400 24px/2 Unknown Font, sans-serif';
var img = ctx.createImageData(w,h);


function animate() {
function animate() {
ctx.clearRect(0, 0, w, h);

ctx.fillStyle = "black";
for (var x = 0; x < w; x++)
for (var x = 0; x < w; x++)
{
for (var y = 0; y < h; y++)
for (var y = 0; y < h; y++)
if (Math.random() > 0.5)
{
ctx.fillRect(x, y, 1, 1);
var index = 4* (x + w*y);
var value = (Math.random() > 0.5) ? 255 : 0;
img.data[index] = value;
img.data[index+1] = value;
img.data[index+2] = value;
img.data[index+3] = 255;
}
}
ctx.putImageData(img,0,0);


frame_count++;
frame_count++;
Line 364: Line 372:


animate();
animate();

</script>
</script>
</body>
</body>