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 & HelpOpenGL and 3D Libraries › Size of ouput TIF file
Page Index Toggle Pages: 1
Size of ouput TIF file (Read 1142 times)
Size of ouput TIF file
May 8th, 2007, 10:54am
 
Hi,
I'm new to Processing and I am trying to create non-repeating textile patterns. I want to output them to tif files to be printed on fabric, but they need to be large (about 3000 x 1500). I've included the OPENGL library to help, but at the moment the biggest size I can export is 1200 x 400. Having increase the amount of memory available, I don't get crashes if I go bigger, but the resultant image only takes up a small amount of the canvas and the rest is black (it looks OK on the windows screen). I have a new Dell Optiplex 745 with it's inbuilt graphics card. Is this likely to be the problem (I have a new card on order), or is the restriction on size something more inherent to Processing? All advice welcome!
Re: Size of ouput TIF file
Reply #1 - May 8th, 2007, 12:14pm
 
There is code around, that will let you create large images, as a series of tiles which you can then put together in an external image manipulation program.

http://workshop.evolutionzone.com/2007/03/24/code-tilesaverpde/

is one example that I know of.
Re: Size of ouput TIF file
Reply #2 - May 8th, 2007, 3:07pm
 
Hi, thanks for such a quick reply. The site you recommended looked great and the code worked perfectly with the example. However, I'm creating an image with randomly placed motifs and I hence I need noLoop() to stop it regenerating. This seems to stop the Tile Saver working. I've left a post on that website - not expecting anyone to answer specifics on that code, but wondered if I was generally on to a loser with this?
Thanks again!
Re: Size of ouput TIF file
Reply #3 - May 9th, 2007, 12:34am
 
With Marius' tiling code you'll need to be able to execute draw() consecutively *without* the scene changing to render out each of the tiled sub-images.  (this also implies that you're running in loop() mode)

This should just be a matter of restructuring your code a bit, so that the "make new pattern" logic is removed from the draw loop, allowing it to run in loop() mode, so the tiler can call draw() as necessary to build up the full image.   You can also inspect the isTiling property of the tiler to see if it's currently in the middle of a tiling operation, if you're trying to auto-generate lots of patterns, perhaps something like:

Code:

void draw() {
if (tiler.isTiling) {
// just render the scene as is
tiler.pre();
DrawCurrentPattern();
tiler.post();
} else {
// tiler is inactive or done, so create a new scene:
GenerateNewPattern();
// and draw it to screen (if you wish, optional)
DrawCurrentPattern();
// AND request the tiler begin anew to render it:
tiler.init("whatever", 4);
}
}


(not checked for accuracy, just for concepts)
Re: Size of ouput TIF file
Reply #4 - May 15th, 2007, 7:01pm
 
Hi, thanks again for more helpful and prompt replies. I have managed to get tiling of a sort now, but it is obvious that the screen is redrawing in between the tiles generating as they don't quite match.

I'm sure I'm being really thick, but I just can't see how to stop it constantly regenerating without using noloop(). I have taken the drawing code out of draw() now, as suggested, but draw still calls it over and over again. It's a simple example - just a for loop that runs 1000 times and draws a shape at randomly generated coordinates. The image is finished when the for loop stops, but how can I prevent it being called over and over by draw()?

Sorry - I know I'm being a pain but I've an exhibition coming up and I'd really like to get fabric printed with patterns created in Processing
Re: Size of ouput TIF file
Reply #5 - May 15th, 2007, 7:15pm
 
One solution is to create an array or two to store all the coordinates, populate it within setup, and then draw the shapes from the array in draw, that way each frame will be the same.
Re: Size of ouput TIF file
Reply #6 - May 19th, 2007, 3:21pm
 
Hi & Thanks again for your time. I've done as you say - whihc seemed like a great idea - but the array isn't recognised in draw() - the help reference for setup() suggests that you can't access variables initialised here, so I think I've got the wrong end of the stick. Is there any sample code you could point me at that shows how to access variables initialised in setup()?

Re: Size of ouput TIF file
Reply #7 - May 19th, 2007, 3:38pm
 
try this:

Code:

int[] arrayA;
int[] arrayB;

void setup()
{
size(...);
arrayA=new int[200]; //or whatever..
arrayB=new int[200];
//build the contents of the arrays
}

void draw()
{
//use the arrays here
}
Re: Size of ouput TIF file
Reply #8 - May 19th, 2007, 3:52pm
 
Hi, didn't expect a reply that fast! I have done as you say (code below - not very elegant!) but I now get the error:

'The variable coord1 may be accessed before having been definitely assigned a value' I know the logic is OK, because the correct pattern appears on he screen if I put all the code back into draw().


float [][] coord1;
 float [][] coord2;
 float [][] coord2a;
 float [][] coord3;
 float [][] coord3a;
 float [][] coord4;
 
void setup() {
 size(1500,500, OPENGL);
 noStroke();
 
 coord1 = new float [6000] [2];
 coord2 = new float [6000] [2];
 coord2a= new float [6000] [2];
 coord3 = new float [6000] [2];
 coord3a = new float [6000] [2];
 coord4 = new float [6000] [2];
 for(int i=0; i<6000; i++) {
     coord1[i][0] = random(0, width);
     coord1[i][1] = random(0, height);
     coord4[i][0] = coord1[i][0] + random(0, 30) + 10;
     coord4[i][1] = coord1[i][1];  
     coord2[i][0]  = coord1[i][0]  + ((coord4[i][0]  - coord1[i][0] )/3);
     coord2[i][1] = (coord1[i][1] + 2 + random(0,3));
     coord2a[i][0] = coord2[i][0];
     coord2a[i][1] = coord1[i][1] -(coord2[i][1] - coord1[i][1]);
     coord3[i][0] =coord1[i][0] + ((coord4[i][0] - coord1[i][0]) * 2  / 3);
     coord3[i][1] = (coord1[i][1] + 4 + random(0,3));
     coord3a[i][0] = coord3[i][0];
    coord3a[i][1] = coord1[i][1] - (coord3[i][1] - coord1[i][1]);
 }
     tiler=new TileSaver(this);
 //noLoop();
}


public void draw() {
 
 if(tiler==null) return; // Not initialized
  // call TileSaver.pre() to prepare frame and setup camera if it exists.
    //if (first==0) {
    tiler.pre();
    background(150,113,68);
  float theta;
 float [][] coord1;
 float [][] coord2;
 float [][] coord2a;
 float [][] coord3;
 float [][] coord3a;
 float [][] coord4;
 
  for(int i=0; i<6000; i++) {
    float colr = random(60, 120);
    float colg = random(110, 225);
    float colb = random(35, 110);
    float angle = random (0, 180);  
    theta = radians(angle);
    rotate(theta);
    bezier(coord1[i][0], coord1[i][1], coord2[i][0], coord2[i][1], coord3[i][0], coord3[i][1], coord4[i][0], coord4[i][1]);
    bezier(coord1[i][0], coord1[i][1], coord2a[i][0], coord2a[i][1], coord3a[i][0], coord3a[i][1], coord4[i][0], coord4[i][1]);
   fill(colr,colg,colb);
   stroke(colr,colg,colb);
   translate(0,0);
   rotate(-theta);
    tiler.post();
  }
 }
Re: Size of ouput TIF file
Reply #9 - May 19th, 2007, 4:29pm
 
You're re-defining coord1 etc in draw.. don't.

take: Code:
   float [][] coord1;
float [][] coord2;
float [][] coord2a;
float [][] coord3;
float [][] coord3a;
float [][] coord4;


out of draw().
Re: Size of ouput TIF file
Reply #10 - May 19th, 2007, 4:55pm
 
OK, that's fanastic - it now appears to draw to screen and doesn't attempt to redraw... only problem is the resulting tga image is blank - it is filled with the background colour but no shapes. Strangely (or not?) the preview png image is fine.
I'm sure you must be hacked off with trying to sort my code out by now, so I think I'll make this my last attempt. The working(?) code is below. Thanks again.

import processing.opengl.*;

TileSaver tiler;

 float [][] coord1;
 float [][] coord2;
 float [][] coord2a;
 float [][] coord3;
 float [][] coord3a;
 float [][] coord4;
 color [] shapecol;
 float[] theta;
 
void setup() {
 size(600,200, OPENGL);
 noStroke();
 
 coord1 = new float [6000] [2];
 coord2 = new float [6000] [2];
 coord2a= new float [6000] [2];
 coord3 = new float [6000] [2];
 coord3a = new float [6000] [2];
 coord4 = new float [6000] [2];
 shapecol = new color [6000];
theta = new float[6000];
 for(int i=0; i<6000; i++) {
     coord1[i][0] = random(0, width);
     coord1[i][1] = random(0, height);
     coord4[i][0] = coord1[i][0] + random(0, 30) + 10;
     coord4[i][1] = coord1[i][1];  
     coord2[i][0]  = coord1[i][0]  + ((coord4[i][0]  - coord1[i][0] )/3);
     coord2[i][1] = (coord1[i][1] + 2 + random(0,3));
     coord2a[i][0] = coord2[i][0];
     coord2a[i][1] = coord1[i][1] -(coord2[i][1] - coord1[i][1]);
     coord3[i][0] =coord1[i][0] + ((coord4[i][0] - coord1[i][0]) * 2  / 3);
     coord3[i][1] = (coord1[i][1] + 4 + random(0,3));
     coord3a[i][0] = coord3[i][0];
    coord3a[i][1] = coord1[i][1] - (coord3[i][1] - coord1[i][1]);
    float colr = random(60, 120);
    float colg = random(110, 225);
    float colb = random(35, 110);
    shapecol[i] = color(colr, colg, colb);
    float angle = random (0, 180);  
    theta[i] = radians(angle);
 }
     tiler=new TileSaver(this);
   smooth();
 //noLoop();
}

public void draw() {
 
 if(tiler==null) return; // Not initialized
  // call TileSaver.pre() to prepare frame and setup camera if it exists.
    //if (first==0) {
    tiler.pre();
    background(150,113,68);
 
  for(int i=0; i<6000; i++) {
    rotate(theta[i]);
    bezier(coord1[i][0], coord1[i][1], coord2[i][0], coord2[i][1], coord3[i][0], coord3[i][1], coord4[i][0], coord4[i][1]);
    bezier(coord1[i][0], coord1[i][1], coord2a[i][0], coord2a[i][1], coord3a[i][0], coord3a[i][1], coord4[i][0], coord4[i][1]);
   fill(shapecol[i]);
   stroke(shapecol[i]);
   translate(0,0);
   rotate(-theta[i]);
    tiler.post();
  }
 }
Re: Size of ouput TIF file
Reply #11 - May 19th, 2007, 5:15pm
 
"tiler.post()" should probably occur one line later, *after* your for loop has drawn everything.
Re: Size of ouput TIF file
Reply #12 - May 19th, 2007, 5:24pm
 
That's it! You've cracked it. Thank you so much for all your time.
Page Index Toggle Pages: 1