I have read the Processing docs on PDF export for 3d sketches. For some reason, my sketch won’t save as a PDF with the specified background. It only saves on a white background.
//Stuff for saving stage
import processing.pdf.*;
// global variables
int DIM = 500; // height, width
int N = 20; // n squares down and up
int R = int(DIM/N); // radius of squares
// setup drawing
void setup(){
size(500, 500, P3D);
rectMode(CENTER);
noFill();
noLoop();
stroke(100, 100, 0);
}
// draw
void draw() {
beginRaw(PDF, "output.pdf");
background(33); // <<<< SHOULD MAKE BACKGROUND GRAY BUT DOES NOT
for (int x=R; x<= width-R; x+=R) { // objects across
for (int y=R; y<=height-R; y+=R) { // objects down
float z = noise(x,y) * 30;
pushMatrix(); // push matrix stack
translate(x, y, z); // pop out of canvas based on z value
rect(0, 0, R, R, 2); // draw rectangle
popMatrix(); // pop matrix stack
} // end x loop
} // end y loop
endRaw();
}
// PDF background problem
// https://discourse.processing.org/t/pdf-export-wont-save-with-background-for-my-3d-sketch/10460
//Stuff for saving stage
import processing.pdf.*;
// global variables
int DIM = 500; // height, width
int N = 20; // n squares down and up
int R = int(DIM/(N+1)); // radius of squares
PGraphics pdf;
// setup drawing
void setup() {
size(500, 500); //, P3D
rectMode(CENTER);
noFill();
stroke(100, 100, 0);
pdf = createGraphics(500, 500, PDF, "outputG.pdf");
pdf.beginDraw();
pdf.background(0,0,80); // <<<< SHOULD MAKE BACKGROUND GRAY BUT DOES NOT
pdf.noFill();
pdf.stroke(100, 100, 0);
for (int x=R; x<= width-R; x+=R) { // objects across
for (int y=R; y<=height-R; y+=R) { // objects down
float z = (noise(x, y) * 2 -1)*3; // 30
//pushMatrix(); // push matrix stack
//translate(0, 0, z); // pop out of canvas based on z value
pdf.rect(x+z, y+z, R, R, 2); // draw rectangle
//popMatrix(); // pop matrix stack
} // end x loop
} // end y loop
// endRaw();
pdf.dispose();
pdf.endDraw();
exit();
}