> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.Yz2dqPNpt5w/rev.2156
 * 
 * authors: 
 *   Andrew
 *   Andrew Meier

 * 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 carX = 100;
int carY = 230;
int busX = 200;
int busY = 190;
int logX = 100;
int logY = 100;
int frogX = 150;
int frogY = 275;


void setup() {  // this is run once.   
    
    // set the background color
    background(255);
    
    // canvas size (Variable aren't evaluated. Integers only, please.)
    size(300, 300); 
      
    // smooth edges
    smooth();
    
    // limit the number of frames per second
    frameRate(30);
    
    // set the width of the line. 
    strokeWeight(12);
} 

void draw() {  // this is run repeatedly.  
    //background(255);
    draw_background();
    draw_log(logX, logY);
    draw_car(carX, carY);
    draw_bus(busX, busY);
    draw_frog(frogX, frogY);
    busX += 3;
    carX -= 5;
    logX += 4
    if (carX < 0)
        carX = width;
    if (busX > width)
        busX = 0;
    if (logX > width)
        logX = 0;
}

void draw_frog(x, y) {
    fill(34,195,16);
    frog_body_width = 12;
    frog_body_height = 15;
    frog_leg_width = 3;
    frog_leg_horiz_length = 6;
    frog_leg_vert_length = 8;
    //frog body
    rect(x,y,frog_body_width,frog_body_height);
    
    //top left leg
    rect(x-frog_leg_horiz_length, y - 5, frog_leg_width, frog_leg_vert_length);
    rect(x - frog_leg_horiz_length, y, frog_leg_horiz_length, frog_leg_width);

    //top right leg
    rect(x + frog_body_width, y, frog_leg_horiz_length, frog_leg_width);
    rect(x + frog_body_width + 3, y - 5, frog_leg_width, frog_leg_vert_length);
    
    //bottom left leg
    rect(x-frog_leg_horiz_length, y+frog_body_height-3, frog_leg_horiz_length, frog_leg_width);
    rect(x-frog_leg_horiz_length, y+frog_body_height-3, frog_leg_width, frog_leg_vert_length);
    
    //bottom right leg
    rect(x + frog_body_width, y+frog_body_height-3, frog_leg_horiz_length, frog_leg_width);
    rect(x + frog_body_width + frog_leg_width, y+frog_body_height - 3, frog_leg_width, frog_leg_vert_length);
    
    //head
    rect(x + (frog_body_width/2) - 3, y - 6, 6, 6);
    //eyes
    fill(255,0,0);
    rect(x + (frog_body_width/2) - 3, y - 5, 2,2); 
    rect(x + (frog_body_width/2) + 1, y - 5, 2,2);
    
    
    //spots
    fill(192, 223, 36);
    rect(x + 3, y + 3, 3, 3);
    rect(x + 6, y + 8, 3, 3);
    
    
}

void draw_car(x, y) {
    fill(0);
    car_width = 40;
    car_height = 10;
    car_top_width = 15;
    car_top_height = 5;
    rect(x, y, car_width, car_height);
    rect(x + ((car_width / 2) - (car_top_width / 2)), y - car_top_height, car_top_width, car_top_height);   
    ellipse(x,y + car_height,10,10);
    ellipse(x + car_width, y + car_height, 10, 10);
    
}

void draw_bus(x, y){
    
    fill(255,0,0);
    bus_width = 80;
    bus_height = 20;
    rect(x, y, bus_width, bus_height, 4);
    fill(0);
    ellipse(x+5,y+bus_height, 10,10);
    ellipse(x+bus_width-5,y+bus_height, 10,10);
    rect(x+2,y+2,8,8,2); 
    rect(x+12, y+2, 8,8,2);
    rect(x+22, y+2, 8,8,2);
    rect(x+32, y+2, 8,8,2);
    rect(x+42, y+2, 8,8,2);
    rect(x+52, y+2, 8,8,2);
    rect(x+62, y+2, 8,8,2);
}

void draw_log(x, y) {
    fill(77, 60, 6);
    log_width = 80;
    log_height = 20;
    rect(x, y, log_width, log_height, 6);
    
    
}

void draw_background() {
    noStroke()
    background(5,21,142);
    
    fill(0);
    rect(0,height - 25, width, 25);
    fill(44, 40, 46);
    rect(0, height - 150, width, 100);
    fill(114, 6, 141);
    rect(0, height - 50, width, 25);
    rect(0, height - 175, width, 25);
    fill(67,233,17);
    rect(0,0,width, 5);
    rect(0,0,10,25);
    rect(30,0,45,25);
    rect(95, 0, 45, 25);
    rect(160, 0, 45, 25);
    rect(225, 0, 45, 25);
    rect(290, 0, 10, 25);
}

void keyPressed() {
    moveAmount = 10;
    if (key == CODED) {
        if (keyCode == UP) {
            frogY -= moveAmount;
        } else if (keyCode == DOWN) {
            frogY += moveAmount;
        } else if (keyCode == LEFT) {
            frogX -= moveAmount;
        } else if (keyCode == RIGHT) {
            frogX += moveAmount;
        }
    }
}