A
PGraphics
instance needs to be initialized w/
beginDraw
() &
endDraw
().
Also, you need to specify its own characteristics like
ellipseMode
(),
smooth
(), etc; apart from main screen surface!
Anyways, for recording PDFs, there's no need to create a separate
PGraphics
!
Here's your code w/o such:
import processing.pdf.*; final static boolean RECORD = true; final static int DIAM = 300; final static int STEP_X = 15, STEP_Y = 15; final static float FRACT = 1.15; final static color BG = #556270; final color[] palette = { #4ECDC4, #C7F464, #FF6B6B, #C44D58 }; void setup() { size(960, 645); noLoop(); smooth(); noStroke(); ellipseMode(CORNER); } void draw() { if (RECORD) { final String path = dataPath("frame." + frameCount + ".pdf"); beginRecord(PDF, path); // PDF record's own init: smooth(); noStroke(); ellipseMode(CORNER); } background (BG); final int xx = width; final int yy = height + DIAM; for (int y = STEP_Y; y < yy; y += DIAM + STEP_Y) { for (int x = STEP_X; x < xx; x += DIAM + STEP_X) { drawCircle(x, y, DIAM); } } if (RECORD) { endRecord(); println("Frame: #" + frameCount); } } void mouseClicked() { redraw(); } void drawCircle(float x, float y, float d) { fill(palette[(color) random(palette.length)]); ellipse(x, y, d, d); if (d > 2) { drawCircle(x, y, d/FRACT); } }