import traer.physics.*; import krister.Ess.*; Pulser[] pulsers = new Pulser[4]; Player pl; ParticleSystem phys = new ParticleSystem(0, .1); AudioFile daft; AudioStream out; FFT analysis; void setup() { size(400, 400); noCursor(); rectMode(CENTER); framerate(24); smooth(); pl = new Player(phys.makeParticle(1, width/2, height/2, 0), 5, 3); // particle, radius, followDist, pulseAmt, color pulsers[0] = new Pulser(phys.makeParticle(1, 50, 70, 0), 25, 50, 1.5, color(255, 0, 0)); pulsers[1] = new Pulser(phys.makeParticle(1, 150, 90, 0), 20, 40, 1.5, color(255, 0, 0)); pulsers[2] = new Pulser(phys.makeParticle(1, 45, 300, 0), 15, 30, 1.5, color(255, 0, 0)); pulsers[3] = new Pulser(phys.makeParticle(1, 234, 300, 0), 10, 20, 1.5, color(255, 0, 0)); for (int i = 0; i < pulsers.length-1; i++) { for (int j = 0; j < pulsers.length; j++) { phys.makeAttraction(pulsers[i].p, pulsers[j].p, -250, 5); } } initEss(512, 16); } void draw() { background(0); analysis.getSpectrum(out); phys.tick(); // println("Frame: " + frameCount); for (int i = 0; i < pulsers.length; i++) { pulsers[i].rendered = false; if ( pulsers[i].p.isDead() ) continue; if ( pulsers[i].isOffScreen() ) { pulsers[i].p.kill(); continue; } if ( analysis.averages[i*4]*100 > 10 ) pulsers[i].pulse(); if ( pulsers[i].isFree() && pulsers[i].distFrom(pl) < 50 ) { pulsers[i].follow(); phys.makeSpring(pl.p, pulsers[i].p, .2, 1, pulsers[i].followDist); } pulsers[i].wallBounce(); for (int j = 0; j < pulsers.length; j++) { pulsers[i].pulseBounce(pulsers[j]); } pulsers[i].render(); } pl.render(); } void keyPressed() { if ( key == CODED ) { pl.move(); } else { if ( key == 'a' ) pl.speedUp(); else if ( key == 's' ) pl.slowDown(); } } void initEss(int bins, int avgs) { Ess.start(this); daft = new AudioFile("hbfs.mp3", 0, Ess.READ, Ess.MIX); out = new AudioStream(128*1024); out.sampleRate(daft.sampleRate); out.start(); analysis = new FFT(bins); analysis.equalizer(true); analysis.limits(); analysis.damp(0.1f); analysis.averages(avgs); } void audioStreamWrite(AudioStream theStream) { // read the next chunk int samplesRead = daft.read(out); if (samplesRead == 0) { // start over daft.close(); daft.open("hbfs.mp3", out.sampleRate, Ess.READ, Ess.MIX); samplesRead = daft.read(out); } } public void stop() { Ess.stop(); super.stop(); }