import processing.core.*; import java.applet.*; import java.awt.*; import java.awt.image.*; import java.awt.event.*; import java.io.*; import java.net.*; import java.text.*; import java.util.*; import java.util.zip.*; public class BifurkationTL extends PApplet {// Max Bense
// Bifurkation
// 2006 Peter Chiochetti
// for Thomas Feuerstein

int maxLen = 35;
int c;
int black = color(0);
int white = color(255);
Vector nodes;

public void setup() {
  size (768, 576);
  background(black);
  frameRate(25);
  nodes = new Vector();
  nodes.add(new Node(width/2, height/2, black));
  c = 1;
}

public void draw() {
  strokeWeight(20);
  c++;
  int n = nodes.size();
  ((Node)nodes.get(PApplet.parseInt(random(n)))).grow();
  if (n >= 1000)
    nodes.removeElementAt(n - 2);
}

class Node {
  float x, y;
  int c;

  Node(float a, float b, int z) {
    x = a;
    y = b;
    c = z;
  }

  public void grow() {
    float ox = x;
    float oy = y;
    float a = random(180);
    float dx = maxLen * cos(a);
    float dy = maxLen * sin(a);
    x += dx;
    y += dy;
    if (x < 0 || y < 0 || x > width || y > height)
    {
      nodes.removeElement(this);
      return;
    }
    stroke(color(random(255), random(255), random(255)));
    line(ox, oy, x, y);

    float x1 = ox + dx / 3;
    float y1 = oy + dy / 3;
    if (x1 < 0 || y1 < 0 || x1 > width || y1 > height)
      return;
    nodes.add(new Node(x1, y1, white));
    stroke(color(random(255), random(255), random(255)));
    line(ox, oy, x1, y1);
  }
}
static public void main(String args[]) {   PApplet.main(new String[] { "BifurkationTL" });}}