We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am a french student in graphic design. For my graduation diploma, I use processing, and currently I have a problem with my code.
In fact, I do not know how to change my lists by increasing and decreasing with the keys "up" and "down".
Here is my code:
PImage[] images0 = new PImage[6] ;
PImage[] images1 = new PImage[6] ;
PImage[] images2 = new PImage[6] ;
PImage[] images3 = new PImage[6] ;
PImage[] images4 = new PImage[6] ;
PImage[] images5 = new PImage[6] ;
void setup() {
size(600,600);
frameRate(4);
for(int i=0; i<6; i++) for(int images=0; images<6; images++) {
images0[i] = loadImage("module_" + i + ".png");
images1[i] = loadImage("module1_" + i + ".png");
images2[i] = loadImage("module2_" + i + ".png");
images3[i] = loadImage("module3_" + i + ".png");
images4[i] = loadImage("module4_" + i + ".png");
images5[i] = loadImage("module5_" + i + ".png");}
}
void draw() {
background(255);
smooth();
noStroke();
noFill();
image(images1[(int)random(6)], 0, 0);
if (keyCode == UP){
background(255);
image(images3[(int)random(6)], 0, 0);}
}
For now I am interested in the action of changing the list increasingly. I guess the reverse code itself, more or less.
My goal is that when the "up" key is pressed once, the list1 goes to the list2, and when pressing the "up" key again, list 2 goes to list3, etc.
I thank you in advance and apologize if my English is bad.
I look forward to your advice.
Answers
Some hints:
Put the keyCode statements inside keyPressed() routine of Processing.
Use a variable to remember the current list (i.e. the list to move).
When press UP use a temporary list to exchange the two lists.
What want you do when the current list is the last list ?
When it's the last list, it's the last list that's played. And if the user wants to go back to a previous list, he must press the "down" key.
Sorry I'm still a little novice in processing. But what do you say:
I need to create a variable like this:
And place it in the void. draw() ?
This is untested code but it should work. I made few changes but nothing critical.
Kf
thank kfrajer
But when I play the program, processing displays:
For the line:
You can use a 2D array (untested), but remember to rename your "module_n.png" files to "module0_n.png" -
thank you so much Lord_of_the_Galaxy
It works. But my lists do not come alive ... I don't understand why?
Animation stays frozen on the last image of each list.
Please explain.
When I play the program, the first list appears and the same for others. But normally each list composed of images should activate as a gif.
For example:
I launch the program.
The first list appears as a gif.
I press the "up" key, the second list appears as a gif.
Etc.
But it does:
I launch the program.
The first list appears on my last picture of my list.
Etc.
Etc.
I do not know if I'm clear :/
https://instagram.com/p/BR__kGrjmee/?taken-by=jordan_le_cointre
like this.
Oh, so that's what you want? I got a bit confused because of @kfrajer's approach.
Try this -
I found!
It was just a value that was not in its right place.
instead of :
Thank you so much to all of you! You helped me a lot and I thank you again. :)
(Oops :D ) Still, check out my new program. I think that's more like what you may want.
it works ! ;) thanks again :)