javascript – How to update the canvas?

Question:

On a canvas, I've added 10 small squares, but I also want to be able to change the position of these squares continuously, and have this change drawn on the canvas every time I do it (I don't necessarily need an animation, just understand how I can update the canvas whenever I want to. ). How can I do this?

Answer:

Use context.clearRect to clear the canvas or just the square. And then redraw.

Scroll to Top