62 <canvas id="canvas" width=400 height=400></canvas> </body> <script> const btndownload = document.querySelector("#animasi"); btndownload.addEventListener("click",function(){ var canvas=document.getElementById("canvas"); var ctx=canvas.getContext("2d"); var cw=canvas.width; var ch=canvas.height; requestAnimationFrame(animate); function animate(currentTime) { var x=Math.random()*canvas.width; var y=Math.random()*canvas.height; ctx.fillRect(x,y,30,30); ctx.fillStyle='#'+Math.floor(Math.random()*16777215) .toString(16); requestAnimationFrame(animate); } }); </script> </html>
RkJQdWJsaXNoZXIy MTM3NDc5MQ==