We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › PGraphics or pdf makes program slow
Page Index Toggle Pages: 1
PGraphics or pdf makes program slow? (Read 302 times)
PGraphics or pdf makes program slow?
Jan 16th, 2008, 5:27pm
 
I made a program which saves the output as a pdf with transparency but it runs very slowly and it wont work as an applet.
Also it hangs if i try to reset tha PGraphics background (ive commented the line below)
Am i doing anything wrong, or is there another way?

import processing.pdf.*;

PGraphics pgpdf;
....

void setup() {  
 ....
 pgpdf = createGraphics(mywidth, myheight,PDF, "pattern.pdf");

 ....
 drawWithLine();
}

....

void update(int x, int y)
{
 
 ...
 if(mousePressed) {
   if(saveBtn.pressed() && !saving) {
     println("going to save");
     saveFile();
     
   } else if (redrawBtn.pressed()) {
     println("redrawing");
     pgpdf = createGraphics(mywidth, myheight,PDF, "pattern.pdf");
     drawWithLine();
   }
 }
}


void saveFile() {
 saving = true;
 pgpdf.dispose();
 println("File Written");
 saving = false;
}

void drawWithLine() {
 background(255);
 strokeWeight(1);
 stroke(200,100,23);
 
 // pgpdf.background(0,0) this results in nullpointexcept.
 pgpdf.beginDraw();  
 pgpdf.strokeWeight(1);
 pgpdf.stroke(200,100,23);

 for(int i=0; i<density; i++) {
   
   //lets create one with x 0
   int rx1 = 0;
   int rx2 = mywidth;
   int ry1 = int(random(myheight));
   int ry2 = int(random(myheight));
   line(rx1, ry1, rx2, ry2);
   pgpdf.line(rx1, ry1, rx2, ry2);    
   //and now one with y 0
   rx1 = int(random(mywidth));
   rx2 = int(random(mywidth));
   ry1 = 0;
   ry2 = myheight;
   line(rx1, ry1, rx2, ry2);
   pgpdf.line(rx1, ry1, rx2, ry2);
 }
 
 
pgpdf.endDraw();
 
}

thanx...
Page Index Toggle Pages: 1