thumbnails - Image gallery assistance if you may -
i created image gallery works great, problem have don't know how set program when open it opens pictures thumbnails , if click on thumbnails image expands.
int maximages; int imageindex; // declaring array of images. pimage[] images; void setup() { size(600,400); images = new pimage[maximages]; maximages = 2; imageindex = 0; // initial image displayed first (int = 0; < images.length; ++ ) { images[i] = loadimage( "changeling" + + ".jpg" ); } } void draw() { // displaying 1 image image(images[imageindex],0,0); }
here it's idea, show images i'm setting them whit width , height of 100 can use value or own algorithm best sizes. knowing space in sketch every image occupies can know when mouse inside 1 of them when mouse click event happen. proceed expand image doubling size until reaches size comparing whit screen size, again can use own value or algorithm best expansion ratio. once mouse it's clicked again when image expanded goes thumbnail again.
hope can useful.
int maximages; int imageindex; boolean imageexpand; // declaring array of images. pimage[] images; void setup() { size(600,400); maximages = 2; imageindex = 0; // initial image displayed first boolean imageexpand; images = new pimage[maximages]; imageexpand = false; (int = 0; < images.length; ++ ) { images[i] = loadimage( "changeling" + + ".jpg" ); } } void draw() { if(!imageexpand){ showthumbnail(); } } void mouseclicked(){ if(!imageexpand){ for(int i=0; < images.length; i++){ if((images[i].x > mousex) && (images[i].x + images[i].width < mousex)){ if((images[i].y > mousey) && (images[i].y + images[i].height < mousey)){ expandimage(images[i]); imageexpand = true; } } } } else{ imageexpand = false; showthumbnail(); } } void expandimage(pimage myimage){ int largewidth, largeheight; while((myimage.width * 2 < 600) && (myimage.height * 2 < 400)){ largewidth = myimage.width * 2; largewidth = myimage.height * 2; } image(myimage, 0, 0, largewidth, largeheight); } void showthumbnail(){ int posx = 0, posy = 0, lastimage = 0; for(int i=0; < images.length; i++){ if(posx + 100 < 600){ image(images[i], posx, posy, 100, 100); posx = posx + 100; } else{ posx = 0; posy = posy + 100; image(images[i], posx, posy, 100, 100); } } } regards jose
Comments
Post a Comment