Animate the canvas to infinitely animate noise to give the appearance of motion in HTML

王林
Release: 2023-08-26 09:13:04
forward
1175 people have browsed it

对画布进行动画处理以无限地对噪声进行动画处理,从而在 HTML 中呈现运动的外观

#putImageData() method places image data onto the canvas. To animate the canvas, we create a reusable ImageData object outside the main loop,

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); }
Copy after login

The above is the detailed content of Animate the canvas to infinitely animate noise to give the appearance of motion in HTML. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!