Create PDF

edited February 2015 in Questions about Code

Hello everyone, I been trying for a long time to creat a PDF file from this sketch. I tried every code possible ans still nothing. I hope someone can help me to find the problem, i'm wondering if is not compatible with Particles… Thanks ! The code :

import processing.pdf.*;
PGraphicsPDF pdf;

import traer.physics.*;

ParticleSystem PS = new ParticleSystem(0.0, 0.5);
int pcount = 400;
int ring_radius = 135;
Particle[] Ring = new Particle[pcount];
Spring[] Innersprings = new Spring[pcount*2];
Spring[] Rim = new Spring[pcount];
float spokeStrength = 0.008;
float spokeDamping = 0.0;
float rimDamping = 0.01;
float rimStrength = 1.0;
float innerspring_length = ring_radius*2.5;
float z=0;
int h=0; 

void setup(){
  size(600,600);
   pdf = (PGraphicsPDF)beginRecord(PDF, "cooldessin.pdf");
  background(255);
  smooth();
  colorMode(HSB,255);
  h = int(random(255));
  buildParticles(PS);
}

void draw(){
  PS.tick();
  translate(height/2,width/2);
  strokeWeight(2);
  stroke((h+(z*0.03))%255,255-(z*0.1),z*0.15,40);
  fill(255);
  // draw the ring
  beginShape();
  for (int p=0; p<pcount; p++){
    vertex(Ring[p].position().x(),Ring[p].position().y());
  }
  endShape(CLOSE);
  for (int s=0; s<pcount; s++){
    int spr = int(random(pcount)); 
    Innersprings[spr].setRestLength(Innersprings[spr].restLength() - random(0,1));
 }
  z++;
}


void buildParticles(ParticleSystem P){
  for (float i=0; i<pcount; i++){ // makes the particles
    Ring[int(i)] = P.makeParticle(1.0,sin(TWO_PI*(i/pcount))*ring_radius,cos(TWO_PI*(i/pcount))*ring_radius,0);
  }
  float segmentlength = (TWO_PI*ring_radius)/float(pcount); 
  for (int i=0; i<pcount; i++){ 
    Innersprings[i] =  P.makeSpring(Ring[i], Ring[int(random(pcount))],spokeStrength, spokeDamping, innerspring_length); // 2 random springs
    Innersprings[i+pcount] =  P.makeSpring(Ring[i], Ring[(i+int(random(pcount)))%pcount], spokeStrength, spokeDamping, innerspring_length); // between each point and 2 others
    if (i < pcount-1) {
      Rim[i] = P.makeSpring(Ring[i],Ring[i+1],rimStrength, rimDamping,segmentlength);
    }
    else { 
      Rim[i] = P.makeSpring(Ring[i],Ring[0],rimStrength, rimDamping, segmentlength);
    }
  }
}

//================================= 
void keyPressed() {
 switch (key) {
 case ' ': 
   pdf.nextPage();
   background(255);
   break;
 case 'f':
   endRecord();
   exit();
   break;
 }
}    
Tagged:

Comments

  • How to post code

    when you post your code:

    • in the editor hit ctrl-t to auto format

    • copy it

    • paste it in the browser

    • leave 2 empty lines before it, 1 line after it

    • mark the code (without the 3 empty lines)

    • press C in the small command bar.

  • edited February 2015

    Just tried your code and it worked for me. Click to see the PDF

  • Hi quark, that is strange, for me is imposible to make any PDF. did you hit the case "f" to make the PDF ? thanks for your ansewer

  • same (good) result hitting 'f'

  • i found the problem! i was missing the sketch.properties! Yes it works now! thanks for the tests. Have a good day.

Sign In or Register to comment.