为画布添加动画以无限地流动噪声,从而在 HTML 中形成动画效果
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);
}
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP