• fullscreen
  • Button.pde
  • pluto_a_planet.pde
  • class Button{
    int x,y;
    int size;
    color baseGray;
    color overGray;
    color pressGray;
    boolean over = false;
    boolean pressed = false;
    
    Button(int xp, int yp, int s, color b, color o, color p){
      x = xp;
      y = yp;
      size = s;
      baseGray = b;
      overGray = o;
      pressGray = p;
    }
    
    void update(){
      if ((mouseX >= x) && (mouseX <= x+size) &&
          (mouseY >= y) && (mouseY <= y+size)){
            over = true;
          } else {
            over = false;
          }
    }
    
    boolean press(){
      if(over == true){
        pressed = true;
        return true;
      } else {
        return false;
      }
    }
    
    void release(){
      pressed = false;
    }
    
    void display(){
      if (pressed == true){
        fill(pressGray);
      }else if (over == true){
        fill(overGray);
      }else{
        fill(baseGray);
      }
      stroke(0);
      rect(x,y,size,size);
    }
    }
    
    //used book's button code to create this
    
    Button button, button2;
    int mode = 0;
    
    void setup(){
      size(200,400);
      button = new Button(125,200,50,color(204),color(255),color(0));
      button2 = new Button(125,300,50,color(204),color(255),color(0));
    }
    
    void draw(){
      background(255);
      fill(0);
      text("Is Pluto a planet?", 50,50);
      text("Yes",75,225);
      text("No",75,325);
      manageButtons();
      
      if(mode == 1){
        fill(0,255,0);
        rect(0,0,200,400);
        fill(255);
        text("CORRECT!",75,height/2);
        text("Pluto is NOT a planet",50,220);
      }
      
      if(mode == 2){
        fill(255,0,0);
        rect(0,0,200,400);
        fill(255);
        text("WRONG",75,height/2);
        text("Pluto is NOT a planet",50,220);
      }
    }
    
    
    void manageButtons(){
      button.update();
      button.display();
      button2.display();
      button2.update();
    }
    
    void mousePressed(){
      if (button.press() == true) {mode = 2;}
      if (button2.press() == true) {mode = 1;}
    }
    
    void mouseReleased(){
      button.release();
      button2.release();
    
    }
    

    code

    tweaks (0)

    about this sketch

    This sketch is running as Java applet, exported from Processing.

    license

    advertisement

    Maximilian Uriarte

    Is Pluto a Planet?

    Add to Faves Me Likey@!
    You must login/register to add this sketch to your favorites.

    For Bryn.

    :-)

    Bryn Fraker
    28 Nov 2011
    HEY! I just wanted to let you know there are some factual inaccuracies in your sketch hahahahahaha
    You need to login/register to comment.