//very simple program of animating bat and witch

//variables to move the bat
int tx, ty;
//variables to move the witch
int Wtx, Wty;

//a function to set up the general drawing parameters
void setup() {
  size(400, 400);
  background(#1B48E3);
  smooth();
  tx = 400;
  ty = 100;
  Wtx = 0;
  Wty = 380;
  frameRate(20);
}

//press any key to reset the bat and witch
void keyPressed() {
  tx = 400;
  ty = 100;
  
  Wtx = 0;
  Wty = 380;
}

//function to draw the bat
void drawBat() {
  fill(#313632);
  stroke(0);
  beginShape();
  vertex(-10, 20);
  vertex(10, 10);
  vertex(20, 20);
  vertex(22, 5);
  vertex(24, 12);
  vertex(26, 5);
  vertex(28, 12);
  vertex(32, 12);
  vertex(26, 20);
  vertex(36, 12);
  vertex(56, 23);
  vertex(51, 28);
  vertex(44, 25);
  vertex(37, 30);
  vertex(30, 25);
  vertex(23, 32);
  vertex(17, 25);
  vertex(10, 28);
  vertex(5, 25);
  vertex(0, 28);
  endShape(CLOSE);
}
  
//function to draw the witch
void drawWitch() {
  
  fill(0);
  //the body
  ellipse(0, 0, 10, 20);
  ellipse(0, -15, 10, 10);
  //legs
  ellipse(9, 7, 11, 4);
  ellipse(12, 12, 4, 11);
  
  //the hat
  triangle(-10, -20, 0, -35, 10, -20);
  
  //the broom
  strokeWeight(6);
  line(25, -20, -10, 20);
  quad(-18, 30, -11, 18, -7, 21, -12, 34);
  
  strokeWeight(1);
  
}


//the draw function - which will loop
void draw() {
  
  int i;
  
  i = 0;
  background(#1B48E3);
  
  //the ground
  fill(#9B895B);
  noStroke();
  rect(0, 370, 400, 35);
  
  //the moon
  fill(#F0B00C);
  ellipse(37, 30, 50, 50);
  
  //draw the bat in an updated position using variables
    pushMatrix();
    translate(tx, ty);
    scale(1.5);
    drawBat();
    popMatrix();
 
   //draw the witch in an updated position using variables
    pushMatrix();
    translate(Wtx, Wty);
    scale(2.0);
    drawWitch();
    popMatrix();
  
  //update my bat variables - either randomly update y 
  tx = tx - 2;
  ty = ty + int(random(-5, 5));
  
  //update my witch variables
  Wtx = Wtx + 2;
  Wty = Wty -2;
  
}