• fullscreen
  • StreetLight.pde
  • assignment_4.pde
  • class StreetLight {
      float x1, y1, w1, h1;
      color c;
      color c2;
      color c3;
      color c4;
      boolean on;
    
      StreetLight(float tx, float ty, float th) {
    
        x1 = tx - .4*th;
        y1 = ty - 2.2*th;
    
        w1 = th/4;
        h1 = 4*th;
    
        c = color (95, 90, 90);
        c2= color (232, 221, 103);
        c3= color (191, 190, 181);
        c4= color (198, 227, 41);
        on= true;
      }
    
      void display() {
        fill(c);
        rectMode(CENTER);
        //pole
        rect(x1, y1, w1, h1);
        //knob on top of bulb
        ellipse(x1, y1 - h1/1.9, w1, h1/3);
        //bulb
        if (on)
          fill(c2);
        else
          fill(100);
        ellipse(x1, y1 - h1/2, 5*w1, h1/4);
        //decor at base of bulb
        fill(c3);
        ellipse(x1, y1- h1/2.7, w1/1.1, w1/1.1);
        ellipse(x1+w1/1.1, y1- h1/2.7, w1/1.1, w1/1.1);
        ellipse(x1-w1/1.1, y1- h1/2.7, w1/1.1, w1/1.1);
      }
    
      /*void turnOn() {
       if (color = c2) {
       fill(c4);
       ellipse(x1, y1 - h1/2, 5*w1, h1/4);
       }
       }
       
       void turnOff() {
       }
       */
      boolean isOn() {
        return on;
      }
    
      void turnOn() {
        on = true;
      }
    
      void turnOff() {
        on = false;
      }
    
    //  void display() {
    //    drawLight();
    //  }
    }
    
    
    //Assignment #4
    //Name: Jessica Tan
    //E-mail: jtan@brynmawr.edu
    //Date: 10/5/10
    
    //----snip here---
    
    // Street Lights...
    
    // The array of StreetLight objects....
       StreetLight[] lights;
    
    void setup() {
    
     size(800, 600);
       smooth();
       background(255);
       frameRate(30);
    
     // these variables are used in creating the street lights
       float x, y, m = -0.375, c;
       float h = 100, distance = 300;
       // Create 6 street lights
       lights = new StreetLight[6];
    
     x = 100; // x location of first street light
       c = height-10; // the intercept for locating the rest of lights
       for (int i = 0; i < 6; i++) {
       y = m*x+c;
       // create a new light at <x, y> of height h
       lights[i] = new StreetLight(x, y, h);
    
     h = h*0.75;
       distance = distance*0.75;
       x += distance;
       }
       } // setup
     
    
    void draw() {
    
     
    
     drawScene();
    
     fill(255);
    
     int i;
    
     // first draw all the lights (in their current state)
       for (i = 0; i < 6; i++)
       lights[i].display();
    
     // randomly turn some light on/off
       if ((frameCount%150) == 0) {
       i = (int)random(6);
       if (lights[i].isOn()) {
       lights[i].turnOff();
       }
       else {
       lights[i].turnOn();
       }
       }
       } // draw
    
    void drawScene() {
       // draws the street scene...
       // curb
       smooth();
       fill(0);
       noStroke();
       quad(25, height, width, 300, width, 315, 150, height);
    
     // sidewalk
       noStroke();
       // fill(85, 82, 77);
       fill(90, 55, 39);
       beginShape();
       vertex(0, height-250);
       vertex(width, 220);
       vertex(width, 301);
       vertex(26, height);
       vertex(0, height);
       vertex(0, height-250);
       endShape(CLOSE);
    
     // dark background
       noStroke();
       fill(98, 73, 76);
       quad(0, height-249, width, 221, width, 0, 0, 0);
    
     // road
       noStroke();
       fill(75);
       triangle(149, height, width, 314, width, height);
       } // drawScene
    
    //---snip---
    
    
    

    code

    tweaks (0)

    about this sketch

    This sketch is running as Java applet, exported from Processing.

    license

    advertisement

    Ira Greenberg

    Jessica Tan

    Add to Faves Me Likey@!
    You must login/register to add this sketch to your favorites.

    Street Lights

    You need to login/register to comment.