动画画布以无限动画化噪声,以在 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);
}

更新于:2020-03-04

77 次观看

开始你的 事业

完成课程即可获得认证

开始
广告
© . All rights reserved.