/* * Afficher une image en plein écran * un clic sur le bord fait glisser l'image * et affiche l'image contigue de la mosaïque * les bords bouclent * * 0 1 2 3 images dans le tableau * 4 5 6 7 * 8 9 10 11 * 12 13 14 15 * * noms des fichiers dans la mosaique * tous le sfichiers sont de dimensions identiques * * 00-00.jpg 00-01.jpg 00-02.jpg 00-03.jpg * 01-00.jpg 01-01.jpg 01-02.jpg 01-03.jpg * 02-00.jpg 02-01.jpg 02-02.jpg 02-03.jpg * 03-00.jpg 03-01.jpg 03-02.jpg 03-03.jpg * */ int xnb = 4; int ynb = 4; int imgw = 1024; int imgh = 768; PImage[] images = new PImage[xnb*ynb]; boolean is_moving = false; int image_en_cours = 0; // numéro de l'image dans le tableau des fichiers int image_next; int transition = 50; int transition_compteur = transition; int x = 0; // coordonnées de la case en cours int y = 0; int x_mod, y_mod; int x_next, y_next; char direction; float xi = 0; // point d'affichage de l'image float yi = 0; float xin, yin; // point d'affichage de la 2e image quand mouvement void setup() { size(1024, 768); frameRate(50); images[0] = loadImage("00-00.jpg"); images[1] = loadImage("00-01.jpg"); images[2] = loadImage("00-02.jpg"); images[3] = loadImage("00-03.jpg"); images[4] = loadImage("01-00.jpg"); images[5] = loadImage("01-01.jpg"); images[6] = loadImage("01-02.jpg"); images[7] = loadImage("01-03.jpg"); images[8] = loadImage("02-00.jpg"); images[9] = loadImage("02-01.jpg"); images[10] = loadImage("02-02.jpg"); images[11] = loadImage("02-03.jpg"); images[12] = loadImage("03-00.jpg"); images[13] = loadImage("03-01.jpg"); images[14] = loadImage("03-02.jpg"); images[15] = loadImage("03-03.jpg"); } void draw() { if (is_moving) { // la transition est en cours // chercher la direction if (transition_compteur == transition) { if (x_mod == -1) direction = 'g'; // gauche if (x_mod == 1) direction = 'd'; // droite if (y_mod == -1) direction = 'h'; // haut if (y_mod == 1) direction = 'b'; // bas } transition_compteur --; if (transition_compteur > 0) { switch(direction) { case 'g': xi = imgw / transition * (transition - transition_compteur); xin = -imgw + xi; yin = 0; yi = 0; break; case 'd': xi = - (imgw / transition * (transition - transition_compteur)); xin = imgw + xi; yin = 0; yi = 0; break; case 'b': xin = 0; xi = 0; yi = - (imgh / transition * (transition - transition_compteur));; yin = imgh + yi; break; case 'h': xin = 0; xi = 0; yi = imgh / transition * (transition - transition_compteur); yin = -imgh + yi; break; } image(images[image_next], xin, yin, width, height); image(images[image_en_cours], xi, yi, width, height); } else { // quand la transition est terminée image_en_cours = image_next; is_moving = false; transition_compteur = transition; } } else { image(images[image_en_cours], 0, 0, width, height); } } void mousePressed() { if (!is_moving) { x_mod = 0; y_mod = 0; if (mouseX < 100) x_mod = -1; //direction = "g"; // gauche else if (mouseX > 924) x_mod = 1; //direction = "d"; // droite else if (mouseY < 100) y_mod = -1; //direction = "h"; // haut else if (mouseY > 668) y_mod = 1; //direction = "b"; // bas else {x_mod = 0; y_mod = 0;} if ((x_mod != 0) || (y_mod != 0)) { x_next = x + x_mod; y_next = y + y_mod; if (x_next < 0) x_next = xnb - 1; if (x_next > (xnb-1)) x_next = 0; if (y_next < 0) y_next = ynb - 1; if (y_next > (ynb-1)) y_next = 0; image_next = x_next + y_next * 4; is_moving = true; x = x_next; y = y_next; print("image en cours : " + image_en_cours); print(" / image next : " + image_next); println(" / case (x,y) : " + x_next + ", " + y_next); } } }