import ddf.minim.*; import ddf.minim.analysis.*; AudioPlayer song; BeatDetect beat; PImage speaker; float kickSize, snareSize, hatSize = 16; int directionX = 1; int directionY = 1; int directionZ = 1; float angleX = 0; float angleY = 0; float angleZ = 0; float angleDiff = 1; void setup() { size(800, 400, P3D); colorMode(HSB, 360, 100, 100); rectMode(CENTER); Minim.start(this); song = Minim.loadFile("groove.mp3"); song.loop(); beat = new BeatDetect(song.bufferSize(), song.sampleRate()); beat.setSensitivity(300); } float c = 0; void draw() { fill(0, 10); rect(width/2, height/2, width, height); stroke(0,10); c += 0.4; fill(c, 100, 100, 120); if (c > 360) { c = 0; } beat.detect(song.mix); if (beat.isKick()) { kickSize = 200; } if (beat.isSnare()) { directionY = -directionY; } if (beat.isHat()) { directionZ = -directionZ; } angleX = angleX + angleDiff * directionX; angleY = angleY + angleDiff * directionY; angleZ = angleZ + angleDiff * directionZ; translate(width/2, height/2); rotateX(radians(angleX)); rotateY(radians(angleY)); rotateZ(radians(angleZ)); box(kickSize); kickSize = constrain(kickSize * 0.99, 150, 200); } float normalize(float value, float sMin, float sMax, float dMin, float dMax) { return constrain( (dMax - dMin) / (sMax - sMin) * ((value - sMin) + dMin), dMin, dMax); } void stop() { song.close(); super.stop(); }