Your browser does not support the canvas tag.

previous        Show / Hide Source        Download        next
/*
 Assignment 1
 Interactive Drawing
 Richard Scott Duff
 Sept 21th 2016
 
 
 A drawn windmill that does nothing with a bat or bird flying past it.  When you press a key the drawing turns from day to night.  When the mouse is pressed you draw a cloud at the mouse's position.
 
 
 */
void setup()
{
  //sets the size of the screen
  size(400, 400);

  // set the recangle to draw from the center to outwards instead of top left corner by deafult
  rectMode(CENTER);

  //set the background color to blue
  background(0, 100, 255);
}

void draw()
{
  //sets the frame rate to 60.
  frameRate(30);

  //sky
  //write code for colouring the sky here
  background(0, 100, 255);

  //Windmill
  stroke(1);

  //Stand
  fill(129, 75, 5);
  rect(200, 325, 100, 50);

  //Body
  fill(129, 75, 5);
  rect(200, 250, 120, 125);

  //Top Triangle
  fill(129, 75, 5);
  triangle(200, 100, 261, 188, 140, 188);

  //All Fan parts is what moves by tracking the mouse X & moseY

  //Top Fan Cloth
  fill(255);
  rect(190, 110, 30, 100);
  //Top Fan Arm
  fill(129, 75, 5);
  rect(200, 120, 5, 120);

  //Right Fan Cloth
  fill(255);
  rect(270, 170, 100, 30);
  //Right Fan Arm
  fill(129, 75, 5);
  rect(260, 180, 120, 5);

  //Bottom Fan Cloth
  fill(255);
  rect(210, 250, 30, 100);
  //Bottom Fan Arm
  fill(129, 75, 5);
  rect(200, 240, 5, 120);

  //Left Fan Cloth
  fill(255);
  rect(130, 190, 100, 30);
  //Left Fan Arm
  fill(129, 75, 5);
  rect(140, 180, 120, 5);


  //Centre Piece For Fan
  fill(0);
  ellipse(200, 175, 20, 20);



  //Left Hill
  noStroke();
  fill(22, 198, 0);
  ellipse(400, 400, 300, 300);

  //Middle Hill
  noStroke();
  ellipse(200, 400, 300, 150);

  //Right Hill
  noStroke();
  ellipse(0, 400, 300, 200);

  // bird or bat thingy
  noStroke();

  frameRate(10);
  /*
  This portion of code is part of the bat thats above the windmill.
  The mouseX means it's locked to follow the mouse's x position on screen.
  the frameCount function does exactly what it says it counts the amount of frames pasted since running the program
  and the sin function mized with the framecount function is how the plusatating effect has been created.
  I also inverted the mouseX to y coord and mouseY to x coord to give the bat an ellusive feeling
  */

  
    fill(0);
  rect(sin(mouseY * 10) + mouseY, mouseX+ 40, 10, 10);

  //bat left wing
  fill(0);
  rect(sin(mouseY * 10) + mouseY - 5, mouseX+35, 10, 10);
  rect(sin(mouseY * 100) + mouseY - 10, sin(frameCount * 10) + mouseX+30, 10, 10);

  //bat right wing
  fill(0);
  rect(sin(mouseY * 10) + mouseY + 5, mouseX +35, 10, 10);
  rect(sin(mouseY * 10) + mouseY + 10, sin(frameCount * 10)+ mouseX+30, 10, 10);

  //bat eyes
  fill(14, 255, 0);
  rect(sin(frameCount * 10) + mouseY - 2, mouseX+36, 2, 2);
  rect(sin(frameCount * 10) + mouseY + 2, mouseX+36, 2, 2);
}

void keyPressed()
{
  /* When a key is pressed on the keyboard it will slow down the framerate to 5 and redraws the whole screen only with a dark background
  instead of a blue one to emitate night time.*/
  frameRate(1);
  background(0);

  //Windmill
  stroke(1);

  //Stand
  fill(72, 40, 1);
  rect(200, 325, 100, 50);

  //Body
  fill(72, 40, 1);
  rect(200, 250, 120, 125);

  //Top Triangle
  fill(72, 40, 1);
  triangle(200, 100, 261, 188, 140, 188);

  //All Fan parts is what moves by tracking the mouse X & moseY

  //Top Fan Cloth
  fill(170, 170, 170);
  rect(190, 110, 30, 100);

  //Top Fan Arm
  fill(72, 40, 1);
  rect(200, 120, 5, 120);

  //Right Fan Cloth
  fill(170, 170, 170);
  rect(270, 170, 100, 30);
  //Right Fan Arm
  fill(72, 40, 1);
  rect(260, 180, 120, 5);

  //Bottom Fan Cloth
  fill(170, 170, 170);
  rect(210, 250, 30, 100);
  //Bottom Fan Arm
  fill(72, 40, 1);
  rect(200, 240, 5, 120);

  //Left Fan Cloth
  fill(170, 170, 170);
  rect(130, 190, 100, 30);
  //Left Fan Arm
  fill(72, 40, 1);
  rect(140, 180, 120, 5);


  //Centre Piece For Fan
  fill(0);
  ellipse(200, 175, 20, 20);

  //Left Hill
  noStroke();
  fill(10, 77, 0);
  ellipse(400, 400, 300, 300);

  //Middle Hill
  noStroke();
  ellipse(200, 400, 300, 150);

  //Right Hill
  noStroke();
  ellipse(0, 400, 300, 200);

  //sin(frameCount * 10) + mouseX + 2
  //bat eyes
  fill(255, 23, 23);
  rect(sin(frameCount * 5000) + 98, 36, 2, 2, 191);
  rect(sin(frameCount * 5000) + 102, 36, 2, 2, 191);

  //bat eyes
  fill(255, 23, 23);
  rect(38, 70, 2, 2, 191);
  rect(42, 70, 2, 2, 191);

  //bat eyes
  fill(255, 23, 23);
  rect(244, 67, 2, 2, 191);
  rect(248, 67, 2, 2, 191);

  //bat eyes
  fill(255, 23, 23);
  rect(320, 110, 2, 2, 191);
  rect(324, 110, 2, 2, 191);

  //bat eyes
  fill(255, 23, 23);
  rect(90, 98, 2, 2, 191);
  rect(94, 98, 2, 2, 191);

  //bat eyes
  fill(255, 23, 23);
  rect(350, 15, 2, 2, 191);
  rect(354, 15, 2, 2, 191);
}// end of the keypressed function

void mousePressed()
{
  // This will draw a cloud at the mouse's position on screen. but it will only last for 5 frames.
  frameRate(5);
  fill(255);
  noStroke();
  //base of the cloud
  ellipse(mouseX, mouseY - 1, 30, 30);
  ellipse(mouseX - 15, mouseY, 25, 25);
  ellipse(mouseX + 15, mouseY, 25, 25);

  // slightly more complex part of the cloud
  ellipse(mouseX, mouseY - 15, 25, 25);
  ellipse(mouseX+7, mouseY - 7, 25, 25);
  ellipse(mouseX-7, mouseY-7, 25, 25);
  ellipse(mouseX, mouseY, 25, 25);

  println("MAGIC MISSLE");
}// end of the mousePressed function