putImageData() 方法将图像数据放置到画布上。为了使画布动画化,我们在主循环之外创建一个可重用的 ImageData 对象,
var ct = c.getContext("2d", {alpha: false}); // context without alpha channel. var a = ct.createImageData(c.width, c.height); var buffer = new Uint32Array(a.data.buffer); function loop() { noise(ct); requestAnimationFrame(loop) })() function noise(ct) { var l =buffer.length - 1; while(l--) buffer[l] = Math.random() <0.5 ?0 : -1>>0; ct.putImageData(a, 0, 0); }