> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.9Mq8ReBTJj8/rev.2331
 * 
 * authors: 
 *   Erin Kennedy
 *   Sean Anderson

 * license (unless otherwise specified): 
 *   creative commons attribution-share alike 3.0 license.
 *   https://creativecommons.org/licenses/by-sa/3.0/ 
 */ 



// Pressing Control-R will render this sketch.

int t = 0;
int xPos = width/2;
int yPos = height/2;
int mood = 0;

// Set drag switch to false
boolean dragging=false;

// If use drags mouse...
void mouseDragged(){
  
  // Set drag switch to true
  dragging=true;
}
  
// If user releases mouse...
void mouseReleased(){
  
  // ..user is no-longer dragging
  dragging=false;
}

void setup() {  // this is run once.   
    
    // set the background color
    background(255);
    
    // specify canvas size
    size(500, 500); 
      
    // smooth edges
    smooth();
    
    // limit the number of frames per second
    frameRate(30);
    
    // set the width of the line. 
    strokeWeight(12);
    
} 

void robo (x, y, int expression) {
    
    if(!dragging) {
        r = random(100);
        g = random(100);
        b = random(100);
    }
    stroke(r, g, b, 255);
    fill(r, g, b, 255);
    
    rect(x, y, 100, 100);
    
    line(x + 50, y, x + 50, y - 30);
    ellipse(x + 50, y - 30, 10, 10);
    
    noFill();
    
    stroke(r+75, g+75, b+75, 255);
    
    line(x + 20, y + 15, x + 20, y + 35);
    line(x + 20, y + 35, x + 40, y + 35);
    
    line(x + 70, y + 15, x + 70, y + 35);
    line(x + 70, y + 35, x + 90, y + 35);
    
    centerx = x + 50;
    centery = y + 50;
    
    // Nose
    arc(centerx, centery, 8, 80, PI, 2*PI);
    
    if(expression == 0) { // Happe
        arc(centerx, centery, 80, 80, 2.25*PI, 2.75*PI);
    } else if(expression == 1) { // Sad
        arc(centerx, centery+50, 40, 40, 1.10*PI, 1.90*PI);
    } else if(expression == 2) { // Open mouth
        noFill();
        ellipse(centerx, centery+30, 60, 40);
        
        stroke(r, g, b, 255);
        fill(r, g, b, 255);
        ellipse(centerx-15, centery+30, 40, 20);
    
        //arc(centerx, centery+30, 40, 40, 2.45*PI, 2.85*PI);
        //arc(centerx, centery+40, 40, 40, 1.10*PI, 1.90*PI);
    } else if(expression == 3) { // Chibi
        arc(centerx, centery, 40, 40, 2.25*PI, 2.75*PI);    
    }
    
}

void bubble(x, y) {
    fill(255, 255, 255, 255);
    stroke(255, 255, 255, 255);
    strokeWeight(2);
    ellipse(x - 50, y - 20, 80, 40);
    
    arc(x - 15, y - 10, 20, 1, .5*PI, -PI);
    
    stroke(0, 0, 0, 255);
    fill(0, 0, 0, 255);
    arc(x - 5, y - 10, 10, 10, .5*PI, -PI);
    bubbleContents(x - 50, y - 20);
}

void bubbleContents(x, y) {
    fill(255, 0, 0, 255);
    noStroke();
    
    if(mood == 0 || mood == 2) { // Heart
    
    triangle(x, y + 10, x - 5, y, x + 5, y);
    ellipse(x - 2, y - 1, 6, 8);
    ellipse(x + 2, y - 1, 6, 8);
    
    } else if(mood == 1) { // Zelda
        fill(200, 200, 50, 255);
        triangle(x, y-15, x+15, y+15, x-15, y+15);
        fill(255, 255, 255, 255);
        triangle(x+6, y, x-6, y, x, y+15);
    }
    
    
}

void draw() {  // this is run repeatedly.  

    // set the color
    t++;    
    mood = 0;
    
    // draw the line
    //line(i, 0, random(0, width), height);
    
    if(dragging) {
        xPos = mouseX-(100/2);
        yPos = mouseY-(100/2);
        expression = 0;
        t = 0;
    } else if (t < 600) {
        expression = 2;
        bubble(xPos, yPos);
    } else if (t < 1000) {
        expression = 1;
    } else {
        mood = 1;
        expression = 2;
        bubble(xPos, yPos);
    }
    strokeWeight(12);
    
    robo(xPos, yPos, expression);
    
    
    fill(0, 0, 0, 100);
    noStroke();
    rect(0, 0, width, height);
    
}