Why it is showing only one box in export of processing.org java pdf?

Viewed 28

Here is my code down below, when in run it shows multiple boxes as I wanted but when I try to export, it only shows a single box at that frame position.I tried generating output at particular frame but its same issue

import processing.pdf.*;
int ofs = 500;


boolean record;

void setup() {
  size(1900, 1080, P3D);
}

void draw() {
  if (record) {
    beginRaw(PDF, "box.pdf");
  }


  background(255);
  translate(width/2, height/2, -800);
  
  rotateZ(0.3);
  rotateY(frameCount/500.0);
  float x = sin(radians(frameCount*0.1));
   for ( int xo = -ofs; xo<=ofs; xo += 100) {
     for ( int yo = -ofs; yo<=ofs; yo += 100) {
        pushMatrix();
        translate ( xo, yo, 0);
        box(200*x);
        fill(155,150,90);
        strokeWeight(3*x);
        popMatrix();
  if (record) {
    endRaw();
    record = false;
  }
    }
      }
        }

void keyPressed() {
  if (key == 'r') {
    record = true;
  }
}


  
1 Answers

So close! :)

Perhaps the formatting might have made it harder to spot the issue. You're calling endRaw(); (which wraps up pdf recording) nested in the for loops.

This means it's only picking up the first box since record is set to false so the other boxes are ignored.

I recommend using Edit > Auto Format (CMD + T / Ctrl + T).

Simply move the if(record) after the nested for loops:


import processing.pdf.*;
int ofs = 500;


boolean record;

void setup() {
  size(1400, 580, P3D);
}

void draw() {
  if (record) {
    beginRaw(PDF, "box.pdf");
  }


  background(255);
  translate(width/2, height/2, -800);

  rotateZ(0.3);
  rotateY(frameCount/500.0);
  float x = sin(radians(frameCount*0.1));
  for ( int xo = -ofs; xo<=ofs; xo += 100) {
    for ( int yo = -ofs; yo<=ofs; yo += 100) {
      pushMatrix();
      translate ( xo, yo, 0);
      box(200*x);
      fill(155, 150, 90);
      strokeWeight(3*x);
      popMatrix();
    }
  }
  
  // finish recording to PDF only after everything was drawn 
  if (record) {
    endRaw();
    record = false;
  }
}

void keyPressed() {
  if (key == 'r') {
    record = true;
  }
}


Related