Your browser does not support the canvas tag.

previous        Show / Hide Source        Download        next
//Fright_Night
//Dalton Walker

//Look around with your flash light but beware the scares
//Some spots cause scares to occur when clicked
//Try to find all of the scare spots
//Also there is a chill bug for you to hang out with



//Declaring variables needed for later
float x1 = 225;
float y = 125;
float x2 = 300;
float w = 50;
float h = 25;
float bugx = random(25, 375);
float bugy = random(325, 375);
float c1 = random(0,255);
float c2 = random(0,255);
float c3 = random(0,255);

//Setup
void setup() {
  size(400, 400);
  rectMode(CORNERS);
  frameRate(30);
}

//Main draw cycle filled with user defined functions to keep it looking clean
void draw() {
  background(#76696B);
  drawRoom();
  drawTable();
  drawLamp();
  drawBed();
  drawWindow();
  drawWindowFrame();
  drawDoor();
  drawBug();
  fill(0, 0, 0, 100);
  rect(0, 0, 400, 400);
  drawFlashLight();


//These conditional statements activate the scares upon pressing mouse in certain spots
  if (mousePressed) {
    if (mouseX > 150 && mouseX < 225 && mouseY < 87.5 && mouseY > 12.5) {
      drawPentagram();
    } else if (mouseX > 12.5 && mouseX < 62.5 && mouseY < 312.5 && mouseY > 150) {
      drawSpider();
    } else if (mouseX > 315.2 && mouseX < 350 && mouseY < 232.5 && mouseY > 175) {
      drawTable();
      drawFallenLamp();
    } else if (mouseX > 200 && mouseX < 325 && mouseY < 132.5 && mouseY > 112.5) {
      drawEyes();
    }
  }
}

//This is a separate mousePressed function to cause the lightning to just flash not linger
void mousePressed() {
  if (mouseX > 87.5 && mouseX < 150 && mouseY < 225 && mouseY > 112.5) {
    drawWindow();
    drawLightning();
    drawWindowFrame();
  }
}


//Function for drawing the spider
void drawSpider() {
  noStroke();
  fill(#505551);
  triangle(12.5, 150, 62.5, 162.5, 12.5, 162.5);
  triangle(12.5, 287.5, 62.5, 290, 12.5, 318.25);
  rect(12.5, 162, 62.5, 290);
  stroke(0);
  line(12.5, 200, 25, 225);
  line(50, 225, 62.5, 200);
  line(12.5, 237.5, 37.5, 250);
  line(12.5, 275, 37.5, 250);
  line(12.5, 312.5, 37.5, 250);
  line(37.5, 300, 37.5, 250);
  line(62.5, 275, 37.5, 250);
  line(63.5, 250, 37.5, 250);
  line(37.5, 200, 37.5, 156.25);
  fill(0);
  ellipse(37.5, 225, 25, 50);
  ellipse(37.5, 250, 12.5, 12.5);
  line(12.5, 150, 12.5, 312.5);
  line(12.5, 150, 62.5, 162.5);
  line(62.5, 162.5, 62.5, 287.5);
}

//Function for drawing the door
void drawDoor() {
  noStroke();
  fill(#711B21);
  triangle(12.5, 150, 62.5, 162.5, 12.5, 162.5);
  triangle(12.5, 287.5, 62.5, 290, 12.5, 318.25);
  rect(12.5, 162, 62.5, 290);
  fill(0);
  ellipse(50, 225, 12.5, 12.5);
}

//Function for drawing the window
void drawWindow() {
  noStroke();
  fill(#055F19);
  rect(87.5, 187.5, 150, 213);
  triangle(87.5, 212.5, 150, 212.5, 87.5, 225);
  fill(#1C024B);
  rect(87.5, 187.5, 150, 125);
  triangle(87.5, 125, 150, 125, 87.5, 112.5);
  stroke(0);
  line(150, 125, 150, 212.5);
  line(87.5, 112.5, 87.5, 225);
  line(87.5, 112.5, 150, 125);
  line(150, 212.5, 87.5, 225);
}

//Function for drawing the window frame
void drawWindowFrame() {
  stroke(0);
  line(118.75, 118.75, 118.75, 218.75);
  line(87.5, 168.75, 150, 168.75);
}


//Function for drawing the bed
void drawBed() {
  noStroke();
  fill(#711B21);
  rect(150, 287.5, 225, 312.5);
  triangle(225, 287.5, 225, 312.5, 300, 225);
  triangle(300, 200, 300, 225, 225, 287.5);
  ellipse(262.5, 187.5, 75, 50);
  fill(#1231DB);
  triangle(225, 200, 225, 287.5, 150, 287.5);
  triangle(225, 200, 225, 287.5, 300, 200);
  fill(255);
  rect(237.5, 187.5, 262.5, 200);
  rect(262.5, 187.5, 287.5, 200);
}

//Function for drawing the table
void drawTable() {
  noStroke();
  fill(#711B21);
  rect(312.5, 212.5, 337.5, 237.5);
  triangle(312.5, 212.5, 337.5, 212.5, 325, 200);
  triangle(325, 200, 337.5, 212.5, 350, 200);
  triangle(350, 200, 350, 225, 337.5, 212.5);
  triangle(350, 225, 337.5, 212.5, 337.5, 237.5);
}

//Function for drawing the lamp on the table
void drawLamp() {
  fill(#8E0785);
  ellipse(331.25, 200, 10, 25);
  fill(#E7FF39);
  rect(325, 175, 337.5, 187.5);
  stroke(0);
  line(331.25, 212.5, 318.25, 206.25);
}

//Function for drawing the pentagram
void drawPentagram() {
  stroke(0);
  fill(#FC001E, 100);
  ellipse(187.5, 50, 75, 75);
  line(175, 37.5, 200, 37.5);
  line(200, 37.5, 175, 62.5);
  line(175, 62.5, 187.5, 25);
  line(187.5, 25, 200, 62.5);
  line(200, 62.5, 175, 37.5);
}

//Function for drawing the lightning
void drawLightning() {
  fill(#FFF815);
  triangle(125, 118.25, 137.5, 118.25, 100, 137.5);
  triangle(95, 137.5, 105, 137.5, 137.5, 162.5);
  triangle(132.5, 162.5, 142.5, 162.5, 100, 187.5);
}

//Function for drawing the lamp fallen over onto the floor
void drawFallenLamp() {
  stroke(0);
  fill(#8E0785);
  ellipse(306.25, 262.5, 10, 25);
  fill(#E7FF39);
  rect(312.5, 275, 325, 287.5);
  line(306.25, 250, 312.5, 225);
  fill(#76696B);
  noStroke();
  rect(325, 175, 350, 200);
  fill(0, 0, 0, 100);
  rect(325, 175, 350, 200);
}

//Function to draw a flashlight beam that follows the mouse
void drawFlashLight() {
  noStroke();
  fill(#FAF449, 50);
  ellipse(mouseX, mouseY, 75, 75);
  ellipse(mouseX, mouseY, 50, 50);
  ellipse(mouseX, mouseY, 25, 25);
}

//Function for drawing room outlines
void drawRoom() {
  stroke(0);
  line(0, 75, 175, 87.5);
  line(350, 87.5, 375, 0);
  line(350, 225, 375, 400);
  line(175, 225, 0, 325);
  noFill();
  rect(175, 87.5, 350, 225);
}

//Function for drawing the eyes
//Loop was used to create spiral ringed look
void drawEyes() {
  float w = 50;
  float h = 25;
  while (w > 0) {
    fill(255);
    stroke(0);
    ellipse(x1, y, w, h);
    ellipse(x2, y, w, h);
    w = w - 5;
    h = h - 2.5;
  }
}

//Function for drawing the randomly located bug
void drawBug() {
  stroke(c1,c2,c3);
  ellipse(bugx, bugy, 6.25, 12.5);
  line(bugx, bugy, bugx - 12, bugy - 6);
  line(bugx, bugy, bugx + 12, bugy + 6);
  line(bugx, bugy, bugx + 12, bugy - 6);
  line(bugx, bugy, bugx - 12, bugy + 6);
}