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 › creating interactive image class
Page Index Toggle Pages: 1
creating interactive image class (Read 636 times)
creating interactive image class
Apr 23rd, 2009, 11:09am
 
hello,
i am a student trying my hardest to learn processing.  I am trying to create a PImage class that will load a 6-10 images in random positions to the screen, this small yet critical thing i cannot seem to understand. i know how to load images, but not loading multiple images into one class.

any advice ????  help ?? any specific functions that might work best ?? many many joyous thanks for anything !!!


Re: creating interactive image class
Reply #1 - Apr 23rd, 2009, 11:30am
 
I'm not sure I understand the question... could you load all the images at start and then just call them in the class?
PImage img1, img2, img3;
....
img1 = loadImage("img1.png");
img2 = loadImage("img2.png");
img3 = loadImage("img3.png");
....
image(img1, (int)random(0,width), (int)random(0,height));
Re: creating interactive image class
Reply #2 - Apr 23rd, 2009, 12:23pm
 
class imageArray
{
 PImage[] arr;
 int n;
 imageArray(int n_)
 {
   n=n_;
   arr=new PImage[n];
 }
 //function(you can write a constructor also)
 void initialize(String dir0,String dir1,,String dirnminus1)
 {
   arr[0]=loadImage(dir0);
   arr[1]=...
 }
}
imageArray imArr;
//initialize it and write this
void drawImages()
{
 for(int i=0;i<n;i++)
 image(imArr.arr[i],(int)random(0,width),(int)random(0,height))
}
Page Index Toggle Pages: 1