//Marcelo Eisenberg Project1

float horizon;
float manX,manY;
float catX,catY;

//setup
void setup() 
{
  size(800,600);
  horizon = height/3;
  reset();
}

void reset()
{
  manX = random(50,width/2);
  manY = random(horizon,height-20);
  
  catX = random(50,width/2);
  catY = random(horizon,height-20);
  
}

void draw()
{
  scene();
  action();
  credits();
}

void scene()
{
  //grass
  background(34,139,34);
  
  //sky
  fill(255,215,0);
  noStroke();
  rect(0,0,width,horizon);
  
  //cloud
  fill(255,255,255);
  circle(600,50,70);
  circle(630,45,70);
  circle(585,60,70);
  circle(630,65,70);
  circle(650,60,70);
  
  //sign
  fill(71,40,11);
  rect(200,horizon-20,10,60);
  rect(155,horizon-100,100,80);
 
  tree();
}

void tree() {
  //tree
  fill(181,101,29);
  rect(500,horizon-40,60,150);
  fill(19,180,19);
  circle(500,150,90);
  circle(550,140,90);
  circle(520,130,90);
  circle(550,150,90);
}

void action() {
  //man

  fill(255,255,255);
  stroke(0,0,0);
  circle(manX,manY,50); //head
  line(manX,manY+25,manX,manY+75); //body
  line(manX,manY+75,manX-20,manY+125); //legs
  line(manX,manY+75,manX+20,manY+125);
  line(manX,manY+60,manX-20,manY+40); //arms
  line(manX,manY+60,manX+20,manY+40);

  cat();
}

void cat() {
  //cat
  fill(211,211,211);
  rect(catX,catY+24,-5,10); //legs
  rect(catX-45,catY+24,-5,10);
  rect(catX,catY,-50,25); //body
  //
  /*
  if (catX<manX) {
    circle(catX,catY,20); //head
    rect(catX-50,catY,-15,5); //tail
  } else {
    circle(catX-50,catY,20); //head
    rect(catX,catY,-15,5); //tail
  }
  */
  float headX=catX-50, tailX=catX+15;
  if (catX<manX) {
    headX=  catX;
    tailX=  catX-50;
  }
  circle( headX, catY ,20); //head
  rect( tailX, catY, -15,5); //tail
  
}

void credits()
{
  //signature
  fill(0,150,225);
  noStroke();
  textSize(16);
  text("Marcelo E.",10,20);
  
  //title
  fill(0,150,225);
  textSize(16);
  text("Project 1",10,40);
  
  //sign
  fill(255,255,255);
  textSize(20);
  text("sup",187,140);
}


// EVENTS //
void keyPressed() {
  if (key  == 'r') reset();
}