We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi there. I'm a little new to processing, only been using it for two months now and I got this basic code running and all. But there's one thing I want to do that I'm not sure of how to do.
I want to create a delay of some sort for the images. It's supposed to be like a memory game with cards and right now it's only one click one card but I want to keep one image open and have a second one revealed and then disappear (with redraw). Even if it's an artificial delay, anything will do. Here's my code that does run successfully with one card revealed at a time. The goal: Two cards revealed and then back to hiding. Thank you all so much.
PImage[] images = new PImage[8];
PFont f;
void setup() {
size(1000, 600);
noFill();
smooth();
f = createFont("Arial", 20, true);
for (int i=0; i < images.length; i++) {
images[0] = loadImage("Art.png");
images[1] = loadImage("Brain.png");
images[2] = loadImage("Cat.png");
images[3] = loadImage("Dog.jpg");
images[4] = loadImage("Movie.png");
images[5] = loadImage("Music.png");
images[6] = loadImage("Phone.png");
images[7] = loadImage("Psych.gif");
noLoop();
}
}
void draw() {
background(0);
fill(255);
rect(25, 10, 200, 250); //rectangle at 25
pushMatrix();
translate(200, 0);
rect(50, 10, 200, 250); //rectangle at 250
translate(200, 0);
rect(75, 10, 200, 250); // rectangle at 475
translate(200, 0);
rect(100, 10, 200, 250); //rectangle at 700
popMatrix();
rect(25, 280, 200, 250); //rectangle at 25
pushMatrix();
translate(200, 0);
rect(50, 280, 200, 250);
translate(200, 0);
rect(75, 280, 200, 250);
translate(200, 0);
rect(100, 280, 200, 250);
popMatrix();
if (mousePressed == mouseX < 225 && mouseX > 0 && mouseY > 0 && mouseY < 250) {
image(images[(int)random(8)], 25, 10);
}
if (mousePressed == mouseX < 450 && mouseX > 250 && mouseY > 0 && mouseY < 250) {
image(images[(int)random(8)], 250, 10);
}
if (mousePressed == mouseX < 675 && mouseX > 475 && mouseY > 0 && mouseY < 250) {
image(images[(int)random(8)], 475, 10);
}
if (mousePressed == mouseX < 1000 && mouseX > 700 && mouseY > 0 && mouseY < 250) {
image(images[(int)random(8)], 700, 10);
}
if (mousePressed == mouseX < 225 && mouseX > 0 && mouseY > 280 && mouseY < 500) {
image(images[(int)random(8)], 25, 280);
}
if (mousePressed == mouseX < 450 && mouseX > 250 && mouseY > 280 && mouseY < 500) {
image(images[(int)random(8)], 250, 280);
}
if (mousePressed == mouseX < 675 && mouseX > 475 && mouseY > 280 && mouseY < 500) {
image(images[(int)random(8)], 475, 280);
}
if (mousePressed == mouseX < 1000 && mouseX > 700 && mouseY > 280 && mouseY < 500) {
image(images[(int)random(8)], 700, 280);
}
textFont(f, 32);
fill(255);
text("Match The Pictures",325, 575);
}
void mousePressed() {
redraw();
}
Comments
try a variable that holds whether one image is already open or not
isFirstImage = false;
when mouse clicked 1st time
isFirstImage = true;
when mouse clicked 2nd time
this is a timer
but you need a way to store where which image is, so you can check whether 2 are equal