I’ve just started getting my feet wet with Processing, and I’m having trouble figuring out why I’m having problems with this sketch rendering out PDFs and SVGs that are missing a lot of the picture. I’m using the beginRecord(); endRecord(); method to save them, as well as save(); to make a PNG (which works fine). It looks like the PDF and SVG have a bunch of lines missing, wherever a line crosses another. If anyone has any pointers on why this might be happening I’d be really appreciative.
On the left is the pdf, on the right is the png:
import processing.pdf.*;
import processing.svg.*;
String title = "curves";
int counter;
int seed;
void setup() {
size(720, 720);
noFill();
smooth();
seed = millis();
seededRender();
}
void draw() {
}
void seededRender() {
randomSeed(seed);
noiseSeed(seed);
render();
}
void render() {
int points = 2;
int lines = 200;
float zoff = 0.03;
float z = 0.0;
background(255);
stroke(0);
for (int i = 0; i <= width; i += width / lines) {
beginShape();
curveVertex(i, 0);
curveVertex(i, 0);
for (float p = 1; p <= points; p++) {
curveVertex(width * noise(z + p), height * (p / (points + 1)));
}
curveVertex(i, height);
curveVertex(i, height);
endShape();
z += zoff;
}
}
//
void keyReleased() {
if (key == TAB) {
newSeed();
}
if (key == ENTER) {
saveImage();
}
}
void newSeed() {
seed = millis();
println("rendered with new seed " + seed);
seededRender();
}
void saveImage() {
String filename = "data/" + title + "_" + nf(counter, 3) + "_" + seed;
beginRecord(PDF, filename + ".pdf");
seededRender();
endRecord();
beginRecord(SVG, filename + ".svg");
seededRender();
endRecord();
save(filename + ".png");
println("saved " + filename);
counter++;
}