Need help with exporting as pdf

Hello guys, I am new to programming and processing and I have some issues with exporting my creation as pdf. I am using the PDF Files from 3D Geometry section of the article on exporting. My issue is that the pdf only shows a part of the code. I guess this is because I have void draw 2 times but how can I deal with this, please help:confounded:. Here is my code:

float LENS = 4;
float RATE = 16;
float k = RATE / LENS;
float[][] distances;
float maxDistance;
int spacer;
float e = 0;
float i = 1;
  
void setup() {
  size(900, 600);
  maxDistance = dist(width/2, height/2, width, height);
  distances = new float[width][height];
  for (int y = 0; y < height; y++) {
    for (int x = 0; x < width; x++) {
      float distance = dist(width/2, height/2, x, y);
      distances[x][y] = distance/maxDistance * 200;
    }
  }
  spacer = 20;
  strokeWeight(0.5);
  noLoop();  // Run once and stop
  background(#669390);
    stroke(#FFFFFF);
    
  strokeWeight(1);
    
}

void draw() {
 
   for (int y = 0; y < height; y += spacer) {
    for (int x = 0; x < width; x += spacer) {
      stroke(distances[x][y]);
      line(x + spacer/2,y, 2*x, 2*y + spacer/2);
    }
  }
  for (int y = 500; y > 0; y -= spacer) {
    for (int x = 700; x > 0; x -= spacer) {
      stroke(distances[x][y]);
      line(x - spacer/2,y-spacer/2, 2*x, 2*y - spacer/2);
    }
  }
    for (int y = 500; y > 0; y -= spacer) {
    for (int x = 0; x < 900; x += spacer) {
      stroke(distances[x][y]);
      line(x + spacer/2,y+spacer/2, 2*x, 2*y + spacer/2);
    }
  }
  
  pushMatrix();
  translate(width*0.5, height*0.5);
  rotate(PI/3.0);
  fill(206, 43, 122);
  star(0, 0, 100, 300, 50); 
  popMatrix();
  
  pushMatrix();
  translate(width*0.5, height*0.5);
  rotate(PI/5.0);
  fill(206, 43, 122);
  star(0, 0, 100, 300, 50); 
  popMatrix();
  

  
  noFill();
  drawRose();
  } 
  
  
void drawRose(){
    
    beginShape();
    translate(width / 2, height / 2);
    for (float t = 0; t < TWO_PI * LENS; t += 0.02) {
    float r = 200 * cos(k * t);
    float x = r * cos(t);
    float y = r * sin(t);
    vertex(x, y);
    }
    endShape(CLOSE);
    
    rotate(PI/5);
    beginShape();
    for (float t = 0; t < TWO_PI * LENS; t += 0.02) {
    float r = 200 * cos(k * t);
    float x = r * cos(t);
    float y = r * sin(t);
    vertex(x, y);
    }
    endShape(CLOSE);
    
     rotate(PI/8);
    beginShape();
    for (float t = 0; t < TWO_PI * LENS; t += 0.02) {
    float r = 200 * cos(k * t);
    float x = r * cos(t);
    float y = r * sin(t);
    vertex(x, y);
    }
    endShape(CLOSE);
    
    rotate(PI/10);
    beginShape();
    for (float t = 0; t < TWO_PI * LENS; t += 0.02) {
    float r = 200 * cos(k * t);
    float x = r * cos(t);
    float y = r * sin(t);
    vertex(x, y);
    }
    endShape(CLOSE);
    
  noLoop();
  
  }
    
void star(float x, float y, float radius1, float radius2, int npoints) {
  float angle = TWO_PI / npoints;
  float halfAngle = angle/2.0;
  beginShape();
  for (float a = 0; a < TWO_PI; a += angle) {
    float sx = x + cos(a) * radius2;
    float sy = y + sin(a) * radius2;
    vertex(sx, sy);
    sx = x + cos(a+halfAngle) * radius1;
    sy = y + sin(a+halfAngle) * radius1;
    vertex(sx, sy);
  }
  endShape(CLOSE);
}

Hi marto,

I can’t see any lines in your code related to PDF export.

1 Like

Hello,

I deleted the code for the export because it didn’t work… and as i am writing this i understand how little sense this makes. Here is how it was before:

import processing.pdf.*;
boolean record;

float LENS = 4;
float RATE = 16;
float k = RATE / LENS;
float[][] distances;
float maxDistance;
int spacer;
float e = 0;
float i = 1;
  
void setup() {
  size(900, 600);

}
   
  maxDistance = dist(width/2, height/2, width, height); //Creating the background lines with arrays
  distances = new float[width][height];
  for (int y = 0; y < height; y++) {
    for (int x = 0; x < width; x++) {
      float distance = dist(width/2, height/2, x, y);
      distances[x][y] = distance/maxDistance * 200;
    }
  }
  spacer = 20; //Changes the density of the lines
  strokeWeight(0.5);
  noLoop();  // Run once and stop
  background(122, 153, 107);
    stroke(#0C6AA7);
    
  strokeWeight(1);
    
}

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

  

   for (int y = 0; y < height; y += spacer) {
    for (int x = 0; x < width; x += spacer) {
      stroke(distances[x][y]);
      line(x + spacer/2,y, 2*x, 2*y + spacer/2);
    }
  }
  for (int y = 500; y > 0; y -= spacer) {
    for (int x = 700; x > 0; x -= spacer) {
      stroke(distances[x][y]);
      line(x - spacer/2,y-spacer/2, 2*x, 2*y - spacer/2);
    }
  }
    for (int y = 500; y > 0; y -= spacer) {
    for (int x = 0; x < 900; x += spacer) {
      stroke(distances[x][y]);
      line(x + spacer/2,y+spacer/2, 2*x, 2*y + spacer/2);
    }
  }
  
  pushMatrix(); //creating two similiar stars with different angle of rotation
  translate(width*0.5, height*0.5);
  rotate(PI/3.0);
  fill(206, 43, 122);
  star(0, 0, 100, 300, 50); 
  popMatrix();
  
    pushMatrix();
  translate(width*0.5, height*0.5);
  rotate(PI/5.0);
  fill(206, 43, 122);
  star(0, 0, 100, 300, 50); 
  popMatrix();
  
  noFill();
  drawLotus();
  } 
  
  

  
  
  
void drawLotus(){
 // creating  4 flowers with different angle of rotation   
    beginShape();
    translate(width / 2, height / 2);
    for (float t = 0; t < TWO_PI * LENS; t += 0.02) {
    float r = 200 * cos(k * t);
    float x = r * cos(t);
    float y = r * sin(t);
    vertex(x, y);
    }
    endShape(CLOSE);
    
    rotate(PI/5);
    beginShape();

    for (float t = 0; t < TWO_PI * LENS; t += 0.02) {
    float r = 200 * cos(k * t);
    float x = r * cos(t);
    float y = r * sin(t);
    vertex(x, y);
    }
    endShape(CLOSE);
    
     rotate(PI/8);
    beginShape();
    
    for (float t = 0; t < TWO_PI * LENS; t += 0.02) {
    float r = 200 * cos(k * t);
    float x = r * cos(t);
    float y = r * sin(t);
    vertex(x, y);
    }
    endShape(CLOSE);
    
    rotate(PI/10);
    beginShape();

    for (float t = 0; t < TWO_PI * LENS; t += 0.02) {
    float r = 200 * cos(k * t);
    float x = r * cos(t);
    float y = r * sin(t);
    vertex(x, y);
    }
    endShape(CLOSE);
    
  noLoop();
  
  }
  //configuring the star's parameters 
void star(float x, float y, float radius1, float radius2, int npoints) {
  float angle = TWO_PI / npoints;
  float halfAngle = angle/2.0;
  beginShape();
  for (float a = 0; a < TWO_PI; a += angle) {
    float sx = x + cos(a) * radius2;
    float sy = y + sin(a) * radius2;
    vertex(sx, sy);
    sx = x + cos(a+halfAngle) * radius1;
    sy = y + sin(a+halfAngle) * radius1;
    vertex(sx, sy);
  }
  endShape(CLOSE);
  if (record) {
    endRaw();
    record = false;
  }
}

// Hit 'r' to record a single frame
void keyPressed() {
  if (key == 'r') {
    record = true;
  }
}

}