My first experiment is a simple one, just some randomly updating pixels on a screen.
Here is the .js code:
function setPixel(bitmapData, x, y, r, g, b, a) { index = (x + y * bitmapData.width) * 4; bitmapData.data[index+0] = r; bitmapData.data[index+1] = g; bitmapData.data[index+2] = b; bitmapData.data[index+3] = a; } element = document.getElementById("bitmap"); canvas = element.getContext("2d"); width = parseInt(element.getAttribute("width")); height = parseInt(element.getAttribute("height")); setInterval('update()',30); function update() { bitmap = canvas.createImageData(width,height); for (i = 0; i < 10000; i++) { x = parseInt(Math.random() * width); y = parseInt(Math.random() * height); r = parseInt(Math.random() * 256); g = parseInt(Math.random() * 256); b = parseInt(Math.random() * 256); setPixel(bitmap, x, y, r, g, b, 0xff); } canvas.putImageData(bitmap, 0, 0); }
No comments:
Post a Comment