/* DO NOT COPY THIS CODE!! */
//// p1demo: Project #1 demo.
////// Dynamic sketch - modularized.
////// Mouse resets hero, dog follows hero
//
//float horizon;
//float sunX, sunY;          // Position of sun
//float xBarney, yBarney;    // Position and speed of creature.
//float xSpeed, ySpeed;
//float xMutt, yMutt;        // Position of dog.
//float houseX=100, houseY=150, houseW=200, houseH=100;
//Tree tree1,tree2;
//
//color RED=color(255,0,0), GREEN=color(0,255,0), BLUE=color(0,0,255);
//color YELLOW=color(255,255,0), MAGENTA=color(0,255,255), CYAN=color(255,0,255);
//color BROWN=color(127,0,0), DARK=color(0,150,0), WHITE=color(255), BLACK=color(0);
//
////// SETUP:  Define screen size, set modes.
//void setup()
//{
//  size( 800, 600 );
//    smooth();
//      horizon=  height/4;
//        houseY=  horizon-houseH;
//          reset();
//          }
//          void reset() {
//            sunX=  width/2;                   // Start the sun half-way
//              sunY=  random( 20, horizon-20 );  // at random height
//                xBarney=  houseX+5;              // Start creature in door.
//                  yBarney=  houseY+10;
//                    xSpeed=  random( 2,5 );           // Random speeds.
//                      ySpeed=  random( -2, +2 );
//                        tree1= new Tree();
//                          tree2= new Tree();
//                          }
//
//
//                          //// DRAW:  sky & sun plus creature
//                          void draw()
//                          {
//                            scene();
//                              action();
//                                show();
//                                  messages();            // (Display the messages last.)
//                                  }
//
//
//                                  //// SCENE:  sky, sun, house.
//                                  void scene() {
//                                    background( 150, 200, 250 );          // Blue sky
//                                      fill( YELLOW );
//                                        ellipse( sunX, sunY, 30, 30 );        // Yellow sun
//                                          fill( GREEN );
//                                            rect( 0,horizon, width,height-horizon );    // Grass
//                                              house();
//                                                trees( );
//                                                }
//                                                void house() {
//                                                  // Red house
//                                                    fill( RED );
//                                                      rect( houseX,houseY, houseW,houseH );              
//                                                        triangle( houseX,houseY, 
//                                                            houseX+houseW,houseY, 
//                                                                houseX+houseW/2,houseY-houseH/2 );
//                                                                  // Brown door with round yellow window
//                                                                    fill( BROWN );      // 
//                                                                      rect( houseX+10,houseY+10, 50,houseH-10 );
//                                                                        fill( YELLOW );
//                                                                          ellipse( houseX+35,houseY+30, 24,24 );
//                                                                            // More windows
//                                                                              strokeWeight(2);
//                                                                                fill( WHITE );      // 
//                                                                                  rect( houseX+80,houseY+25, 30,40 );
//                                                                                    rect( houseX+140,houseY+25, 30,40 );
//                                                                                      strokeWeight(1);
//                                                                                      }
//                                                                                      void trees() {
//                                                                                        tree1.show();
//                                                                                          tree2.show();
//                                                                                          }
//
//                                                                                            
//
//                                                                                            //// MESSAGES.
//                                                                                            void messages() {
//                                                                                              fill(0);
//                                                                                                textSize(20);
//                                                                                                  text( "Project #1 demo.", width/3, 20 );
//                                                                                                    textSize(12);
//                                                                                                      text( "Click to reset hero & dog.\n  Press any key reset.", 10, height/2 );
//                                                                                                        // Also display the author and file name.
//                                                                                                          text( "B.A.Martin / p1demo.pde", 10, height-10 );
//                                                                                                          }
//
//                                                                                                          //// ACTION:  sun moves (then resets to random height)
//                                                                                                          void action() {
//                                                                                                            if (sunX > width) {
//                                                                                                                sunX=  0;
//                                                                                                                    sunY=  random( 20, 120 );
//                                                                                                                      }
//                                                                                                                        sunX=  sunX + 1;
//                                                                                                                          // Move the creature.
//                                                                                                                            if (xBarney>width-30  || xBarney<80) xSpeed = -xSpeed;
//                                                                                                                              if (yBarney>height-50 || yBarney<horizon-100) ySpeed = -ySpeed;
//                                                                                                                                xBarney=  xBarney + xSpeed;
//                                                                                                                                  yBarney=  yBarney + ySpeed;
//                                                                                                                                  }
//
//                                                                                                                                  //// Show hero & dog.
//                                                                                                                                  void show() {
//                                                                                                                                    hero();
//                                                                                                                                      xMutt= xSpeed>0 ? xBarney-100 : xBarney+100;
//                                                                                                                                        yMutt= yBarney+100;
//                                                                                                                                          dog();
//                                                                                                                                          }
//                                                                                                                                          void hero() {
//                                                                                                                                            // Draw creature.
//                                                                                                                                              fill( BLUE );
//                                                                                                                                                rect( xBarney,yBarney, 50, 80 );                 // Blue body
//                                                                                                                                                  fill( 200, 150, 100 );
//                                                                                                                                                    ellipse( xBarney+25, yBarney-20, 40, 40 );       // Head on top
//                                                                                                                                                      fill( YELLOW );
//                                                                                                                                                        text( "Barney", xBarney+5, yBarney+15 );         // Name on shirt
//                                                                                                                                                          // Eyes.
//                                                                                                                                                            fill( 255 );
//                                                                                                                                                              ellipse( xBarney+15, yBarney-25, 12, 12 );
//                                                                                                                                                                ellipse( xBarney+35, yBarney-25, 12, 12 );
//                                                                                                                                                                  float look= xSpeed>0 ? -2 : +2;
//                                                                                                                                                                    fill( 0, 150, 0 );
//                                                                                                                                                                      ellipse( xBarney+15+look, yBarney-23, 4, 4 );
//                                                                                                                                                                        ellipse( xBarney+35+look, yBarney-23, 4, 4 );
//                                                                                                                                                                        }
//                                                                                                                                                                        void dog() {
//                                                                                                                                                                          fill( BROWN );
//                                                                                                                                                                            rect( xMutt,yMutt, 70, 30 );                 // Brown dog
//                                                                                                                                                                              float xHead, yHead;
//                                                                                                                                                                                xHead= xSpeed>0 ? xMutt+50 : xMutt-70+50;
//                                                                                                                                                                                  yHead= yMutt-20;
//                                                                                                                                                                                    rect( xHead,yHead, 40, 20 );
//                                                                                                                                                                                      fill( YELLOW );
//                                                                                                                                                                                        text( "Mutt", xMutt+15, yMutt+15 );         // Name on body
//                                                                                                                                                                                          // Eye.
//                                                                                                                                                                                            fill( 255 );
//                                                                                                                                                                                              ellipse( xHead+12, yHead+5, 12, 12 );
//                                                                                                                                                                                                float look= xSpeed>0 ? -2 : +2;
//                                                                                                                                                                                                  fill( 0, 150, 0 );
//                                                                                                                                                                                                    ellipse( xHead+12-look, yHead+3, 4, 4 );
//                                                                                                                                                                                                    }
//
//
//                                                                                                                                                                                                    //// EVENT HANDLERS ////
//                                                                                                                                                                                                    void mousePressed() {
//                                                                                                                                                                                                      reset();
//                                                                                                                                                                                                        // Set the position (x,y)
//                                                                                                                                                                                                          xBarney=  mouseX;
//                                                                                                                                                                                                            yBarney=  mouseY;
//                                                                                                                                                                                                            }
//                                                                                                                                                                                                            void keyPressed() {
//                                                                                                                                                                                                              reset();
//                                                                                                                                                                                                                houseX= random( 10, width/4 );
//                                                                                                                                                                                                                  houseY= random( horizon, height-50 );
//                                                                                                                                                                                                                  }
//                                                                                                                                                                                                                  //
//                                                                                                                                                                                                                  //
//                                                                                                                                                                                                                  class Tree {
//                                                                                                                                                                                                                    float x=500, y=120, w=60, h=60;
//                                                                                                                                                                                                                      color c=DARK;
//                                                                                                                                                                                                                        //// CONSTRUCTORS ////
//                                                                                                                                                                                                                          Tree() {
//                                                                                                                                                                                                                              x= random( width/2, width );
//                                                                                                                                                                                                                                  y= horizon - random( 80, 130 );
//                                                                                                                                                                                                                                      w= random( horizon-y-20, horizon-y+20 );
//                                                                                                                                                                                                                                          h= random( w-20, w );
//                                                                                                                                                                                                                                              c= color( random(150), random(100,250), random(50) ); 
//                                                                                                                                                                                                                                                }
//                                                                                                                                                                                                                                                  void show() {
//                                                                                                                                                                                                                                                      fill( BROWN );
//                                                                                                                                                                                                                                                          rect( x-10,y, 20, horizon-y );  // Trunk
//                                                                                                                                                                                                                                                              fill( c );
//                                                                                                                                                                                                                                                                  ellipse( x,y, w, h );
//                                                                                                                                                                                                                                                                    }
//                                                                                                                                                                                                                                                                    }
//
