We are about to switch to a new forum software. Until then we have removed the registration on this forum.
PShape letter, triang;
float spacing,x,y;
import processing.pdf.*;
void setup(){
size(720,720);
background(255);
frameRate(2);
spacing=width/11;
letter = loadShape("a.svg");
triang = loadShape("tri.svg");
shapeMode(CENTER);
beginRecord(PDF, "decay4.pdf");
}
void draw(){
float aX = random(0,width);
float aY = random(0,height);
for(int o=0; o<36; o++){
int dice = int(random(0,8));
letter.disableStyle();
noFill();
stroke(0);
if(dice == 1){ stroke(255,0,0); }
strokeWeight(.25);
rotate(o*10);
shape(letter, aX,aY,1000,1000);
rotate(-o*10);
}
translate(spacing,spacing);
for(int i=0; i<9; i++){
for(int j=0; j<9; j++){
x=i*spacing;
y=j*spacing;
int dice2 = int(random(0,10));
if(dice2 == 3){
noStroke();
fill(255);
rect(x,y,spacing/2,spacing/2);
}
}
}
}
void mousePressed() {
endRecord();
exit();
}
I've been trying to create pdf's of a few sketches which randomly generate on top of themselves, creating interesting and varied layered looks. I've found, however, that all the different methods of creating pdf screenshots fail to capture the image that processing displays.
I've taken a screenshot of my processing window, and I've uploaded a pdf similar to every other pdf I've captured using processing's tools. The difference is the amount of layering (obvious in the top left corner).
https://drive.google.com/file/d/0B3CsnykcA_TqVTZTWlhaWGxGRlU/view?usp=sharing
Answers
Without having investigated I can think of a few plausible reasons the problem might occurring:
I can't test your sketch because I don't have your shape files, but I notice that
shapeMode(CENTER);
occurs beforebeginRecord
-- that or some other setting might(?) cause different behavior for the PDF renderer and the screen. Try moving shapeMode after beginRecord. Worth trying.Final debugging idea: You could also try implementing the sketch with the PDF renderer only using
size()
.It was the placement of beginRecord, thank you! Moved it a few lines up and the renderings are turning out perfect.
@apolit5 -- great!!
For future forum-goers having this problem:
The crucial idea is that beginRecord only sees the settings after it is called. So you can be seeing one thing on the screen, and another thing in the PDF, because the screen and PDF are drawing using different settings. In this case, shapes were CENTERed via shapeMode() on the screen, but the PDF didn't know about the shapeMode(), so it was drawing them un-centered.