音量で動きを変えるジェネラティブアート
import ddf.minim.*; import ddf.minim.analysis.*; import ddf.minim.effects.*; import ddf.minim.signals.*; import ddf.minim.spi.*; import ddf.minim.ugens.*; int x = 50; int y = 50; float xnoise = random(1); float ynoise = random(1); int count = 0; int sx, sy; Minim minim; AudioPlayer music; void setup() { size(300, 300); stroke(random(255), random(255), random(255), 30); sx = width/2; sy = height/2; minim = new Minim(this); String s = "music.mp3"; music = minim.loadFile(s, 2048); //loadFile("音声ファイル", バッファサイズ) music.play(); background(0); } void draw() { float left = 0; float right = 0; for (int i = 0; i < music.bufferSize() - 1; i++) { left += abs(music.left.get(i)); right += abs(music.right.get(i)); } left = left/music.bufferSize()/50; right = right/music.bufferSize()/50; println(left + " " + right ); stroke(random(255), random(255), random(255), 100); x = (int)(noise(xnoise) * width); y = (int)(noise(ynoise) * height); line(sx, sy, x, y); xnoise += left; ynoise += right; fill(0, 5); rect(0, 0, width, height); }
Copy