Your browser does not support the canvas tag.

previous        Show / Hide Source        Download        next
Fountain fountain = new Fountain();
Trees trees = new Trees();

// Array
Bird[] borbs = new Bird[3];

void setup() {
  size(600, 400);
  makeBirds();
}
void makeBirds() {
  for (int i=0; i<3; i++) {
    borbs[i]=new Bird(random(-200, -40), random(0, 150), random(1, 4), 0);
  }
}

void draw() {
  for (int i=0; i<3; i++) {
    borbs[i].update();
  }
  rectMode(CENTER);
  background(252, 255, 245);
  fill(145, 170, 157);
  rect(300, 300, 600, 240);

  fountain.display();
  trees.bL();
  trees.bR();
  trees.mR();
  trees.mL();
  for (int i=0; i<borbs.length; i++) {
    borbs[i].display();
  }
  trees.fL(); 
  trees.fR();
  fountain.fountainSpurt();
}
class Bird {
  PVector position=new PVector();
  PVector speed=new PVector();

  color birdColor;
  //set up the bird variables and vectors (sampled from RaceWay)
  Bird(float x, float y, float velocityX, float velocityY) {
    position.x=x;
    position.y=y;
    speed.x=velocityX;
    speed.y=velocityY;
    RandoBirdrColor();
  }
  // refresh the bird's position
  void update() {
    position.add(speed);
    if (position.x>width+40) {
      position.x=-40;
      position.y=random(0, 150);
      RandoBirdrColor();
    }
  }

  void RandoBirdrColor() {
    birdColor=color(random(200, 255), random(200, 255), random(150, 255));
  }
  void display() {
    fill(birdColor);
    ellipse( position.x, position.y+10*sin(frameCount/5), 25, 10);
  }
}
class Fountain {
  float w = 15;
  boolean doFountainSpurt = false;

  Fountain() {
  }

  //when you click, it makes the fountain spurt up
  void fountainSpurt() {
    if (mousePressed == true) {
      doFountainSpurt = true;
      println("FLOOOSH!");
    } else {
      doFountainSpurt=false;
            println("*trickle trickle trickle*");
    }
    if (doFountainSpurt == true) {
      w = 15*sin(frameCount/5)+20;
    } else {
      w=0;
    }
  }
  void display() {
    noStroke();
    rectMode(CENTER);
    fill(62, 96, 111);

    //fountain stem 2
    rect(300, 215, 20, 50);
    triangle(310, 190, 320, 190, 310, 200);
    triangle(280, 190, 290, 190, 290, 200);

    //Water top
    fill(209, 219, 189, 200);
    //Change this rectangle to CORNERS so that when the spurt happens,
    //it doesn't appear below the fountain as well
    rectMode(CORNERS);
    rect(270 + sin (frameCount/5), 185-w, 330- sin (frameCount/5), 250, 10);
    fill(62, 96, 111);
    rectMode(CENTER);


    //fountain stem
    rect(300, 245, 60, 10);
    triangle(320, 250, 320, 260, 330, 250);
    triangle(280, 250, 280, 260, 270, 250);
    rect(300, 275, 40, 50);

    //Water mid
    fill(209, 219, 189, 200);
    rect(300, 275, 100 + sin (frameCount/10), 70, 10);
    fill(62, 96, 111);

    //fountain L2
    rect(300, 310, 140, 20);

    //Water bottom
    fill(209, 219, 189, 200);
    rect(300, 320, 160 + 2*(sin(frameCount/15)), 40, 10);
    fill(62, 96, 111);

    //fountain base
    rect(300, 335, 200, 30);
  }
}
class Trees {
  Trees() {
  }

  //////////////////////////
  ///////    BACK    ///////
  //////////////////////////

  //Tree back left
  void bL() {
    noStroke();
    rectMode(CORNERS);
    fill(51, 83, 98);
    rect(60, 160, 80, 220);
    //leaves
    fill(126, 156, 140);
    rect(-150, -130, 250, 160, 50);
    rect(-280, -60, 280, 60, 50);
  }

  //Tree back right
  void bR() {
    fill(51, 83, 98);
    rect(520, 160, 540, 220);
    //leaves
    fill(126, 156, 140);
    rect(350, -130, 650, 160, 50);
    rect(-280, -60, 280, 60, 50);
  }

  //////////////////////////
  ///////   MIDDLE   ///////
  //////////////////////////

  //Tree middle left
  void mL() {
    fill(31, 64, 80);
    rect(30, 140, 60, 270);
    //leaves
    fill(114, 146, 129);
    rect(-150, -130, 170, 140, 50);
    rect(-280, -60, 260, 110, 50);
  }

  //Tree middle right
  void mR() {
    fill(31, 64, 80);
    rect(540, 140, 570, 270);
    //leaves
    fill(114, 146, 129);
    rect(430, -130, 670, 140, 50);
    rect(340, -60, 660, 110, 50);
  }

  //////////////////////////
  ///////    FRONT   ///////
  //////////////////////////

  //Tree front left
  void fL() {
    fill(25, 52, 65);
    rect(0, 130, 30, 400);
    //leaves
    fill(100, 130, 114);
    rect(-150, -130, 150, 130, 50);
    rect(-280, -60, 280, 60, 50);
  }

  //Tree front right
  void fR() {
    fill(25, 52, 65);
    rect(570, 130, 600, 400);
    //leaves
    fill(100, 130, 114);
    rect(450, -130, 650, 130, 50);
    rect(320, -60, 680, 60, 50);
  }
}