Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var sound;
var slider1;
var toggle;
var center1;
var center2;
var soundColor;
var d;
function setup() {
createCanvas(500, 500);
smooth();
slider1 = createSlider(.5, 15, 7);
slider1.position(200, 15);
var button1 = createButton('wave style');
button1.mousePressed(toggle);
button1.position(19, 19);
sound = new p5.AudioIn();
sound.start();
fft = new p5.FFT(1.0, 256);
fft.setInput(sound);
}
function draw() {
background(30, 0, 40);
var slideVal1 = slider1.value();
sound.amp(slideVal1);
waveformer(20, 120, 255);
waveformer(80, 255, 80);
waveformer(255, 40, 255);
}
function toggle() {
if (center1 === undefined) {
center1 = 250;
center2 = 250;
} else {
center1 = undefined;
center2 = undefined;
}
}
function waveformer(r, b, g) {
var waveform = fft.waveform();
noFill();
beginShape();
stroke(r, b, g);
strokeWeight(1);
for (var i = 0; i < waveform.length; i++) {
var x = map(i, 0, waveform.length, 0, width);
var y = map(waveform[i], -1, 1, 0, height);
vertex(x, y);
vertex(x + 2, y + 2);
vertex(center1, center2);
}
endShape();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.