import ddf.minim.signals.*; import ddf.minim.*; import ddf.minim.analysis.*; import ddf.minim.effects.*; import traer.physics.*; Minim minim; AudioPlayer song; AudioInput in; BeatDetect beat; BeatListener bl; float kickSize, snareSize, hatSize; float redSize, greenSize, blueSize; ParticleSystem physics; Particle last; float yValue; int mouseCounter = 0; int mouse0 = mouseCounter%2; void setup() { size( 640, 480 ); background(255); fill( 255, 64 ); frameRate( 24 ); physics = new ParticleSystem(0.5, 0.001 ); ellipseMode( CENTER ); smooth(); cursor(CROSS); minim = new Minim(this); song = minim.loadFile("missyou.mp3", 2048); song.play(); beat = new BeatDetect(song.bufferSize(), song.sampleRate()); beat.setSensitivity(30); kickSize = snareSize = hatSize = 16; bl = new BeatListener(beat, song); } void mouseReleased() { mouseCounter++; if (mouseCounter%2 == 0) { physics = new ParticleSystem(0.5, 0.001 ); } else { physics = new ParticleSystem(-0.5, 0.001 ); } } void draw() { //if ( beat.isOnset() ) beatLength = 255; if ( beat.isKick() ) { kickSize = 32; redSize = 255; } if ( beat.isSnare() ) { snareSize = 32; greenSize = 255; } if ( beat.isHat() ) { hatSize = 32; blueSize = 255; } kickSize = constrain(kickSize * 0.95, 16, 32); snareSize = constrain(snareSize * 0.95, 16, 32); hatSize = constrain(hatSize * 0.95, 16, 32); redSize = constrain(redSize * .8, 16, 255); greenSize = constrain(greenSize * .8, 16, 255); blueSize = constrain(blueSize * .8, 16, 255); yValue = mouseY; //println(mouseY/100); for ( int i = 0; i < 5; i++ ) { Particle p = physics.makeParticle( 1.0f, mouseX, mouseY, mouseY); p.setVelocity( random( -1, 1 ), random( -1, -1 ), 0 ); if ( last != null ) physics.makeSpring( p, last, 0.1f, 0.1f, 10 ); last = p; } physics.tick(); noStroke(); for ( int i = 0; i < physics.numberOfParticles(); ++i ) { Particle p = physics.getParticle( i ); if(mouseCounter%2 == 1){ fill(255); } else if(mouseCounter%2 == 0){ fill( redSize, greenSize ,blueSize,(255/(p.age()+1)*(yValue/400)) ); } ellipse( p.position().x(), p.position().y(), 4, 4); if ( p.age() > 30 ){ p.kill(); } if(p.age()>2){ ellipse( p.position().x(), p.position().y(), yValue/35+kickSize/50, yValue/35+kickSize/50); } } } class BeatListener implements AudioListener { private BeatDetect beat; private AudioPlayer source; BeatListener(BeatDetect beat, AudioPlayer source) { this.source = source; this.source.addListener(this); this.beat = beat; } void samples(float[] samps) { beat.detect(source.mix); } void samples(float[] sampsL, float[] sampsR) { beat.detect(source.mix); } }