|
Author |
Topic: Create Image Gallery... I need some help (Read 1393 times) |
|
kendokendokendo Guest
|
Create Image Gallery... I need some help
« on: Mar 17th, 2005, 7:22pm » |
|
Hey, What I'm trying to do is create two buttons - a forward button and a back button - and when you click them they go between 6 pictures. The program starts on picture 1, clicking back from pic 1 will make it go to pic 6, clicking forward from pic 6 will make it go to pic 1, etc. - sort of like an image gallery thing. I grasp the concept of what I have to do - tell it that when the button is pressed, it should evaluate which picture its on, and then depending on what picture its on it should load the next picture in the specified order. However, the syntax is really giving me hell. Here's what I got. It throws the "unspecified token; void" at void setup. //define all the variables int rectX, rectY; int circleX, circleY; int rectSize = 10; int circleSize = 10; color rectColor, circleColor; color rectHighlight, circleHighlight; boolean rectOver = false; boolean circleOver = false; BImage one; one = loadImage("one.JPG"); BImage two; two = loadImage("two.JPG"); BImage three; three = loadImage("three.JPG"); BImage four; four = loadImage("four.JPG"); BImage five; five=loadImage("five.JPG"); BImage six; six = loadImage("six.JPG"); BImage bread; bread = loadImage("bread.jpg"); int jerk = 0; //make the buttons and load the background image - general setting up void setup() { size(480, 640); background(255); image(bread); rectColor = color(120, 240, 120); circleColor = color(240, 120, 120); rectHighlight = color(0, 255, 0); circleHighlight = color(255, 0, 0); rectX = 30; rectY = 30; circleX = 10; circleY = 10; rectMode(CENTER_DIAMETER); ellipseMode(CENTER_DIAMETER); } //button interactivity - change color when pressed void loop() { update(mouseX, mouseY); background(255); if(rectOver) { fill(rectHighlight); } else { fill(rectColor); } rect(rectX, rectY, rectSize, rectSize); if(circleOver) { fill(circleHighlight); } else { fill(circleColor); } ellipse(circleX, circleY, circleSize, circleSize); } void update(int x, int y) { if (overCircle(circleX, circleY, circleSize)) { circleOver = true; rectOver = false; } else if (overRect(rectX, rectY, rectSize, rectSize)) { rectOver = true; circleOver = false; } else { circleOver = rectOver = false; } } //scroll forwards void mousePressed() { if(rectOver && jerk = 0) { jerk = jerk + 1; image(one); } if(rectOver && jerk = 1) { jerk = jerk + 1; image(two); } if(rectOver && jerk = 2) { jerk = jerk + 1; image(three); } if(rectOver && jerk = 3) { jerk = jerk + 1; image(four); } if(rectOver && jerk = 4) { jerk = jerk + 1; image(five); } if(rectOver && jerk = 5) { jerk = jerk + 1; image(six); } if(rectOver && jerk = 6) { image(one); } //scroll backwards if (circleOver && jerk = 6) { jerk = jerk - 1; image(six); if (circleOver && jerk = 5) { jerk = jerk - 1; image(five); } if (circleOver && jerk = 4) { jerk = jerk - 1; image(four); } if (circleOver && jerk = 3) { jerk = jerk - 1; image(three); } if (circleOver && jerk = 2) { jerk = jerk - 1; image(two); } if (circleOver && jerk = 1) { jerk = jerk - 1; image(one); } if (circleOver && jerk = 0) { jerk = jerk - 1; image(six); } } boolean overRect(int x, int y, int width, int height) { if (mouseX >= x && mouseX <= x+width && mouseY >= y && mouseY <= y+height) { return true; } else { return false; } } boolean overCircle(int x, int y, int diameter) { float disX = x - mouseX; float disY = y - mouseY; if (sqrt(sq(disX) + sq(disY)) < diameter/2) { return true; } else { return false; } }
|
« Last Edit: Mar 17th, 2005, 7:24pm by kendokendokendo » |
|
|
|
|
st33d
|
Re: Create Image Gallery... I need some help
« Reply #1 on: Mar 17th, 2005, 10:28pm » |
|
Wow. You know about the mouse listener but you don't know some other stuff. Code: /* set up the containers for your information first the funny [] brackets are containers with lots of "slots" in are called arrays */ BImage [] picture; int count; /* now fill up your containers and set the scene. You can join up setting an array, like BImage picture = new BImage[6]; But spacing it out will prepare you for creating arrays of any size if you go on to learn how to use objects and classes. It helps me to think of the program as one big class/object, that's how I'm setting this out for you. */ void setup(){ //this next line sets up the container slots, numbering 0 to 5 picture = new BImage[6]; //now fill up the slots picture[0] = loadImage("one.jpg"); picture[1] = loadImage("two.jpg"); picture[2] = loadImage("three.jpg"); picture[3] = loadImage("four.jpg"); picture[4] = loadImage("five.jpg"); picture[5] = loadImage("six.jpg"); /* if your file names were numbers you could do this: for (int i = 0; i < picture.length; i++){ picture[i] = loadImage(i+".jpg"); } which would help if you decide to expand your list of images */ count = 0; size(480,640); } /* I'm sticking the screen update stuff all in the main loop but you can move all that to an outside function if need be */ void loop(){ background(255); image(picture[count],0,0); rect(10,10,20,20); rect(width-30,10,20,20); } void mousePressed(){ if (overRect(10,10,20,20)){ /* what the "%" does is wrap the value of count back round to zero if it goes up to a value equal to the amount of slots in the picture array. Look up modulo. */ count = (count+1)%picture.length; } if (overRect(width-30,10,20,20)){ /* increment and decrement (++ & --) use less machine code than saying count = count + 1; and so are quicker */ count--; if (count < 0){ count = picture.length-1; } } } boolean overRect(int x, int y, int width, int height) { if (mouseX >= x && mouseX <= x+width && mouseY >= y && mouseY <= y+height) { return true; } else { return false; } } |
|
|
I could murder a pint.
|
|
|
kendokendokendo Guest
|
Re: Create Image Gallery... I need some help
« Reply #2 on: Mar 20th, 2005, 8:49pm » |
|
this helped me out greatly - thanks.
|
|
|
|
|