beginRecord not capturing all frames in display.

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

  • edited November 2016 Answer ✓

    Without having investigated I can think of a few plausible reasons the problem might occurring:

    1. there is a bug (in the sketch, or in the Processing PDF renderer), and certain types of frames record, others don't
    2. too many layers A: there you can't record more than x layers in a PDF. All the layers are written to memory by beginRecord, but fail to write out to the file on endRecord
    3. too many layers B: all the layers are actually written into the file -- the data is there. However, standard implementations of PDF viewers don't load more than x layers.
    4. This was the problem: beginRecord is being called too late and missing key settings, so screen and PDF are drawn differently.

    Note that beginRecord() will only pick up any settings that happen after it has been called. For instance, if you call textFont() before beginRecord(), then that font will not be set for the file that you're recording to.

    I can't test your sketch because I don't have your shape files, but I notice that shapeMode(CENTER); occurs before beginRecord -- 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.

  • edited November 2016 Answer ✓

    @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.

Sign In or Register to comment.