- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Animating canvas to infinitely animate the noise to give the appearance of movement in HTML
The putImageData() method places the image data onto the canvas. To animate 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); }
Advertisements