ArrayList seeds; float smallest = 0.5; float LUTstep = 0.01; int angleMax = int(TWO_PI/LUTstep); int rightAngle = angleMax/4; float[] sinLUT; float[] cosLUT; float hue = 0; boolean colour = false; void setup() { size(600,400); background(255); // 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(HSB); fill(0); seeds = new ArrayList(); seeds.add(new Seed(width/2, height/2)); frameRate(30); } void draw() { // fill(255,5); // rectMode(CORNERS); // rect(0,0,width,height); if (colour) { fill(hue++,255,255); hue = hue%255; } else { fill(0); } 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; angle = int(random(angleMax)); //angle = 0; rot = int(random(0.15)*angleMax/TWO_PI); // rot = int(0.15*angleMax/TWO_PI); shrink = random(0.012)+0.98; //shrink = 0.992; // shrink = 0.98; fertility = random(0.03) + 0.02; // fertility = 0.03; } void draw() { if (dead) return; if (size < smallest) { dead = true; return; } if (y > height || y < 0 || x > width || x < 0) { dead = true; return; } ellipse(x,y,size,size); x += size*cosLUT[angle]; y += size*sinLUT[angle]; angle = ((angle+rot)+angleMax)%angleMax; size *= shrink; if (random(1) < fertility) { 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(255); } void keyPressed() { if (key =='c') reset(); if (key == 'g') colour = !colour; } void mousePressed() { seeds.add(new Seed(mouseX, mouseY)); } void mouseDragged() { seeds.add(new Seed(mouseX, mouseY)); }