Hello @hareti,
See these issues and workaround/fix:
- Copying PGraphics to PImage using .get() or .copy() clears PGraphics object, if the renderer is P2D · Issue #681 · benfry/processing4 · GitHub
- Second beginDraw / endDraw call clears PGraphics object when created w/ P2D · Issue #641 · benfry/processing4 · GitHub < Above refers to this
From issue above:
// ---- include to fix ----
pg.beginDraw();
pg.endDraw();
// ------------------------
Your code saves the expected PNG files with the above added.
I have encountered this issue in the past:
:)