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 › newbie : direct to file writing
Page Index Toggle Pages: 1
newbie : direct to file writing ? (Read 1128 times)
newbie : direct to file writing ?
Jun 22nd, 2006, 12:27pm
 
im having code here generating some graphics, is it possible
to write the output directly to an image file after X amount of time or after keypress ? i need to have huge resolution for  a print project, thats why. like 10000x7000 pixels...

i got this from the FAQ, but i have no clue how to add it
in the actual code

void setup() {
 big = (PGraphics) createGraphics(3000, 3000, P3D);

 big.beginFrame();
 big.background(128);
 big.line(20, 1800, 1800, 900);
 // etc..
 big.endFrame();

 // make sure the file is written to the sketch folder
 String path = savePath("big.tif");
 big.save(path);
}


greetz,
timbre
Re: newbie : direct to file writing ?
Reply #1 - Jun 22nd, 2006, 7:41pm
 
You could probably add a counter to the draw() routine and then look for a certain amount to trigger the file write..


Quote:


int counter;

PGraphics big = new PGraphics(2000, 2000, null);

void setup() {
 big.background(128);
}

void draw()
{
 big.beginFrame();  
 big.line(20, 1800, 1800, 900);
 // etc..
 big.endFrame();

 counter++;
 if(counter >= 100)
 {
   // make sure the file is written to the sketch folder
   String path = savePath("big.tif");
   big.save(path);
   noLoop();  
 }
}



Re: newbie : direct to file writing ?
Reply #2 - Jun 22nd, 2006, 9:07pm
 
Well... that code will actually spit out a file, but I don't think it's working exactly right. I'm certain I don't know enough about this to be an expert.  Can someone else please chime in on why my code doesn't work?
Re: newbie : direct to file writing ?
Reply #3 - Jun 22nd, 2006, 9:12pm
 
In setup add big.defaults(), and you may need to make it a PGraphics3, to get it to work. Not sure you need the beginFrame/endFrame stuff either.
Re: newbie : direct to file writing ?
Reply #4 - Jun 22nd, 2006, 9:18pm
 
Aha!  This works!  Thanks, JohnG, I've been looking for a similar solution, so thanks for the tip. :)


Quote:


int counter;

PGraphics3 big = new PGraphics3(2000, 2000, null);

void setup() {
 big.background(128);
 big.defaults();
 // big.beginFrame();  
}

void draw()
{

 big.line(counter*10, 1800, 1800, 900);
 // etc..


 counter++;
 if(counter >= 100)
 {
  //  big.endFrame();
   // make sure the file is written to the sketch folder
   String path = savePath("big.jpg");
   big.save(path);  
   noLoop();
   
 }
}


Re: newbie : direct to file writing ?
Reply #5 - Jun 22nd, 2006, 9:23pm
 
Interesting to note that if you introduce

 big.smooth();  

to the setup, you get a .tif file... not a jpg.
Re: newbie : direct to file writing ?
Reply #6 - Jun 22nd, 2006, 9:28pm
 
just a love note, this is the day that processing got kicked up a huge notch for me. Smiley  This is so way cool being able to save gigantic files now.
Re: newbie : direct to file writing ?
Reply #7 - Jun 22nd, 2006, 9:44pm
 
wonderful !! im going to try tomorrow.
Re: newbie : direct to file writing ?
Reply #8 - Jun 23rd, 2006, 8:07pm
 
hi, for example how could i insert that counter/file writing code in this source ? if tried for hours but it won't work



//

int dimx = 900;
int dimy = 900;
int num = 0;
int maxnum = 200;

// grid of cracks
int[] cgrid;
Crack[] cracks;

// color parameters
int maxpal = 512;
int numpal = 0;
color[] goodcolor = new color[maxpal];

// sand painters
SandPainter[] sands;

// MAIN METHODS ---------------------------------------------

void setup() {
 size(900,900,P3D);
//  size(dimx,dimy,P3D);
 background(255);
 takecolor("some_image.gif");
 
 cgrid = new int[dimx*dimy];
 cracks = new Crack[maxnum];
 
 begin();  
}

void draw() {
 // crack all cracks
 for (int n=0;n<num;n++) {
   cracks[n].move();
 }
}

void mousePressed() {
 begin();
}
   

Page Index Toggle Pages: 1