//Hairball_4Trees_GreenOnBlack //Michael Shaub //Aug, 18, 2007 //------------- //Based very much on "Hairballs" by W. Xavier Sneigrove ArrayList seeds; float smallest = 0.5; float LUTstep = 0.01; int step = 1; int direction = 0; int angleMax = int(TWO_PI/LUTstep); int rightAngle = angleMax/4; float[] sinLUT; float[] cosLUT; float hue = 0; boolean colour = false; boolean wait = true; int redrawWhite = 0; void setup() { size(600,400); background(0); fill(0,255,0,128); // INitialize LUTs sinLUT = new float[int(TWO_PI/LUTstep)+1]; cosLUT = new float[int(TWO_PI/LUTstep)+1]; int i = 0; for (float angle = 0; angle < TWO_PI; angle += LUTstep) { sinLUT[i] = sin(angle); cosLUT[i] = cos(angle); i++; } ellipseMode(CENTER); noStroke(); smooth(); //colorMode(RGB); fill(0,255,0,128); seeds = new ArrayList(); seeds.add(new Seed(width/2, height)); frameRate(15); } void draw() { // fill(255,5); // rectMode(CORNERS); // rect(0,0,width,height); if (redrawWhite >= 100){ for (float k=height; k>0; k--){ strokeWeight(1); stroke(0,0,0,10); line(0,k,width,k); stroke(0,0,0,255); line(0,0,width,0); noStroke(); } redrawWhite=0; }else{ redrawWhite++; println("whiteCounter = "+redrawWhite); } if (wait==false){ seeds.add(new Seed(width/2, height)); } if (colour) { fill(hue++,255,255); hue = hue%255; } else { fill(0,255,0,128); } int vectorTop = seeds.size(); for (int i = 0; i < vectorTop; i++) { Seed seed = (Seed) seeds.get(i); seed.draw(); if (seed.dead) { seeds.remove(i); i--; vectorTop--; } } } class Seed { boolean dead = false; int angle; float size = 5; float x; float y; int rot; float shrink = 0.99; float fertility = 0.03; Seed(float _x, float _y, int _angle, float _size, int _rot, float _shrink, float _fertility) { x = _x; y = _y; angle = _angle; size = _size; rot = _rot; shrink = _shrink; fertility = _fertility; } Seed(float _x, float _y) { x = _x; y = _y; if (random(-1,1) < 0){ angle = int(random(400,470)); direction = -1; } else{ angle = int(random(90,120)); direction = 1; } //angle = 470;//int(random(angleMax)); //angle = 90; rot = int(random(0.01,0.05)*angleMax/TWO_PI); //println("rot = "+ rot); // rot = int(0.15*angleMax/TWO_PI); shrink = random(0.012)+0.98; //shrink = 0.8992; // shrink = 0.98; fertility = random(0.03) + 0.02; //fertility = 0.02; } void draw() { if (dead) return; if (dead) { wait=false; } if (size < smallest) { dead = true; wait=false; return; } if (y > height || y < 0 || x > width || x < 0) { dead = true; wait=false; return; } //direction = int(random(-10,10)); println(direction); ellipse(x,y,size,size); wait=true; x += size*cosLUT[abs(angle)]; if (direction < 0){ y += size*sinLUT[abs(angle)]; angle = ((angle+rot)+angleMax)%angleMax; } else{ y -= size*sinLUT[abs(angle)]; angle = ((angle+rot)+angleMax)%angleMax; } size *= shrink; if (size < 3){ if (random(1) < fertility) { if (direction < 0){ int angle2 = int(-.5*(angle+rightAngle)%angleMax); seeds.add(new Seed(x+size*cosLUT[abs(angle2)], y+size*sinLUT[abs(angle2)], angle2, size, rot, shrink, fertility)); } else{ int angle2 = (angle+rightAngle)%angleMax; seeds.add(new Seed(x+size*cosLUT[angle2], y+size*sinLUT[angle2], angle2, size, rot, shrink, fertility)); } } } } } void reset() { seeds.clear(); background(0,0,0); } void keyPressed() { /*if (key =='c') reset(); if (key == 'g') colour = !colour; */ } void mousePressed() { redrawWhite = 100; } void mouseDragged() { redrawWhite = 100; //seeds.add(new Seed(mouseX, mouseY)); }