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 & HelpSyntax Questions › simple math question
Page Index Toggle Pages: 1
simple math question (Read 524 times)
simple math question
Mar 26th, 2009, 4:29pm
 
hello,
so, i need to tile an image using integers in the x position, (tiling one image 30 times from the 0 x position)  i do not know how to do this (so i dont have to write out all the exact coordinates)


PImage a, b;




void setup(){
 size(772, 390);
 background(255);
 a = loadImage("bar.png");
 b = loadImage("slider.png");
 noLoop();
 

}

void draw(){
 image(a, 0, 0);





}


i need a function in the second 0 of the image(a) to tile it down.  help ! (im super new to this!)

thanks
Re: simple math question
Reply #1 - Mar 26th, 2009, 4:55pm
 
You need a loop to repeat the image copy.
You need to shift the coordinates of each copy by the width of the image.
That would be:

void draw()
{
 int xPos = 0;
 do
 {
   image(a, xPos, 0);
   xPos += a.width;
 } while (xPos < width);
}
Re: simple math question
Reply #2 - Mar 26th, 2009, 12:54pm
 
And by extension, you need another very similar loop to do the y-coordinate direction.

The trick is (and I remember this not being obvious to me when I was learning programming back in the dark ages) is that to tile the image over the whole sketch window you'll need to put one of the loops _inside_ the other.  Not one after the other.
Page Index Toggle Pages: 1