Your browser does not support the canvas tag.

previous        Show / Hide Source        Download        next
/*
Sad Day 
by JinXuan (Jacky) Xu

Move the mouse around and it rains... hard.
*/


//declare person and umbrella object
Person jacky;
Umbrella ella;

//declare arrays
Rain[]water = new Rain [3];

void setup() {
  //setup no mouse pointer, size, rectangle mode, no stroke
  noCursor();
  size (600, 600);
  rectMode(CORNER);
  noStroke();
  //initialize object
  jacky = new Person();
  ella = new Umbrella();
}


void draw() {
  //draw background
  background (85);
  // draw array 
  letItRain();
  //display array from rain class
  for (int i = 0; i<water.length; i++) {
    water[i].display();
    // i wanted for the rain to fall slowly ish but it didnt work out
    //water[i].movement();
  }
  // add functions and classes
  block();
  jacky.display();
  ella.display();
  cloud();
}

//array from the Rain class, follows the mouse, andd have slightly random color
void letItRain() {
  for (int i = 0; i<water.length; i++) {
    water[i] = new Rain (color(random(230, 255)), mouseX, mouseY);
  }
}

void cloud() {
  //draw cloud that follows the mouse
  noStroke();
  fill (#adadad);
  //middle
  ellipse(mouseX, mouseY, 73, 57);
  //side
  ellipse(mouseX-35, mouseY, 70, 55);
  ellipse(mouseX+35, mouseY, 70, 55);
  //outside
  ellipse(mouseX-80, mouseY, 58, 48);
  ellipse(mouseX+80, mouseY, 58, 48);
}

void block() {
  //block off rain behind the person
  fill (85);
  rect(200, 210, 260, 390);
}
//define person class
class Person {

  //state variables
  int bodyX ;
  int bodyY ;
  int bodyYC ;

  Person() {
    //constructor
    bodyX = width/2-90;
    bodyY = 510;
    bodyYC = 285;
  }


  void display() {
    //display person
    noStroke();
    fill (#5b6c8f);
    ellipse(width/2, 310, 100, 100);
    bezier(bodyX, bodyY, bodyX, bodyYC, bodyX+180, bodyYC, bodyX+180, bodyY);
  }
}
//define class rain
class Rain {

  //state position value, color, and position of rain
  PVector position; 
  color tear;
  float mousePositionX, mousePositionY;

  //constructs rain with temp color, and mouse positions
  Rain (color tempTear, float mousePisitionX, float mousePisitionY) { 
    //adds vector position values, random so it's spread out in an area like real rain
    position = new PVector(mousePisitionX+ random(-100, 100), mousePisitionY + random(0, 500));
    //restate color
    tear=tempTear;
  }

  // display rain at random length
  void display () {
    fill(tear);
    noStroke ();
    rect (position.x, position.y, 3, random(12, 20), 40);
  }
  // i wanted for the rain to fall slowly ish but it didnt work out
  //void movement()
  //{
  //  position.y += 1; 
  //}
}
//define class
class Umbrella {
  //state variables
  int umbX;
  int umbY;
  int umbYC;

  //constructor
  Umbrella() {
    umbX = 200;
    umbY = 210;
    umbYC = 80;
  }


  void display() {
    //displays umbrella
    fill (#738fcb);
    bezier(umbX, umbY, umbX, umbYC, umbX+260, umbYC, umbX+260, umbY);
    strokeWeight(10);
    stroke(#738fcb);
    line(330, umbY, 330, 420);
  }
}