Draw rectangles with the mouse, background refresh

There was an error Message because that Code was not meant to be executed. It just shows how to use a PGraphics to do what you are trying to achieve…

I can‘t Test it right now, but you can probably do exactly what you want to achieve by replacing in your first Code, the PImage buff with a PGraphics and changing the way you intitialize it, then adding another PImage variable and set the background of your PGraphics to be that image. It‘s 2 changed lines and 3 lines of Code added. That should do it… actually, remember to change the reference to PImage into PGraphics, so some more lines changed… and i‘m not sure wether you can use background(PGraphics), so you might have to use image(PGraphics, x, y, w, h);