Skip to content

Instantly share code, notes, and snippets.

@t-kashima
Last active September 20, 2015 16:21
Show Gist options
  • Save t-kashima/6a355a4467f6b29aa7e2 to your computer and use it in GitHub Desktop.
Save t-kashima/6a355a4467f6b29aa7e2 to your computer and use it in GitHub Desktop.
Sound Visualizer
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();
}
@t-kashima
Copy link
Author

sample

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment