//// 

String title=" Lisa  -horizon,water, fish";
String author="Lisa Sparacino; project #2";
String help=  "KEYS:\n  q: quit\n  r: Move sun\n +/-: move sun fast/slow\n  s:  stop sun\n  g:  go sun";


boolean day=true;

float horizon;
float left=50, right, top, bottom;
float skyR=100, skyG=200, skyB=255;
float sunR=255, sunG=255, sunB=0;
float sunX=50, sunY=50, sunDX=2, sunDY=0;
float f1X, f1Y, f1DX;
float t1X, t1Y, t1DX;
float boatX, boatY, boatDX;


////SETUP
void setup() {
  size(800, 600);
  left=  width-500;
  right=  width-50;
  top=  100;
  bottom=  height-50;
  horizon=  height/3;
  rectMode(CENTER);

  reset1();
  resetBoat();
}
void reset1() { 
 // stroke(2);
  f1X=left-25; 
  f1Y=random(top+60, bottom-20); 
  f1DX=random( 1, 10 );
}
void resetBoat() { 
  boatX=horizon; 
  boatY=horizon;
  
}

void draw() {
  scene();
  if (keyPressed && key == '?') {
    fill(0);
    textSize(24);
    text( help, 500, horizon+150 );
    textSize(12);
    return;
  }
  sun();
  button();
  boat();
  action();
  msgs();
 
 
  // Draw fish

  float ftX;  //fishTail
  //   Orange fish
  ftX=f1X-25;
  fill( 255, 165, 0 );
  ellipse( f1X, f1Y, 50, 16 );  // fish body
  triangle( ftX, f1Y, ftX-20, f1Y-12, ftX-20, f1Y+12 );  //tail
}

void scene() {
  // Sky
  //// Day or night

  background( skyR, skyG, skyB );
  fill( 59, 152, 166 );  // sea
  rectMode(CORNER);
  rect( 0, horizon, width, height );
  fill (114, 87, 87); //mud
  rect( 0, 570, 800, horizon/6 );

  rectMode(CENTER);
}  

//// Move & show sun.
void sun() {
  // Sun.
  sunX=  sunX+sunDX;
  if (sunX>width ) {
    day=  ! day;
    sunX=50;
    if (day) { 
      skyR=100; 
      skyG=200; 
      skyB=255;
    }   // Day sky
    else { 
      skyR=random(47, 112); 
      skyG=random(79, 128); 
      skyB=random(79, 144);
    }   // Nite sky
    if (day) { 
      sunR=255; 
      sunG=255; 
      sunB=0;
    }   // Day sun
    else {  
      noStroke (); 
      sunR=skyR; 
      sunG=skyG; 
      sunB=skyB;
    }   // (No) Nite moon
  } 
  fill( sunR, sunG, sunB );
  ellipse( sunX, sunY, 50, 50 );
}
//// move & show red boat
void boat() {
  boatX=100; 
  boatY=200;
  fill (225, 0, 0);
  rect (boatX-40, boatY-20, 100, 40);
}
//// ACTION:  move fish and boat
void action() {
  // fish moves across.
  f1X += f1DX;
  if (f1X>right) reset1();
  //boat moves across
  boatX += boatDX;
  if (boatX>right) resetBoat ();
}
//// MSGS:  title, author;
void msgs() {
  fill(0);
  textSize(24);
  text( title, width/4, 30 );
  
  textSize(12);
  text( author, 40, height-20 );}

//// EVENTS ////
void keyPressed() {
  if (key == 'q') exit();
  if (key == 'r') {
    sunY=  random( 20, horizon-30 );    // Random height
    sunX=50;
  }
  if (key == '+') { 
    sunDX=  sunDX * 2;
  }       // Faster
  if (key == '-') { 
    sunDX=  sunDX / 2;
  }      // Slower
  if (key == 's') { 
    sunDX=  0;
  }      // Stop
  if (key == 'g') { 
    sunDX=  2;
  }      // Go
}


////
void button() {
}

