Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <canvas id="canvas"></canvas>
- <script>
- const canvas = document.getElementById("canvas")
- const ctx = canvas.getContext('2d')
- ctx.fillStyle = "#ff0000"
- ctx.fillRect(20, 20, 100, 100)
- const canvasurl = canvas.toDataURL('image/png')
- let bg = new Image()
- bg.src = canvasurl
- ctx.drawImage(bg, 0, 0)
- let x = 0
- const main = () => {
- ctx.fillStyle = "#000000"
- ctx.fillRect(0, 0, canvas.width, canvas.height)
- ctx.drawImage(bg, 0, 0)
- ctx.fillStyle = "#00ff00"
- ctx.fillRect(x, 40, 20, 20)
- x += 0.3
- requestAnimationFrame(main)
- }
- main()
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement