Your browser does not support the canvas tag.

previous        Show / Hide Source        Download        next
void setup() {

  // Set size of the window
  size (400, 400);
  
}

// Variables that will be used as color values for the flower's center
int center = 250 ;

void draw() {

  // Set color of the background
  background (100, 180, 250) ;
  
  // Set stem color, size and position
  fill (0, 200, 10);
  rect (195, 200, 10, 200);

  // Set color and size of the flower's center
  fill(250, center, 100) ;
  ellipse (200, 200, 50, 50) ;

  // Set color of the flower petals and center depending on wheather or not the mouse is being pressed
  // Also changes the background to nature if the mouse is being pressed
  if (mousePressed == true) {
    
    // Changes the color of the flower's center when clicked
    center = 0 ;
    
    // Set size and position of the flower petals
    fill (240, 130, 190) ;
    ellipse (200, 140, 70, 70) ;
    ellipse (236, 250, 70, 70) ;
    ellipse (164, 250, 70, 70) ;
    ellipse (142, 182, 70, 70) ;
    ellipse (258, 182, 70, 70) ;
    
    // Trees
    fill (0, 160, 50);
    triangle (60, 40, 20, 140, 100, 140);
    triangle (60, 140, 10, 240, 110, 240);
    triangle (60, 240, 0, 340, 120, 340);
    // Tree trunk
    fill (150, 100, 0);
    rect (40, 340, 40, 60);
    
    // Dark Grass
    fill (0, 110, 50);
    triangle (110, 360, 115, 400, 125, 400);
    triangle (140, 340, 135, 400, 145, 400);
    triangle (170, 350, 150, 400, 160, 400 );
    triangle (230, 360, 230, 400, 240, 400);
    triangle (250, 345, 245, 400, 255, 400);
    triangle (280, 360, 265, 400, 275, 400);
    
    // Light grass
    fill (150, 200, 100);
    triangle (320, 260, 300, 400, 310, 400);
    triangle (340, 190, 335, 400, 343, 400); 
    triangle (360, 220, 360, 400, 370, 400);
      
  } 
  
  // Changes the background to the city
  // Changes the flower's center color
  else {
    
    // Changes the color of the flower's center
    center = 250;
    
    // Building 1
    fill (150) ;
    rect (10, 60, 80, 390);
    //Building 1 Dectoration
    fill (170);
    rect (20, 70, 15, 390);
    rect (64, 70, 15, 390);
    rect (42, 70, 15, 390);
    
    // Building 2
    fill (120) ;
    rect (110, 240, 70, 260);
    // Building 2 windows
    fill (0, 10, 100, 80);
    rect (120, 260, 20, 30);
    rect (150, 260, 20, 30);
    rect (120, 300, 20, 30);
    rect (150, 300, 20, 30);
    rect (120, 340, 20, 30);
    rect (150, 340, 20, 30);
    rect (120, 380, 20, 20);
    rect (150, 380, 20, 20); 
    
    // Building 3
    fill (190);
    rect (300, 100, 90, 320);
    // Building 3 windows
    fill (0, 100, 200, 40);
    rect (310, 110, 70, 20);
    rect (310, 140, 70, 20);
    rect (310, 170, 70, 20);
    rect (310, 200, 10, 390);
    rect (330, 200, 10, 390); 
    rect (350, 200, 10, 390);
    rect (370, 200, 10, 390);
    
    // Building 3
    fill (150);
    rect (220, 290, 70, 290);
    // Building 3 windows
    fill (180);
    rect (230, 300, 50, 10);
    rect (230, 320, 10, 60);
    rect (250, 320, 10, 60);
    rect (270, 320, 10, 60);
    rect (230, 390, 50, 10);
    
  }
   
   // Set leaf size, position and color
   fill (0, 200, 10);
   ellipse (245, 320, 80, 40);
   
   // Circle that follows the mouse
   fill (100, 50, 190);
   ellipse (mouseX, mouseY, 10, 10);
   
}