inst
YaBB Newbies
Offline
Posts: 13
How to store positions for images of an array
Dec 14th , 2009, 2:53am
Hi, I found this great code from Daniel Shiffman to load 10 images, that are stored in an array. I would like to diplay the images on specified positions. Each image has an index-nr. in the array, that should correspond to a specified postion. Does anybody did tra this? thanks! frank ------------- int imgCount = 10; PImage[] imgs = new PImage[imgCount]; float imgW; // Keeps track of loaded images (true or false) boolean[] loadStates = new boolean[imgCount]; // For loading animation float loaderX, loaderY, theta; void setup() { size(800, 400); smooth(); imgW = width/imgCount; // Load images asynchronously for (int i = 0; i < imgCount; i++){ imgs[i] = requestImage("dublin"+i+".jpg"); } } void draw(){ background(0); // Start loading animation runLoaderAni(); for (int i = 0; i < imgs.length; i++){ // Check if individual images are fully loaded if ((imgs[i].width != 0) && (imgs[i].width != -1)){ // As images are loaded set true in boolean array loadStates[i] = true; } } // When all images are loaded draw them to the screen if (checkLoadStates()){ drawImages(); } } void drawImages(){ for (int i = 0; i < imgs.length; i++){ image(imgs[i], width/10*i, 0, imgW, height/10); //image(imgs[i], width/10*i, 0, imgW, height); } } // Loading animation void runLoaderAni(){ // Only run when images are loading if (!checkLoadStates()){ ellipse(loaderX, loaderY, 10, 10); loaderX += 2; loaderY = height/2 + sin(theta) * (height/2.5); theta += PI/22; // Reposition ellipse if it goes off the screen if (loaderX > width + 5){ loaderX = -5; } } } // Return true when all images are loaded - no false values left in array boolean checkLoadStates(){ for (int i = 0; i < imgs.length; i++){ if (loadStates[i] == false){ return false; } } return true; }