Here's an example code snippet that creates a square pulse animation using Canvas and requestAnimationFrame:
index.tsx926 chars39 lines
This code creates a canvas element and uses its 2D context to draw a square with a variable radius that changes over time. The animation is achieved by calling the requestAnimationFrame
method inside the draw
function, which causes the function to be called again and again, creating a continuous loop of frames. The growing
variable keeps track of whether the radius should be increasing or decreasing, and the maxRadius
variable sets an upper limit to the size of the square.
gistlibby LogSnag