Last active
June 5, 2016 21:44
-
-
Save mgm000/6544e1fbdd4f142d1af38b9c7e93a02d to your computer and use it in GitHub Desktop.
Moving Circle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ddf.minim.*; | |
import ddf.minim.analysis.*; | |
Minim minim; | |
AudioPlayer player; | |
AudioMetaData meta; | |
BeatDetect beat; | |
int r = 200; | |
float rad = 70; | |
void setup() | |
{ | |
size(800, 800); | |
//size(400, 400); | |
minim = new Minim(this); | |
player = minim.loadFile("song.mp3"); | |
meta = player.getMetaData(); | |
beat = new BeatDetect(); | |
player.loop(); | |
//player.play(); | |
background(-1); | |
noCursor(); | |
} | |
void draw() | |
{ | |
float t = map(mouseX, 0, width, 0, 1); | |
beat.detect(player.mix); | |
fill(#000000); | |
noStroke(); | |
rect(0, 0, width, height); | |
translate(width/2, height/2); | |
fill(#d4bdc5); | |
fill(-1, 5); | |
if (beat.isOnset()) rad = rad*0.9; | |
else rad = 40; | |
stroke(1, 0); | |
int bsize = player.bufferSize(); | |
for (int i = 0; i < bsize - 1; i+=5) | |
{ | |
float x = (r)*cos(i*2*PI/bsize); | |
float y = (r)*sin(i*2*PI/bsize); | |
float x2 = (r + player.left.get(i)*100)*cos(i*2*PI/bsize); | |
float y2 = (r + player.left.get(i)*100)*sin(i*2*PI/bsize); | |
line(x, y, x2, y2); | |
} | |
beginShape(); | |
noFill(); | |
stroke(-1, 30); | |
for (int i = 0; i < bsize; i+=30) | |
{ | |
float x2 = (r + player.left.get(i)*100)*cos(i*2*PI/bsize); | |
float y2 = (r + player.left.get(i)*100)*sin(i*2*PI/bsize); | |
vertex(x2, y2); | |
pushStyle(); | |
stroke(-1); | |
strokeWeight(1); | |
point(x2, y2); | |
popStyle(); | |
} | |
endShape(); | |
if (flag) showMeta(); | |
} | |
void showMeta() { | |
int time = meta.length(); | |
textSize(30); | |
textAlign(CENTER); | |
text( (int)(time/1000-millis()/1000)/60 + ":"+ (time/1000-millis()/1000)%60, -7, 21); | |
} | |
boolean flag =false; | |
void mousePressed() { | |
if (dist(mouseX, mouseY, width/2, height/2)<150) flag =!flag; | |
} | |
// | |
void keyPressed() { | |
if (key==' ')exit(); | |
if (key=='s')saveFrame("###.jpeg"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment