clearing a canvas partially | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

clearing a canvas partially

hypothetical i have a canvas, and that canvas is ontop of an image, the canvas is being drawn on constantly per frame... how do i clear the canvas partially, not completely clearing it, the parts being cleared should not be completely cleared, like slightly lower the opacity, and the image is needed to be visible except its drawn over in the canvas. (drawing the image on the canvas is not viable)

6th Mar 2024, 12:21 PM
Yeeter
Yeeter - avatar
3 Answers
+ 1
It sounds to me like you may need a buffer canvas. Have the main canvas hold the image. Place the buffer canvas directly over the main canvas. Apply changes to the buffer canvas during the click down event and then on click up apply the buffer canvas to the main and clear the buffer. With the right fiddling, you get an undo-redo mechanism out of it.
6th Mar 2024, 2:55 PM
Sam
0
clearRect() only clears the specified part of the canvas. https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/clearRect
6th Mar 2024, 1:01 PM
Lisa
Lisa - avatar
0
You can use reset() to clear the hole canvas.
6th Mar 2024, 3:00 PM
Jan
Jan - avatar