lookoutforthatcow
YaBB Newbies
Offline
Posts: 3
Re: Problems with buttons
Reply #1 - Mar 19th , 2009, 6:58pm
This is the code guys int redX, redY; //position of red button int blueX, blueY; //position of blue button int greenX, greenY; //position of green button int eraseX, eraseY; //position of erase button int whiteX, whiteY; //position of white button int blueSize = 25; //diamater of blue button int redSize = 25; //diamater of red button int greenSize = 25; //diamater of green button int eraseSize = 25; //diameter of green button int whiteSize = 25; //diameter of a green button int y = mouseY; int x = mouseX; color redColour, blueColour, greenColour; color whiteColour, whiteHighlight; color redHighlight, blueHighlight, greenHighlight; color penColour, eraseColour, eraseHighlight; boolean redOver = false; boolean greenOver = false; boolean blueOver = false; boolean eraseOver = false; boolean whiteOver = false; void setup() { background(255); size(768,520); smooth(); redColour = color(180,0,0); greenColour = color(0,180,0); blueColour = color(0,0,180); whiteColour = color(255); eraseColour = color(0); eraseHighlight = color(100); redHighlight = color(100); greenHighlight = color(100); blueHighlight = color(100); whiteHighlight = color(100); penColour = color(0); redX = 20; redY = 480; greenX = 55; greenY = 480; blueX = 90; blueY = 480; eraseX = 125; eraseY = 480; whiteX = 160; whiteY = 480; //red button if(redOver) { fill(redHighlight); } else { fill(redColour); } rect(redX,redY,redSize,redSize); stroke(2); //green button if(greenOver) { fill(greenHighlight); } else { fill(greenColour); } rect(greenX,greenY,greenSize,greenSize); stroke(2); //blue button if(blueOver) { fill(blueHighlight); } else { fill(blueColour); } rect(blueX,blueY,blueSize,blueSize); stroke(2); //black button if(eraseOver) { fill(eraseHighlight); } else { fill(eraseColour); } rect(eraseX,eraseY,eraseSize,eraseSize); stroke(2); //whitebutton if(whiteOver) { fill(whiteHighlight); } else { fill(whiteColour); } rect(whiteX,whiteY,whiteSize,whiteSize); stroke(2); } void draw() { // draw if mouse pressed if (mousePressed) { line(pmouseX, pmouseY, mouseX, mouseY); stroke(penColour); strokeWeight(3); } else if (y > 480) { strokeWeight(0); } //large colours if (mouseButton == RIGHT){ stroke(random(255),random(255),random(255)); strokeWeight(20); } if(keyPressed){ if(key=='c' || key == 'C'){ background(255); } } if( redOver(redX,redY,redSize, redSize)) { redOver = true; blueOver = false; greenOver = false; eraseOver = false; whiteOver = false; } else if ( blueOver(blueX,blueY,blueSize,blueSize)) { blueOver = true; redOver = false; greenOver = false; eraseOver = false; whiteOver = false; } else if ( greenOver(greenX,greenY,greenSize,greenSize)) { greenOver = true; blueOver = false; redOver = false; eraseOver = false; whiteOver = false; } else if ( eraseOver(eraseX,eraseY,eraseSize,eraseSize)) { eraseOver = true; blueOver = false; greenOver = false; redOver = false; whiteOver = false; } else if ( whiteOver(whiteX,whiteY,whiteSize,whiteSize)) { eraseOver = false; blueOver = false; greenOver = false; redOver = false; whiteOver = true; } else { redOver = greenOver = blueOver = eraseOver = false; } } boolean redOver(int x, int y, int width, int height) { if (mouseX >= 25 && mouseX <= 50 && mouseY >= 480 && mouseY <= 505) { return true; } else { return false; } } boolean greenOver(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 blueOver(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 eraseOver(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 whiteOver(int x, int y, int width, int height) { if (mouseX >= x && mouseX <= x+width && mouseY >= y && mouseY <= y+height) { return true; } else { return false; } } void mousePressed() { if(redOver) { penColour = redColour; } if(greenOver) { penColour = greenColour; } if(blueOver) { penColour = blueColour; } if (eraseOver) { penColour = eraseColour; } if (whiteOver) { penColour = whiteColour; } }