P2D and PDF

edited December 2015 in Programming Questions

Hi,

I am trying to make a PDF out of my picture but it doesn't work. I get only a part of the picture and a random huge black circle.

this is my program:

import processing.pdf.*;
int i; 


PShape ind;
PShape yearind;
PShape monthind;
PShape dayind;
PShape hourind;
PShape minind;
PShape secind;
PShape msecind;

float[]time= {
  year()*2/30, month()*30/1.3, day()*360/31/1.1, hour()*15/0.9, minute()*6/0.7, second()*6/0.5, millis()*3.6/0.3
};

float year = time[0];
float month = time[1];
float day = time[2];
float hour = time[3];
float min = time[4];
float sec = time[5];
float msec = time[6];

int[]R = {
  0, 0, 0, 0, 0, 0, 0
};
int[]G = {
  0, 0, 0, 0, 0, 0, 0
};
int[]B = {
  0, 0, 0, 0, 0, 0, 0
};

void setup() {
  size(displayWidth, displayHeight, P2D);
  beginRecord(PDF, "clock.pdf");

  background(0);
  frameRate(1000);

  if (hour()>=18||hour<6) {
    R[0] += 19;
    G[0] += 27;
    B[0] += 94;

    R[3] += 124;
    G[3] += 32;
    B[3] += 200;

    R[2] += 26;
    G[2] += 48;
    B[2] += 66;

    R[5] += 150;
    G[5] += 100;
    B[5] += 200;

    R[6] += 50;
    G[6] += 50;
    B[6] += 200;

    R[1] += 103;
    G[1] += 52;
    B[1] += 99;

    R[4] += 44;
    G[4] += 81;
    B[4] += 112;
  }
  //  if (month()==12&&day()==25||month()==12&&day()==26){
  //    c1R = c1R +0;
  //    c1G = c1G +255;
  //    c1B = c1B +0;
  //  
  //  }
  color cyear = color(R[0], G[0], B[0]);
  color cmonth = color(R[1], G[1], B[1]);
  color cday = color(R[2], G[2], B[2]);
  color chour = color(R[3], G[3], B[3]);
  color cmin = color(R[4], G[4], B[4]);
  color csec = color(R[5], G[5], B[5]);
  color cmsec = color(R[6], G[6], B[6]);


  ind = createShape();
  ind.beginShape();
  ind.translate(-595, -421);
  ind.stroke( 255 );
  ind.vertex( 595, 421 );  
  ind.vertex( 1011, 421 );  
  ind.vertex( 595, 421);
  ind.endShape(CLOSE);

  yearind = createShape();
  yearind.beginShape();
  yearind.translate(-595, -421);
  yearind.stroke(cyear);
  yearind.vertex( 595, 421 );  
  yearind.vertex( 1011, 421 );  
  yearind.vertex( 595, 421);
  yearind.endShape(CLOSE);

  monthind = createShape();
  monthind.beginShape();
  monthind.translate(-595, -421);
  monthind.stroke( cmonth );
  monthind.vertex( 595, 421 );  
  monthind.vertex( 961, 421 );  
  monthind.vertex( 595, 421);
  monthind.endShape(CLOSE);

  dayind = createShape();
  dayind.beginShape();
  dayind.translate(-595, -421);
  dayind.stroke( cday );
  dayind.vertex( 595, 421 );  
  dayind.vertex( 911, 421 );  
  dayind.vertex( 595, 421);
  dayind.endShape(CLOSE);

  hourind = createShape();
  hourind.beginShape();
  hourind.translate(-595, -421);
  hourind.stroke( chour );
  hourind.vertex( 595, 421 );  
  hourind.vertex( 861, 421 );  
  hourind.vertex( 595, 421);
  hourind.endShape(CLOSE);

  minind = createShape();
  minind.beginShape();
  minind.translate(-595, -421);
  minind.stroke( cmin );
  minind.vertex( 595, 421 );  
  minind.vertex( 811, 421 );  
  minind.vertex( 595, 421);
  minind.endShape(CLOSE);

  secind = createShape();
  secind.beginShape();
  secind.translate(-595, -421);
  secind.stroke( csec );
  secind.vertex( 595, 421 );  
  secind.vertex( 761, 421 );  
  secind.vertex( 595, 421);
  secind.endShape(CLOSE);

  msecind = createShape();
  msecind.beginShape();
  msecind.translate(-595, -421);
  msecind.stroke( cmsec);
  msecind.vertex( 595, 421 );  
  msecind.vertex( 711, 421 );  
  msecind.vertex( 595, 421);
  msecind.endShape(CLOSE);
}

void draw() {

  i++;
  translate(width/2, height/2);

  if (i<=year) {

    shape(yearind, 0, 0);

    yearind.rotate(radians(1.5));
  }

  if (i>=year&&i<=year + month) {
    shape(monthind, 0, 0);
    monthind.rotate(radians(1.3));
  }

  if (i>=year+month&&i<=year+month+day) {
    shape(dayind, 0, 0);
    dayind.rotate(radians(1.1));
  }

  if (i>=year+month+day&&i<=year+month+day+hour) {
    shape(hourind, 0, 0);
    hourind.rotate(radians(0.9));
  }

  if (i>=year+month+day+hour&&i<=year+month+day+hour+min) {
    shape(minind, 0, 0);
    minind.rotate(radians(0.7));
  }

  if (i>=year+month+day+hour+min&&i<=year+month+day+hour+min+sec) {
    shape(secind, 0, 0);
    secind.rotate(radians(0.5));
  }

  if (i>=year+month+day+hour+min+sec&&i<=year+month+day+hour+min+sec+msec) {
    shape(msecind, 0, 0);
    msecind.rotate(radians(0.3));
  }


  shape(ind, 0, 0);
  ind.rotate(radians(30));
}
void mousePressed() {
  endRecord();

  exit();
} 
Tagged:

Answers

  • Answer ✓

    Please format your code for the forum. You can find out how here

  • i'm already trying ahahhaha

  • ow never mind i've got my problem already ahaha

  • I have formatted the code for you this time.

    BTW although the forum nags you to accept/reject comments on your discussion you don't have to. Only mark a comment as Accepted if it solves your problem otherwise people might ignore the discussion because they think it has been solved.

  • Thank you very much! I was already thinking that I did something wrong.

Sign In or Register to comment.