xxxxxxxxxx
var constellations = [];
var movers = [];
var graphics;
var startOffset=0;
var xpos = 30;
var dir = 1;
var speed = 2;
var m;
var mic, fft;
function setup() {
createCanvas(800, 960);
//this draws to the invisible canvas in the computer memory
//this lets you ;leave a trail' and have a background color
graphics = createGraphics (800,400)
// graphics.background('rgba(12, 56, 95,0.05)');
// graphics.background('#F9DA78');
graphics.background('rgba(12, 56, 95, .95)');
//using p5 audio to instantiate an instance of audio in
mic = new p5.AudioIn();
//start taking audio data from the computer's built in mic
mic.start();
//create an instance of p5's fft method to visualize audio
fft = new p5.FFT();
//set the mic-from audioIn to be the input for the fft visualizer
fft.setInput(mic);
//next I want to tie the fft input to the behavior of the balls
fill('#EF6E73');
for (var i = 0; i < 20; i++) {
// fill('rgba(239, 110, 115, 1)');
movers[i] = new Mover(random(0.1, 5), 0, 0);
// constellations[i] = new Constellation(random(0.1, 5), 0, 0);
}
}
function draw() {
background('rgba(39, 35, 62, .01)');
image(graphics, 0, 0)
graphics.fill(0, 255, 0, 100)
//p5 method beginShape following the following logic
// beginShape();
// vertex(30, 20);
// vertex(85, 20);
// vertex(85, 75);
// vertex(30, 75);
// endShape(CLOSE);
//set up the fft analyzer
var spectrum = fft.analyze();
console.log(spectrum)
fill('rgba(12, 56, 95, .05)')
beginShape();
//draw out the fft spectrum as visualization
for (i = 0; i<spectrum.length; i++) {
//maping spectrum i from a value between 0 and 225 to a value between height and 0
//where is the height value coming from
vertex(i, map(spectrum[i], 0, 255, height, 0) );
}
endShape();
for (var i = 0; i < movers.length; i++) {
var wind = createVector(0.01, 0);
var gravity = createVector(0, 0.1);
movers[i].applyForce(wind);
movers[i].applyForce(gravity);
movers[i].update();
movers[i].display();
movers[i].checkEdges();
}
// for (var i = 0; i <constellations.length; i++) {
// var wind = createVector(0.01, 0);
// var gravity = createVector(0, 0.1);
// constellations[i].applyForce(wind);
// constellations[i].applyForce(gravity);
// constellations[i].update();
// constellations[i].display();
// constellations[i].checkEdges();
// }
}