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 › pictures on a row
Page Index Toggle Pages: 1
pictures on a row (Read 347 times)
pictures on a row
Oct 4th, 2007, 3:09pm
 
i need a better way of doing this. i want the picture to be copied 4 times to the right and then let it fall back one on one, just like it does in this sketch. the problem is just that there's a  big break when the images have to go back.

PImage cola;
int move = 0;
int hello = 0;

void cola(){

 if(frameCount%30 == 0)
 {
   move += cola.width+20;
 }


 if ( move > 4*(cola.width+20)){
   hello++;
 }

 if ( hello == 1){
     if(frameCount%30 == 0)
 {
   move -= cola.width+20;
   
 }
}
 
   if(move == -(cola.width+20))
 {
   
   move += cola.width+20;
 }
 
 

 for (int x = 200; x < move; x = x + cola.width+20){

   image(cola,x,180);


 }
}
Re: pictures on a row
Reply #1 - Oct 4th, 2007, 7:04pm
 
I'm not sure I quite understand your request because I couldn't test your code properly.

Try this... it creates a tile background using an image.
It works better with a small image.
------------------------------------------------------
PImage imageName;
int deltaX = 5; //space between images on the X axis
int deltaY = 5; //space between images on the Y axis

void setup() {
 size(800,800);
 background(0);
 
 imageName = loadImage("image01.gif"); //loads the image
 
 noLoop(); //only plays once
}

void draw() {
 int numberOfImages = width * height / (imageName.width + deltaX) * (imageName.height + deltaY); //counts the number of images it has to place. Total area of the sketch divided by the area of the image
 int row = 0; //initialize row

 for (int i = 0; i < numberOfImages; i++)  {
   //if i has reached it's peak value,
   if (i % int(width/imageName.width + deltaX) == 0) {
     row++;  //then add a new row
   }
   
   //position the image at the right X and Y
   image(imageName, i % int(width/imageName.width + deltaX) * (imageName.width + deltaX), (row-1) * (imageName.height+ deltaY), imageName.width, imageName.height);
 }
}
----------------------------------------------------------

Hope it helped!
Steven
Page Index Toggle Pages: 1