Exporting PDF does not show all objects

Hi, I am trying to export a pdf of my final drawing, however when I open the pdf it does not show some of the objects…

Anyone who can help me with this?

Here is my code:

// Creative Challenge 1. Final Version (Concept.9).
// NAME: CRAZY GROWING DANDELION
// DATE: 07/10/2022
// AUTHOR: TAISSIA VISSER

// INSPIRED BY:
// https://discourse.processing.org/t/arrangement-of-depth-of-objects/39129
// https://discourse.processing.org/t/how-to-generate-points-ellipse-within-a-circle-area/20933
// https://discourse.processing.org/t/circle-packing-shapes/30686

// REFERENCES:
// https://www.youtube.com/watch?v=QHEQuoIKgNE&t=1233s&ab_channel=TheCodingTrain
// https://processing.org/
// https://funprogramming.org/60-Are-two-circles-touching-or-intersecting.html

// USER GUIDE:
// By running the program, a dandelion will grow and form itself.
// The user does not have to take action besides running the code to create the dandelion.

import processing.pdf.*;

boolean record;

ArrayList<Dotcore>dotcores;
int corewidth = 150;
int coreheight = 150;
int Xcore = 500;
int Ycore = 500;
int dotcounter = 20;
float seedsangle = 0.0;
int seedscounter = 100;
int counter = 0;
int counter2 = 0;
float fluffAngle = 3;
int fluffcounter = 300;

void setup () {
  background(#BCECF5);
  size(1000, 1000);
  dotcores = new ArrayList<Dotcore>();
}

void draw () {
  if (record) {beginRecord(PDF, "CRAZY_DANDELION2.pdf");
  }  
  
  // CORE DANDELION
  noStroke();
  fill(#EDF0D7);
  ellipse(Xcore, Ycore, corewidth, coreheight);

  // DOTS IN THE CORE
  pushStyle();
  newDot();

  // If boolean edges returns true, boolean growing will return false. (See main page).
  // If boolean growing will return false, the dot will stop growing.
  for (Dotcore DT : dotcores) {
    if (DT.edges()) {
      DT.growing = false;
    }
    // Measuring the distance between the centre of a generated Dotcore and the core itself
    // in order to create a circular shape where in random dots will appear.
    if (dist(DT.x, DT.y, Xcore, Ycore)<70) {
      DT.show();
    }
    DT.grow();
  }
  popStyle();

  // STEM
  stem(500, 520);

  // FLUFFBALL
  pushMatrix();
  translate(500, 500);

  // Creating a maximum off lines that can be drawn to imitate a fluffy effect.
  counter2 = counter2 + 1;
  if (counter2 < fluffcounter) {
    fluffball(0, 0);
  }
  popMatrix();

  // SEEDS
  // Creating a maximum off seeds that will be   drawn around the core.
  pushStyle();
  counter = counter +1;
  if (counter < seedscounter) {
    seeds(500, 500, 85);
  }
  popStyle();
     if (record){
  endRecord();
  record = false;
  }  
  saveFrame("Dandelion.png");
}

// SEED FUNCTION
void seeds(int x, int y, int radius) {
  seedsangle += random (-5, 5);
  x += (cos(seedsangle)*radius);
  y += (sin(seedsangle)*radius);
  translate (x, y);
  rotate(seedsangle);
  fill(#B4A47A);
  stroke(#98885F);
  strokeWeight(1);
  ellipse(0, 0, 20, 5);
}

// NEW DOT FUNCTION
void newDot() {
  pushMatrix();
  translate(width/2, height/2);
  float x = random(Xcore-corewidth/2, Xcore+coreheight/2);
  float y = random (Ycore- coreheight/2, Ycore+coreheight/2 );
  popMatrix();


  boolean valid = true;
  for (Dotcore DT : dotcores) {
    float d = dist(x, y, DT.x, DT.y);
    if (d<DT.r) {
      valid = false;
      break;
    }
  }
  if (valid) {
    dotcores.add(new Dotcore(x, y));
  }
}

// STEM FUNCTION
void stem(int x, int y) {
  pushMatrix();
  translate(x, y);
  strokeWeight(20);
  stroke(#C4C94F);
  line(0, 0+60, 0, height);
  popMatrix();
}

// FLUFFBALL LINES FUNCTION
void fluffball(int Xpos, int Ypos) {
  fluffAngle += random(-10, 10);
  Xpos += cos(fluffAngle); // Update x-coordinate
  Ypos += sin(fluffAngle); // Update y-coordinate
  translate (random(-10, 10), random(10, -10));
  rotate(fluffAngle);
  stroke(200);
  strokeWeight(1);
  line(0, 0, 0, 250);
}

// KEYPRESS TO SAVE DOCUMENT
void keyPressed() {
  if (key=='s') {
    record = true;
    println("saved");
  }
}

second tab

// FOR EVERY DOT DRAWN IN THE CORE
class Dotcore {
  float x;
  float y;
  float r;
  boolean growing = true;
  
  Dotcore(float x_, float y_) {
    x = x_;
    y = y_;
    r = 1;
  }
  
  void grow() {
    if (growing) {
      r = r +1;
    }
  }
  
  // EDGES, creating a border where dots are not able to grow. 
  // If any of these statements is true, the boolean will edges will return true.
  // If boolean edges returns true, boolean growing will return false. (See main page).
  boolean edges() {
    return (x + r > Xcore + corewidth/2 || x - r < Xcore - corewidth/2 || y + r > Ycore + coreheight/2 || y - r < Ycore - coreheight/2 || r > 7 || dist(x,y,Xcore,Ycore)>70);
  }
  
  void show() {
    stroke(#9CA25F);
    strokeWeight(1);
    fill(#E3E8B0);
    ellipse(x, y, r*2, r*2);
  }
}

The final pdf should look like this:

but I am getting this:

Is there anyone who can help me with this?

2 Likes

Hello @Ties2901,

PDF Export Library Reference:

Find this section in the above reference and implement that:

Many Frames Into One File (With Screen Display)

I was able to capture many frames to a PDF.

Voila!

:)

2 Likes

Thanks!! Going to try out this method immediately

Hi GLV;

I have implemented the example from the link you have send me, but unfortunately I still do not get the entire flower ;(

Would you be able to check if i have written it correctly?

Thanks!

// Creative Challenge 1. Final Version (Concept.9).
// NAME: CRAZY GROWING DANDELION
// DATE: 07/10/2022
// AUTHOR: TAISSIA VISSER

// INSPIRED BY:
// https://discourse.processing.org/t/arrangement-of-depth-of-objects/39129
// https://discourse.processing.org/t/how-to-generate-points-ellipse-within-a-circle-area/20933
// https://discourse.processing.org/t/circle-packing-shapes/30686

// REFERENCES:
// https://www.youtube.com/watch?v=QHEQuoIKgNE&t=1233s&ab_channel=TheCodingTrain
// https://processing.org/
// https://funprogramming.org/60-Are-two-circles-touching-or-intersecting.html

// USER GUIDE:
// By running the program, a dandelion will grow and form itself.
// The user does not have to take action besides running the code to create the dandelion.

import processing.pdf.*;

boolean record;

ArrayList<Dotcore>dotcores;
int corewidth = 150;
int coreheight = 150;
int Xcore = 500;
int Ycore = 500;
float seedsangle = 0.0;
int seedscounter = 100;
int counter = 0;
int counter2 = 0;
int counter3 = 0;
float fluffAngle = 3;
int fluffcounter = 300;
int dotcounter = 400;

void setup () {
  background(#BCECF5);
  size(1000, 1000);
  dotcores = new ArrayList<Dotcore>();
}

void draw () {
  beginRecord(PDF, "CRAZY_DANDELION4.pdf");
  // CORE DANDELION
  noStroke();
  fill(#EDF0D7);
  ellipse(Xcore, Ycore, corewidth, coreheight);

  // DOTS IN THE CORE
  pushStyle();
  counter3 = counter3 +1;
  if (counter3 < dotcounter) {
    newDot();
  }

  // If boolean edges returns true, boolean growing will return false. (See main page).
  // If boolean growing will return false, the dot will stop growing.
  for (Dotcore DT : dotcores) {
    if (DT.edges()) {
      DT.growing = false;
    }
    // Measuring the distance between the centre of a generated Dotcore and the core itself
    // in order to create a circular shape where in random dots will appear.
    if (dist(DT.x, DT.y, Xcore, Ycore)<70) {
      DT.show();
    }
    DT.grow();
  }
 
  popStyle();

  // STEM
  stem(500, 520);

  // FLUFFBALL
  pushMatrix();
  translate(500, 500);

  // Creating a maximum off lines that can be drawn to imitate a fluffy effect.
  counter2 = counter2 + 1;
  if (counter2 < fluffcounter) {
    fluffball(0, 0);
  }
  popMatrix();

  // SEEDS
  // Creating a maximum off seeds that will be   drawn around the core.
  pushStyle();
  counter = counter +1;
  if (counter < seedscounter) {
    seeds(500, 500, 85);
  }
  popStyle();
   endRecord();
  saveFrame("DANDELION.png");
}

// SEED FUNCTION
void seeds(int x, int y, int radius) {
  seedsangle += random (-5, 5);
  x += (cos(seedsangle)*radius);
  y += (sin(seedsangle)*radius);
  translate (x, y);
  rotate(seedsangle);
  fill(#B4A47A);
  stroke(#98885F);
  strokeWeight(1);
  ellipse(0, 0, 20, 5);
}

// NEW DOT FUNCTION
void newDot() {
  pushMatrix();
  translate(width/2, height/2);
  float x = random(Xcore-corewidth/2, Xcore+coreheight/2);
  float y = random (Ycore- coreheight/2, Ycore+coreheight/2 );
  popMatrix();


  boolean valid = true;
  for (Dotcore DT : dotcores) {
    float d = dist(x, y, DT.x, DT.y);
    if (d<DT.r) {
      valid = false;
      break;
    }
  }
  if (valid) {
    dotcores.add(new Dotcore(x, y));
  }
}

// STEM FUNCTION
void stem(int x, int y) {
  pushMatrix();
  translate(x, y);
  strokeWeight(20);
  stroke(#C4C94F);
  line(0, 0+60, 0, height);
  popMatrix();
}

// FLUFFBALL LINES FUNCTION
void fluffball(int Xpos, int Ypos) {
  fluffAngle += random(-10, 10);
  Xpos += cos(fluffAngle); // Update x-coordinate
  Ypos += sin(fluffAngle); // Update y-coordinate
  translate (random(-10, 10), random(10, -10));
  rotate(fluffAngle);
  stroke(200);
  strokeWeight(1);
  line(0, 0, 0, 250);
}

void keyPressed() {
  if (key == 's') {
    endRecord();
    println("saved");
    exit();
  }
}
// FOR EVERY DOT DRAWN IN THE CORE
class Dotcore {
  float x;
  float y;
  float r;
  boolean growing = true;
  
  Dotcore(float x_, float y_) {
    x = x_;
    y = y_;
    r = 1;
  }
  
  void grow() {
    if (growing) {
      r = r +1;
    }
  }
  
  // EDGES, creating a border where dots are not able to grow. 
  // If any of these statements is true, the boolean will edges will return true.
  // If boolean edges returns true, boolean growing will return false. (See main page).
  boolean edges() {
    return (x + r > Xcore + corewidth/2 || x - r < Xcore - corewidth/2 || y + r > Ycore + coreheight/2 || y - r < Ycore - coreheight/2 || r > 7 || dist(x,y,Xcore,Ycore)>70);
  }
  
  void show() {
    stroke(#9CA25F);
    strokeWeight(1);
    fill(#E3E8B0);
    ellipse(x, y, r*2, r*2);
  }
}

Sorry I saw I did not place the begin record in the setup, but now I have done this it gives me the following error:

Hello @Ties2901,

You need to be methodical, meticulous and scrutinize your code and the example code.

  • Remove all code related to PDF in original code or comment it out.
  • Add code related to PDF for multiple frames.

Looks like you have code leftover from your first effort.

I will leave you to find it… this is your journey and it is worth the effort in the long run.

Thank me later.

:)

1 Like