Last active
July 31, 2024 06:21
-
-
Save lxchurbakov/50e9f8e25215cc0a26dd7fa2df146327 to your computer and use it in GitHub Desktop.
HTML5 Canvas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const canvas = canvasRef.current; | |
const pixelRatio = window.devicePixelRatio || 1; | |
const rect = canvas.getBoundingClientRect(); | |
canvas.style.width = rect.width + 'px'; | |
canvas.style.height = rect.height + 'px'; | |
canvas.width = rect.width * pixelRatio; | |
canvas.height = rect.height * pixelRatio; | |
const context = canvas.getContext('2d'); | |
context.scale(pixelRatio, pixelRatio); | |
const render = () => { | |
context.clearRect(0, 0, rect.width, rect.height); | |
// | |
requestAnimationFrame(render); | |
}; | |
requestAnimationFrame(render); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment