Last active
September 20, 2015 16:21
-
-
Save t-kashima/6a355a4467f6b29aa7e2 to your computer and use it in GitHub Desktop.
Sound Visualizer
This file contains hidden or 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.spi.*; | |
import ddf.minim.signals.*; | |
import ddf.minim.*; | |
import ddf.minim.analysis.*; | |
import ddf.minim.ugens.*; | |
import ddf.minim.effects.*; | |
private Minim mMinim; | |
private AudioPlayer mPlayer; | |
private static final int BASE_RADIUS = 256; | |
void setup() { | |
size(400, 400); | |
frameRate(60); | |
this.mMinim = new Minim(this); | |
mPlayer = mMinim.loadFile("sample.mp3", 512); | |
mPlayer.play(); | |
} | |
void draw() { | |
// background color | |
background(0); | |
// Draw points in music player | |
float x, y; | |
float radius = BASE_RADIUS + random(256) - 128; | |
for (int i = 0; i < mPlayer.left.size() - 1; i++) { | |
x = getWidth() / 2 + cos(i) * radius * mPlayer.left.get(i); | |
y = getHeight() / 2 + sin(i) * radius * mPlayer.right.get(i); | |
// stroke color | |
stroke(random(256), random(256), random(256)); | |
// stroke weight | |
strokeWeight(random(10) + 1); | |
// Draw a point | |
point(x, y); | |
} | |
} | |
void stop() { | |
mPlayer.close(); | |
mMinim.stop(); | |
super.stop(); | |
} |
Author
t-kashima
commented
Jul 29, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment