Hello Processing Forum,
I am working on a project that is similar to a slot-machine. I am running 3 rows of images (animated gifs and I am stumped on whether I can construct a line of code in my current code logic that recognizes when all 3 columns have loaded the same matching gif when I press the space bar. Here is a simple version of my code to show you. (My actual project has sounds and many more gifs - it is busting at the seams in memory use but working!)
I am hoping I can solve this issue simply using a fairly similar structure. I am exhibiting this project as part of an installation in a week. Thank you for your help in dissecting this logic.
import gifAnimation.*;
//button switch variable
boolean toggle = true;
//image variables
PImage[] thumbs = new PImage[3];
float x;
float y1;
float y2;
float y3;
float thumbSpacing;
float thumbStripLength;
float thumbSpeed1;
float thumbSpeed2;
float thumbSpeed3;
void setup() {
size(900,300 ,P2D);
//load array of images
Gif loop0 = new Gif(this, "1.gif");
loop0.loop();
Gif loop1 = new Gif(this, "2.gif");
loop1.loop();
Gif loop2 = new Gif(this, "3.gif");
loop2.loop();
thumbs[0] = loop0;
thumbs[1] = loop1;
thumbs[2] = loop2;
y1=0;
x=0;
thumbSpacing = 300;
thumbStripLength = thumbSpacing*thumbs.length;
}
void draw() {
background(0);
smooth();
//spin 3 arrays at various speeds
if (toggle == true) {
//speeds of 3 spinning decks
thumbSpeed1 = 25;
thumbSpeed2 = 30;
thumbSpeed3 = 335;
y1 = y1 + thumbSpeed1;
y2 = y2 + thumbSpeed2;
y3 = y3 + thumbSpeed3;
} else {
//3 closest images stop in space when key presses
thumbSpeed1 = 0;
y1 = (int)(y1/thumbSpacing) * thumbSpacing;
y2 = (int)(y2/thumbSpacing) * thumbSpacing;
y3 = (int)(y3/thumbSpacing) * thumbSpacing;
//COULD I PUT A CONDITIONAL HERE TO LOAD A RED TRANSPARENCY RECT
//WHENEVER THE SAME 3 GIFS LOAD AFTER SPACE BAR IS PRESSED???
//I AM STRUGGLING ON HOW TO SEE THIS SOLUTION :)
//if ( ){
// fill (255,0,0,100);
// rect (0,0,900,300);
//}
} //<-- closes else
//array of images call
for (int i = 0; i < thumbs.length ; i++) {
image(thumbs[i], x , - (y1 + i * thumbSpacing) % thumbStripLength + height );
image(thumbs[i], x+300 , - (y2 + i * thumbSpacing) % thumbStripLength + height );
image(thumbs[i], x+600 , - (y3 + i * thumbSpacing) % thumbStripLength + height);
}
} // <-- closes draw
void keyPressed () {
toggle = !toggle;
}