Your browser does not support the canvas tag.

previous        Show / Hide Source        Download        next
/*

  Interative Drawing - The Spoopy (Not so) Forest
  By Robert Orange
  
*/

void setup()
{
  size(600,400);
  rectMode(CORNERS);
  ellipseMode(CENTER);
  noStroke();
  //Remove cursor.
  noCursor(); 
  frameRate(25);
}

void draw()
{
  rectMode(CORNERS);
  //Redraw the background.
  background(0); 
//NIGHTTIME BACKGROUND ----------
  //Replace the background with a blue gradient background to simulate night time.
  fill(50,50,100);
  rect(0,0,600,75);
  fill(30,30,90);
  rect(0,75,600,225);
  fill(10,10,70);
  rect(0,225,600,400);
  //Grass
  fill(10,45,20);
  rect(0,250,600,400);
  //Water
  fill(10,20,60);
  quad(-40-mouseX/6,250,20-mouseX/6,250,40-mouseX/10,400,-80-mouseX/10,400);
//TREES LAYERS
  rectMode(CORNERS);
  fill(10,5,10);
  //LAYER 1
  //1st Tree
  rect(75-mouseX/4,250,120-mouseX/4,0);
  triangle(50-mouseX/4,250,75-mouseX/4,210,75-mouseX/4,250);
  triangle(120-mouseX/4,250,120-mouseX/4,210,145-mouseX/4,250);
  //2nd Tree
  rect(145-mouseX/4,250,195-mouseX/4,0);
  triangle(120-mouseX/4,250,145-mouseX/4,230,145-mouseX/4,250);
  triangle(195-mouseX/4,250,195-mouseX/4,230,215-mouseX/4,250);
  quad(195-mouseX/4,30,195-mouseX/4,10,215-mouseX/4,0,230-mouseX/4,0);
  //3rd Tree
  rect(250-mouseX/4,250,270-mouseX/4,0);
  triangle(225-mouseX/4,250,250-mouseX/4,210,250-mouseX/4,250);
  triangle(270-mouseX/4,250,270-mouseX/4,210,295-mouseX/4,250);
  //4th Tree
  rect(320-mouseX/4,250,345-mouseX/4,0);
  triangle(295-mouseX/4,250,320-mouseX/4,210,320-mouseX/4,250);
  triangle(345-mouseX/4,250,345-mouseX/4,210,365-mouseX/4,250);
  //4th Tree
  rect(375-mouseX/4,250,430-mouseX/4,0);
  triangle(350-mouseX/4,250,375-mouseX/4,210,375-mouseX/4,250);
  triangle(430-mouseX/4,250,430-mouseX/4,210,455-mouseX/4,250);
  //LAYER 2
  /*Draw a hovering ghost Behind the 2nd layer of trees.
  Ghost moves when the mouse moves*/
  fill(10,75);
  //Draw ghost body
  ellipse(width/2+mouseX-mouseY,170+5*sin(frameCount/5),100,150);
  ellipse(width/2+mouseX-mouseY,170+5*sin(frameCount/5.5),110,160);
  fill(100,0,0,50);
  //Draw Ghost eyes
  ellipse(-20+width/2+mouseX-mouseY,130+5*sin(frameCount/5.5),20,20);
  ellipse(-20+width/2+mouseX-mouseY,130+5*sin(frameCount/5.5),25,25);
  ellipse(20+width/2+mouseX-mouseY,130+5*sin(frameCount/5.5),20,20);
  ellipse(20+width/2+mouseX-mouseY,130+5*sin(frameCount/5.5),25,25);
  //Draw Ghost eye trails
  ellipse(-20+width/2+pmouseX-pmouseY,130+5*sin(frameCount/5.5),20,20);
  ellipse(20+width/2+pmouseX-pmouseY,130+5*sin(frameCount/5.5),20,20);
  //1st Tree
  fill(30,25,10);
  rect(40-mouseX/6,270,110-mouseX/6,0);
  triangle(25-mouseX/6,270,50-mouseX/6,225,50-mouseX/6,270);
  triangle(100-mouseX/6,270,100-mouseX/6,225,125-mouseX/6,270);
  //2nd Tree
  rect(220-mouseX/6,270,270-mouseX/6,0);
  triangle(195-mouseX/6,270,220-mouseX/6,195,220-mouseX/6,270);
  triangle(270-mouseX/6,270,270-mouseX/6,195,295-mouseX/6,270);
  quad(220-mouseX/6,70,220-mouseX/6,25,200-mouseX/6,0,180-mouseX/6,0);
  //3rd Tree
  rect(290-mouseX/6,270,360-mouseX/6,0);
  triangle(265-mouseX/6,270,290-mouseX/6,190,385-mouseX/6,270);
  triangle(360-mouseX/6,270,360-mouseX/6,190,385-mouseX/6,270);
  //LAYER 3
  /*Nothing here cause drawing all of the trees takes forever
  and would be nicer with loops. #Lazy4Lyf
  Wake me up inside*/
  //LAYER 4
  //Bush 1
  fill(32,80,27);
  ellipse(600-mouseX/11,400,200,150);
  ellipse(575-mouseX/11,340,100,50);
  ellipse(625-mouseX/11,340,100,50);
  fill(45,90,42);
  ellipse(550-mouseX/12,375,100,75);
  ellipse(625-mouseX/12,375,100,75);
  ellipse(600-mouseX/12,325,75,50);
  strokeWeight(5);
  stroke(95,85,45);
  line(600-mouseX/11,400,550-mouseX/13,350);
  stroke(103,92,48);
  line(595-mouseX/12,395,630-mouseX/13,350);
  noStroke();
  fill(60,98,56);
  ellipse(590-mouseX/13,350,100,75);

// LIGHT ------------------------  
  /*
  Draw the light that follows the cursor 
  only when the mouse is pressed.
  Slight drag on the light to simulate distance.
  Can't wake up*/ 
  if(mousePressed)
  {
    fill(255,255,70,5+mouseY/15);
    ellipse(pmouseX,pmouseY + 7, 200 + mouseY/4, 185 +mouseY/6);
    ellipse(pmouseX,pmouseY + 5, 165 + mouseY/4, 150 +mouseY/6);
    ellipse(pmouseX,pmouseY + 5, 155 + mouseY/4, 140 +mouseY/6);
    ellipse(pmouseX,pmouseY + 5, 150 + mouseY/4, 135 +mouseY/6);
    //Change fill to be whiter.
    fill(255,255,150,15+mouseY/15);
    ellipse(pmouseX,pmouseY, 70 + mouseY/6, 67 +mouseY/8);
    ellipse(pmouseX,pmouseY, 65 + mouseY/6, 62 +mouseY/8);
    ellipse(pmouseX,pmouseY, 55 + mouseY/6, 52 +mouseY/8);
    ellipse(pmouseX,pmouseY, 50 + mouseY/6, 47 +mouseY/8);
    //BRIGHTNESS INTENSIFIES.
    fill(255,255,220,30+mouseY/15);
    ellipse(pmouseX,pmouseY, 45 + mouseY/9, 42 +mouseY/10);
    ellipse(pmouseX,pmouseY, 35 + mouseY/9, 32 +mouseY/10);
    ellipse(pmouseX,pmouseY, 30 + mouseY/9, 27 +mouseY/10);
  }
//FLASHLIGHT ----------------
  rectMode(CENTER);
  translate(width/2,height+25);
  //Rotate the flashlight to follow the cursor's position.
  rotate(atan2( mouseY - height,mouseX - width/2));
  //Draw the Light emitted from flashlight.
  if(mousePressed)
  {
    fill(255,255,220,70);
    quad(50,25,50,-25,100,-50,100,50);
    quad(50,25,50,-25,105,-105/2,105,105/2);
    fill(255,255,150,30);
    triangle(50,0,50,25,130,130/2);
    triangle(50,0,50,-25,130,-130/2);
    quad(50,25,50,-25,125,-125/2,125,125/2);
    quad(50,25,50,-25,130,-130/2,130,130/2);
    fill(255,255,70,10);
    quad(50,25,50,-25,150,-75,150,75);
    quad(50,25,50,-25,155,-155/2,155,155/2);
  }
  fill(90);
  ellipse(60,0,60,60);
  fill(100);
  ellipse(50,0,50,60);
  rect(0,0,100,50);

}