Your browser does not support the canvas tag.

previous        Show / Hide Source        Download        next
// First Coding Assignment
// Title: Under The Bed
// How to Interact: Click the mouse to go from day time to night an dsee the creepy monsters under your bed
// You can also move the sun by moving the mouse up and down
// By: Dylan M.

void setup() {
  size(400, 400);
  // I saw that in the examples other people used custom cursors so I wanted to try it out
  noCursor();
}

void mousePressed() { 
  //Frame rate brought down so you can see what actually happens when it is presed
  frameRate(2);

  // Back wall
  rectMode(CORNER);
  stroke(55, 30, 25);
  fill(60, 55, 50);
  rect(140, 60, 200, 220);

  //Left wall
  quad(0, 0, 140, 60, 140, 280, 0, 400);

  //Right wall
  quad(400, 0, 340, 60, 340, 280, 400, 400);

  //Ceiling
  stroke(150);
  fill(150);
  quad(0, 0, 400, 0, 340, 60, 140, 60);

  //Floor
  stroke(50);
  fill(50);
  quad(0, 400, 140, 280, 340, 280, 500, 500);

  //Left bed leg
  stroke(0);
  fill(30);
  rect(150, 360, 20, 30);
  triangle(170, 360, 170, 390, 180, 360);

  // Right bed leg
  rect(310, 360, 20, 30);
  triangle(310, 360, 300, 360, 310, 390);

  //Bed rest
  stroke(25, 15, 10);
  fill(25, 15, 10);
  rect(180, 170, 120, 70, 3);

  //Night stand
  quad(130, 240, 180, 240, 180, 260, 110, 260);
  rect(110, 260, 70, 20, 3);
  rect(110, 280, 70, 30, 3);
  fill(120);
  ellipse(140, 270, 10, 10);

  //top of bed
  stroke(90, 20, 10);
  fill(90, 20, 10);
  quad(180, 240, 150, 320, 330, 320, 300, 240);

  //Front of bed
  rect(150, 320, 180, 40, 4);

  //White bed sheet
  stroke(170);
  strokeWeight(3);
  fill(170);
  quad(180, 240, 173, 260, 307, 260, 300, 240);

  //Window
  strokeWeight(1);
  stroke(0, 14, 40);
  fill(0, 14, 40);
  quad(20, 80, 20, 240, 130, 200, 130, 100);


  //Window sill
  stroke(100);
  fill(100);
  quad(20, 240, 130, 200, 130, 213, 20, 260);

  //Moon
  stroke(200);
  fill(200);
  ellipse(100, 130+mouseY/8, 40, 40);
  stroke(0, 14, 40);
  // To make the Moon a crescent I took advantage of Processing's refresh system and put a darker ellipse over the Moon
  fill(0, 14, 40);
  ellipse(88, 130+mouseY/8, 40, 40);

  //Stars
  stroke(255);
  strokeWeight(5);
  fill(255);
  point(30, 160);
  point(30, 215);
  point(40, 110);
  point(50, 180);
  point(50, 130);
  point(60, 210);
  point(70, 150);
  point(80, 120);
  point(80, 185);
  point(120, 190);

  // Door
  strokeWeight(1);
  stroke(120);
  fill(120);
  quad(340, 150, 340, 280, 380, 333, 380, 140);

  // Doorknob
  stroke(20); 
  fill(20);
  ellipse(370, 230, 10, 10);

  //Outlet
  stroke(140);
  fill(140);
  rect(320, 260, 10, 15);

  //Plug
  stroke(30);
  fill(30);
  ellipse(325.6, 266, 3.5, 3.5);
  ellipse(325.6, 272, 3.5, 3.5);

  // Light 
  stroke(40);
  fill(40);
  triangle(200, 20, 280, 20, 240, 60);

  stroke(100);
  fill(100);
  ellipse(240, 55, 60, 60);

  // Eyes 1
  stroke(120, 0, 0);
  fill(255, 0, 0);
  ellipse(190, 370, 13, 5);
  ellipse(203, 370, 13, 5);
  fill(0);
  ellipse(190, 370, 3, 3);
  ellipse(203, 370, 3, 3);

  //Darker eyes
  stroke(120, 0, 0);
  fill(155, 0, 0);
  ellipse(225, 365, 13, 5);
  ellipse(240, 365, 13, 5);
  fill(255);
  ellipse(225, 365, 3, 3);
  ellipse(240, 365, 3, 3);

  //Big white eyes with red pupils
  stroke(240, 0, 0);
  fill(250);
  ellipse(240, 380, 20, 10);
  ellipse(270, 380, 20, 10);
  fill(0);
  ellipse(240, 380, 3, 7);
  ellipse(270, 380, 3, 7);

  //Pure red eyes (no pupils)
  stroke(120, 0, 0);
  fill(255, 0, 0);
  ellipse(285, 367, 5, 10);
  ellipse(295, 367, 5, 10);
  fill(255);
  ellipse(225, 365, 3, 3);
  ellipse(240, 365, 3, 3);

  //Custom mouse
  stroke(0);
  fill(255);
  triangle(mouseX-5, mouseY-7, mouseX+5, mouseY+3, mouseX-4, mouseY+6);
}

void draw() {
  frameRate(60);

  // Back wall
  rectMode(CORNER);
  stroke(200, 170, 115);
  fill(255, 225, 170);
  rect(140, 60, 200, 220);

  //Left wall
  quad(0, 0, 140, 60, 140, 280, 0, 400);

  //Right wall
  quad(400, 0, 340, 60, 340, 280, 400, 360);

  //Ceiling
  stroke(230);
  fill(230);
  quad(0, 0, 400, 0, 340, 60, 140, 60);

  //Floor
  stroke(100, 45, 25);
  fill(100, 45, 25);
  quad(0, 400, 140, 280, 340, 280, 500, 500);

  //Left bed leg
  stroke(60);
  fill(80);
  rect(150, 360, 20, 30);
  triangle(170, 360, 170, 390, 180, 360);

  // right bed leg
  rect(310, 360, 20, 30);
  triangle(310, 360, 300, 360, 310, 390);

  //Bed rest
  stroke(75, 50, 40);
  fill(95, 65, 50);
  rect(180, 170, 120, 70, 3);

  //Night stand
  quad(130, 240, 180, 240, 180, 260, 110, 260);
  rect(110, 260, 70, 20, 3);
  rect(110, 280, 70, 30, 3);
  fill(180);
  ellipse(140, 270, 10, 10);

  //Top of bed
  stroke(185, 40, 45);
  fill(185, 40, 45);
  quad(180, 240, 150, 320, 330, 320, 300, 240);

  //Front of bed
  rect(150, 320, 180, 40, 4);

  //White bed sheet
  stroke(250);
  strokeWeight(3);
  fill(250);
  quad(180, 240, 173, 260, 307, 260, 300, 240);

  //Window
  strokeWeight(1);
  stroke(173, 213, 247);
  fill(173, 213, 247);
  quad(20, 80, 20, 240, 130, 200, 130, 100);

  //Window sill
  stroke(240);
  fill(240);
  quad(20, 240, 130, 200, 130, 213, 20, 260);

  //Sun
  stroke(240, 205, 0);
  fill(240, 205, 50);
  ellipse(50, 110+mouseY/4.5, 40, 40);

  // Door
  stroke(240);
  fill(240);
  quad(340, 150, 340, 280, 380, 333, 380, 140);

  // Doorknob
  stroke(100); 
  fill(100);
  ellipse(370, 230, 10, 10);

  //Outlet
  stroke(250);
  fill(250);
  rect(320, 260, 10, 15);

  //Plug
  stroke(150);
  fill(150);
  ellipse(325.6, 266, 3.5, 3.5);
  ellipse(325.6, 272, 3.5, 3.5);

  // Light 
  stroke(150);
  fill(150);
  triangle(200, 20, 280, 20, 240, 60);

  stroke(255);
  fill(255);
  ellipse(240, 55, 60, 60);


  //Custom mouse
  fill(0);
  triangle(mouseX-5, mouseY-7, mouseX+5, mouseY+3, mouseX-4, mouseY+6);
}