• fullscreen
  • workshop_3.pde
  • // Pressing Control-R will render this sketch.
      
      
    float rx, ry;    // rectangle x- and y-coordinate
    float rd = 100;  // rectangle width
      
    float ex, ey;    // ellipse x- and y-coordinate
    float ed = 106;  // ellipse diameter
      
    void setup() {
      size(640, 360);
      smooth();
       
      // Set the x- and y-coordinates for the rectangle
      rx = width * 0.33 - rd/2;
      ry = height * 0.5 - rd/2;
       
      // Set the x- and y-coordinates for the ellipse
      ex = width * 0.66;
      ey = height * 0.5;
    }
      
    void draw() {
      background(102);
      float d = dist(mouseX, mouseY, ex, ey);
      
      //rectangle rollover
    
      if ((mouseX > rx) && (mouseY > ry) && (mouseX < rx + rd) && (mouseY < ry + rd)) {
       fill(0); 
      } else {
       fill(255); 
       }
       
         rect(rx, ry, rd, rd); 
    
     
       //ellipse rollover
        
        if (d < ed/2) {
        fill(255);
        fill(255,0,0);
      } else {
        fill(255);
      }
        ellipse(ex, ey, ed, ed);
    
    }
    
    
    

    code

    tweaks (0)

    about this sketch

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

    license

    advertisement

    griffin

    workshop_3

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

    epar
    6 Jul 2012
    The workshop assignment required you to "Design a reaction when the mouse moves over a rectangle and design a different action when the mouse moves over a circle." Your code now had the same action for both the ellipse and the rectangle (change the fill color), please update your code to fulfill the workshop requirements.
    You need to login/register to comment.