xxxxxxxxxx
93
var slider
var song
var button
var amp
var FFT
var songHistory = [];
var notes=[];
function preload() {
song = loadSound("Not Your Average Thug_01.mp3")
}
function setup() {
createCanvas(windowWidth, windowHeight);
angleMode(DEGREES)
button = createButton("play")
button.mousePressed(togglePlaying)
button.position(width / 2, height / 2 + 230)
slider = createSlider(0, 1, 0.5, 0.01)
slider.position(width / 2 - 150, height / 2 + 230);
amp = new p5.Amplitude();
FFT = new p5.FFT(0.9);
}
function togglePlaying() {
if (!song.isPlaying()) {
song.play();
button.html("pause");
} else {
song.pause();
button.html("play");
}
}
function draw() {
background(72, 61, 139);
disc(width / 2, height / 2);
textSize(15);
text('volume', width / 2 - 200, height / 2 + 244);
wave();
}
function disc(x, y) {
var spectrum = FFT.analyze();
push();
translate(x, y);
noFill();
for (var i = 0; i < spectrum.length; i++) {
var mycolor = map(i, 0, spectrum.length, 0, 256);
var angle = map(i, 0, spectrum.length, 0, 720);
colorMode(HSB, 256);
var r = map(spectrum[i], 0, 180, 80, 180);
var linex = r * cos(angle);
var liney = r * sin(angle);
line(0, 0, linex, liney);
}
var vol = amp.getLevel()
var size = map(vol, 0, 1, 40, 250);
colorMode(HSB, 256);
fill(random(0, 80), random(0, 80), 256);
ellipse(0, 0, vol * 200 + 70, vol * 200 + 70);
pop()
}
function wave() {
push();
translate(width / 2, height / 2);
song.setVolume(slider.value());
var vol = amp.getLevel();
songHistory.push(vol);
colorMode(HSB, 256);
stroke(random(0, 70), random(0, 70), 256);
noFill();
beginShape();
strokeWeight(3);
for (var i = 0; i < 360; i++) {
var r = map(songHistory[i], 0, 1, 150, 520);
var x = r * cos(i);
var y = r * sin(i);
vertex(x, y);
}
endShape();
if (songHistory.length > 360) {
songHistory.splice(0, 1);
}
pop()
}