import ddf.minim.signals.*; import ddf.minim.*; import ddf.minim.analysis.*; import ddf.minim.effects.*; Minim minim; AudioInput input; FFT spectrum; // int maxCells = 2000; // max number of cells in the "colony" float anglefactormin = 0.3; // try an assymetrical range to get more curly shapes float anglefactormax = 0.7; // or a more constrained range for fewer branches int numBands = 44; // how many freq bands int lifeSpan = 500; // how many ticks each cell lives for int spawnEnergy = 50; // min cell energy to breed int branchEnergy = 400; float breedChance = 0.5; float branchChance = 0.01; float diameterFactor = 200; // multiplier - diameter = diameterFactor/(band+1) float ampFactor = 1; // multiplier to get cell wall thickness from spectrum band amplitude float Damping = 0.99; // damps incoming audio // float worldx = 0; float worldy = 0; ArrayList Cells = new ArrayList(maxCells); //ArrayList growCells = new ArrayList(maxCells); Cell firstCell; void setup(){ size(1000,450); background(0); firstCell = new Cell(400,400,0.0,20,0.3); // x,y,angle,band, branchcurve Cells.add(firstCell); // minim = new Minim(this); input = minim.getLineIn(Minim.MONO, 1024); spectrum = new FFT(1024,44100); spectrum.logAverages(11,4); // make 44 log spaced bands, lowest at 11Hz // } void draw(){ doSpectrum(); //background(0); noStroke(); fill(0,20); rect(0,0,width,height); translate(worldx,worldy); noFill(); stroke(255,100); smooth(); for (int i=0; i lifeSpan && energy < 100){ Cells.remove(this); if (parent != null) parent.numkids--; } else if (energy > spawnEnergy && Cells.size() < maxCells) { // if you're big enough, there's room to breed, and you're lucky float chance = random(1); if (numkids == 0 && chance < breedChance){ makeChild(parent_angle+branch_curvature, branch_curvature+random(-0.05,0.05)); // continue this branch with a small curve mutation } else if (chance < branchChance && energy > spawnEnergy*4) { makeChild(parent_angle-1.5, branch_curvature+random(-0.2,0.2)); // start a new branch with a mutated curvature } } } } void stop() { input.close(); super.stop(); } void keyPressed(){ if (keyCode == UP){ worldy -= 5; } else if (keyCode == DOWN){ worldy += 5; } else if (keyCode == LEFT){ worldx -= 5; } else if (keyCode == RIGHT){ worldx += 5; } }