how to capture the pdf of a particular clip

edited May 2014 in How To...

Currently this is the scripts i'm using. I'm wondering if there is a way to capture a particular frame or clip in the animation? I am pasting the code here for reference. Thank you so much!

import processing.pdf.*;
PImage img;
int w=759, h=756, sx=w, x, y;

boolean record;

void setup() {
  size (759,756 );
  img = loadImage("Mullion_texture_2_rot.jpg"); 
}

void draw() {

  if (record) {
    //Note that #### will be replaced with the frame number. Fancy Oh you fancy, oh you fancy!
    beginRecord(PDF, "img-01-####.pdf");
  }

 if (sx-->0)for (x=0;x++<w;) for  (y=0;(y+=sx)<h;)  {
   stroke(img.get(x,y));
   line(x,y,x+1,y+sx);
   strokeWeight(1);

 if (sx-->0)for (x=0;x++<w;) for  (y=0;(y+=sx)<h;)  {
   stroke(img.get(x,y));
   line(x,y,x+1,y+sx);
   strokeWeight(1);
}
  }
  if (record) {
    endRecord();
    record = false;
  }
}

void mousePressed() {
  record = true;
}
Tagged:

Answers

  • To newcomers in this forum: read attentively these instructions
    You chose no category and you don't know how to format. I fixed these.

  • "to capture a particular frame or clip in the animation?"
    Not too sure what is "particular". Is is by frame number?

    One problem with PDF capture is that it can only capture what is being drawn, it cannot capture what has been already drawn. Ie. it records the drawing function calls (stroke, line, etc.) as they happen. If you start to record in the middle of the sketch run, you only capture from the point of the start of the capture.

    Now, you are lucky, your sketch is deterministic, not relying on random numbers. What you can do is to store the frameCount value when you click. Then you start the record, and replay all the animation at once (do a loop over the frameCount, simulating the successive draw() calls).

    Side note: in general, you must call strokeWeight() before drawing a line. Here, it doesn't change anyway, so you can call it only once, in setup().

  • You can try this (untested, it is to give you a general idea of what I am talking about):

    import processing.pdf.*;
    PImage img;
    int w=759, h=756, sx=w, x, y;
    
    boolean record;
    
    void setup() {
      size (759,756 );
      strokeWeight(1);
    
      img = loadImage("Mullion_texture_2_rot.jpg");
    }
    
    void draw() {
       drawLines();
    }
    
    void mousePressed() {
      beginRecord(PDF, "img-01-####.pdf");
      sx = w; x = 0; y = 0; // Reset variables, you might want to save them and restore them after, if you prefer
      for (int i = 0; i < frameCount; i++)
      {
        drawLines();
      }
      endRecord();
    }
    
    void drawLines()
    {
     if (sx-->0)for (x=0;x++<w;) for  (y=0;(y+=sx)<h;)  {
       stroke(img.get(x,y));
       line(x,y,x+1,y+sx);
    
        if (sx-->0)for (x=0;x++<w;) for  (y=0;(y+=sx)<h;)  {
          stroke(img.get(x,y));
          line(x,y,x+1,y+sx);
        }
      }
    }
    
Sign In or Register to comment.