• fullscreen
  • Circle.pde
  • Firenetwork.pde
  • Intersection.pde
  • //...................................................
    //............................... circle object class
    class Circle {
      float x, y;
      float radius;
      int grey, r, g, b;
    
      //...................................................
      //................... standard object creation method
      Circle(float pcenterX, float pcenterY)
      {
        float travDist, minRad, maxRad, radFactor;
    
        x = mouseX;
        y = mouseY;
    
        //find the distance the mouse has traveled since the previous Circle
        travDist=dist(pcenterX, pcenterY, mouseX, mouseY);
        minRad=3; //set minimum randomized radius
        maxRad=5; //set maximum for randomized radius
        radFactor=.125; //scaling factor for the travel distance multiplier
    
        //set Circle radius
        radius = int( random(minRad,maxRad) * (travDist * radFactor));
    
        //set colors, 20% randomized grey, 80% randomized color
    
          grey = int(random(0,100));
    
        if (grey > 20) {
          r = (int) circleR;
          g = (int) circleG;
          b = (int) circleB;
        }
        else {
          r = int(random(100,200));
          g = r;
          b = r;
        }
      }
    
    
      //...................................................
      //..................... object method to draw circles
      void drawCirc()
      {
        noFill();
        smooth();
        strokeWeight(1);
        stroke(r,g,b);
        ellipse(x, y, radius*2, radius*2);
      }
    }
    
    
    //Firenetwork by Jack Gaumer
    //Fall 2010 Midterm Project
    //Southern California Insititute of Architecture
    //Visual Studies 8500 - Generative Design, with Jeremy Rotsztain
    //10.19.2010
    
    
    //set drawing size as variables
    int dwgWidth = screen.width;
    int dwgHeight = screen.height;
    
    //randomizing colors for cirles
    float circleR = random(0,255);
    float circleG = random(0,255);
    float circleB = random(0,255);
    
    //randomizing colors for intersection point network
    float netSR = random(0,255);
    float netSG = random(0,255);
    float netSB = random(0,255);
    float netSA = random(50,100);
    float netFR = netSR + 150;
    float netFG = netSG + 150;
    float netFB = netSB + 150;
    float netFA = 4;
    
    //randomizing colors for firework orbs
    float orbR = random(0,255);
    float orbG = random(0,255);
    float orbB = random(0,255);
    float orbA = random(5,25);
    
    //boolean switch for the intersection point push mode
    boolean pushMode = false;
    
    //object list initialization
    ArrayList circles;
    ArrayList inters;
    
    //...................................................
    //............................. standard setup method
    void setup() {
      size(dwgWidth, dwgHeight);
      background(0);
    
      //object initialization
      circles = new ArrayList();
      inters = new ArrayList();
    }
    
    //...................................................
    //.............................. standard draw method
    void draw() {
    
      //switch to put the sketch into network PUSH MODE
      if(pushMode == true)
      {
        if(inters.size() != 0) //making sure that intersections do infact exist
        {
          for(int k = 0; k< inters.size(); k++) //check each intersection point for pushing
          {
            Intersection inter = (Intersection) inters.get(k);
            pushInter(inter); //push intersection points
          }
        }
      }
      else { //drawing GENERATION MODE
    
        //redraw current circle set first
        for(int k = 0; k< circles.size(); k++)
        {
          Circle c = (Circle) circles.get(k);
          c.drawCirc();
        }
    
    
        //redraw current intersection set second
        if(inters.size() != 0)
        {
          for(int k = 0; k< inters.size(); k++)
          {
            Intersection inter = (Intersection) inters.get(k);
            inter.drawInter();
          }
        }
    
    
        //circle and intersection generation
        if((frameCount % 30) == 0) //conditional to make sure that circles draw every 30 frames only
        {
          if(circles.size() == 0) //conditional to handle the very first circle generation
          {
            int randX = (int) random(0,dwgWidth);
            int randY = (int) random(0,dwgHeight);
    
            circles.add(new Circle(randX, randY));
          }
          else //generation for all circles after the first
          {
            Circle c = (Circle) circles.get(circles.size()-1); //working object of the circle previous to the new one
            if(circles.size() >= 10) //makes sure that there are only 10 circles in existance at any time
            {
              circles.remove(0);
            }
            circles.add(new Circle(c.x, c.y)); //circle creation, with previous circle centerpoints as input
          }
    
          Circle cc = (Circle) circles.get(circles.size()-1);  //working object of the new circle
          for(int k = 0; k < circles.size(); k++)
          {
            Circle cp = (Circle) circles.get(k); //working object for all objects but the new one
            findInter(cp, cc); //check for and create intersection points between circles
          }
        }
      }
    
    
      //draw intersection network
      fill(netFR, netFG, netFB, netFA);
      stroke(netSR, netSG, netSB, netSA);
      strokeWeight(1);
      beginShape();
      for(int k = 0; k< inters.size(); k++)
      {
        if ((k > 0) && (k < inters.size()))
        {
    
          Intersection interb = (Intersection) inters.get(k);
          Intersection intere = (Intersection) inters.get(k);
    
          vertex(interb.x, interb.y);
          vertex(intere.x, intere.y);
        }
      }
      endShape(CLOSE);
    }
    
    
    
    //...................................................
    //........... method for intersection point PUSH MODE
    public void pushInter(Intersection interPoint)
    {
      float pushFactor = 0;
    
      if( dist(mouseX, mouseY, interPoint.x, interPoint.y) <= 5) {
        pushFactor = 4;
      }
      else if( dist(mouseX, mouseY, interPoint.x, interPoint.y) <= 20) {
        pushFactor = 2;
      }
      else if( dist(mouseX, mouseY, interPoint.x, interPoint.y) <= 40) {
        pushFactor = 1;
      }
      else if( dist(mouseX, mouseY, interPoint.x, interPoint.y) <= 70) {
        pushFactor = .75;
      }
      else if( dist(mouseX, mouseY, interPoint.x, interPoint.y) <= 100) {
        pushFactor = .5;
      }
      else if( dist(mouseX, mouseY, interPoint.x, interPoint.y) <= 130) {
        pushFactor = .25;
      }
      else if( dist(mouseX, mouseY, interPoint.x, interPoint.y) <= 160) {
        pushFactor = .15;
      }
      else {
        return;
      }
    
    
      if((mouseX - interPoint.x) < 0)
      {
        interPoint.x = interPoint.x + (abs(mouseX - interPoint.x)*pushFactor);
      }
      else
      {
        interPoint.x = interPoint.x - (abs(mouseX - interPoint.x)*pushFactor);
      }
    
    
      if((mouseY - interPoint.y) < 0)
      {
        interPoint.y = interPoint.y + (abs(mouseY - interPoint.y)*pushFactor);
      }
      else
      {
        interPoint.y = interPoint.y - (abs(mouseY - interPoint.y)*pushFactor);
      }
      
    }
    
    
    
    //...................................................
    //................. circle-circle intersection method
    //mathematics to find the Intersections was based on the following geometric result
    //http://local.wasp.uwa.edu.au/~pbourke/geometry/2Circle/
    public void findInter(Circle prev, Circle curr)
    {
      float d = dist(prev.x, prev.y, curr.x, curr.y); //distance between center of Circles
      float a = 0; //a is to be the distance between the center of one of the Circles and the line of Intersection
      float dx, dy; //change in x and y values between the centers of the two Circles
      float x2, y2; //coordinates of the Intersection of the line from center to center and the line described in the comment of a
      float h = 0; //h is to be the distance from x2,y2 to the Intersection points along the line of Intersection
      float rx, ry; //offset distance from x2 and y2 to the Intersection points
    
      if ( (d > prev.radius + curr.radius) || (d < abs(prev.radius - curr.radius)) ) //if there are no Intersections
      {
        return;
      }
      else if ((d == 0) && (prev.radius == curr.radius)) //if the Circles are coincident
      {
        return;
      }
      else //if there are Intersections
      {
        a = ( (pow(prev.radius, 2) - pow(curr.radius, 2) + pow(d, 2))/(2*d));
        dx = curr.x - prev.x;
        dy = curr.y - prev.y;
    
        x2 = prev.x + ( dx * (a/d) );
        y2 = prev.y + ( dy * (a/d) );
    
        h = sqrt( pow(prev.radius, 2) - pow(a, 2));
    
        rx = -dy * (h/d);
        ry = dx * (h/d);
    
        if(d == prev.radius) //check to see if there is only one Intersection, set values accordingly
        {
          inters.add(new Intersection(x2, y2));
        }
        else //there are two Intersections, set values accordingly
        {
          inters.add(new Intersection(x2 + rx, y2 + ry));
          inters.add(new Intersection(x2 - rx, y2 - ry));
        }
      }
      return;
    }
    
    
    
    //...................................................
    //.................. mode keyPressed overwrite method
    void keyPressed() {
      if(key == 's')
      {
        saveFrame("firenetwork-########.tiff");
      }
      if(key == 'q')
      {
        if(pushMode == false)
        {
          pushMode = true;
        }
        else
        {
          pushMode = false;
          netSR = random(0,255);
          netSG = random(0,255);
          netSB = random(0,255);
          netSA = random(50,100);
          netFR = netSR + 150;
          netFG = netSG + 150;
          netFB = netSB + 150;
        }
      }
    }
    
    
    //...................................................
    //......................... intersection object class
    class Intersection {
      float x,y;
      int time;
    
      //...................................................
      //................... standard object creation method
      Intersection(float xi, float yi)
      {
        x = xi;
        y = yi;
      }
    
      //...................................................
      //.......................... object initiation method
      void initiateInter(float xi, float yi)
      {
        x = xi;
        y = yi;
        time = 0;
      }
    
      //...................................................
      //............................ orb object draw method
      void drawInter()
      {
        float orbRad;
    
        smooth();
        noStroke();
        fill(orbR, orbG, orbB, orbA);
        orbRad = (time * .8);
    
          ellipse(x, y, orbRad, orbRad);
          if(time == 600) //checks to see if 600 ticks of time have passed before starting to change orb colors
          {
            time = 0;
            orbR = random(0,255);
            orbG = random(0,255);
            orbB = random(0,255);
            orbA = random(10,40);
          }
        time++;
      }
    }
    
    

    code

    tweaks (0)

    license

    advertisement

    Jack Gaumer

    Firenetwork

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

    A "drawing tool".

    Click into the drawing tool window and press 'q' to toggle a different mode on and off.

    You need to login/register to comment.