////Dynamic sketch - modularized
////V.C. Castillo

float horizon;
float zoogX, zoogY;
float sunX = 10, sunY = 50;

////SETUP: size & models
void setup()  {
  size( 600, 400 );
  horizon = height/3;
}

void reset()  {
  sunX = 10;
  sunY = 50;
}

////NEXT FRAME: scene, action, show
void draw()  {
  background( 150, 200, 250 );  //sky
  scene();
  action();
  show();
}

////Scene: sky & grass
void scene() {
  fill( 100, 255, 100);
  rect( 0, horizon, width, height - horizon );  //grass
  fill( 255, 255, 0 );
  ellipse( sunX, sunY, 30, 30 );
  fill( 255, 0, 0 );
  rect( 200, horizon - 80, 100, 80 );  //house
  fill( 0 );
  rect( 220, horizon - 60, 30, 60 );  //door
}

////Action: Make Zoog follow the mouse
void action() {
  zoogX = mouseX;
  zoogY = mouseY;
  sunX += sunX + 1;  //Sun moves across sky
//L value = R value
}

////Show: draw Zoog
void show() {
  fill( 0, 0, 255 );
  rect( zoogX - 15, zoogY +10, 30, 40);  //body
  fill( 255, 0, 255);
  ellipse( zoogX, zoogY, 16, 20 );       //head
}

////Event Handlers
void mousePressed() {
  reset();
}

void keyPressed()  {
  if ( key == 'q' ) exit();
  if ( key == 'r' ) reset();
}