xxxxxxxxxx
var theshape = []; // this is an empty array where we're gonna store stuff
var temp = {};
var themic;
function setup() {
createCanvas(windowWidth, windowHeight);
background(100);
themic = new p5.AudioIn();
themic.start();
}
function draw() {
background(128, 0, 0);
fill(0, 100, 100, 50);
stroke(255, 255, 0);
strokeWeight(5);
let amp = themic.getLevel()*100; // how loud am i?
beginShape(TRIANGLE_STRIP);
for(let i = 0;i<theshape.length;i++)
{
vertex(theshape[i].x, theshape[i].y);
ellipse(theshape[i].x, theshape[i].y, amp, amp);
theshape[i].x += theshape[i].v * cos(theshape[i].a);
theshape[i].y += theshape[i].v * sin(theshape[i].a);
}
endShape(CLOSE);
}
function mouseMoved()
{
console.log("MOVED!!!!");
}
function mouseDragged()
{
console.log("DRAGGED!!!!");
}
function mousePressed()
{
console.log("PRESSED!!!");
temp.x = mouseX;
temp.y = mouseY;
}
function mouseReleased()
{
console.log("RELEASED!!!!");
let m = {};
m.x = mouseX;
m.y = mouseY;
m.v = dist(m.x, m.y, temp.x, temp.y)/20.;
m.a = atan2((m.y-temp.y), (m.x-temp.x));
theshape.push(m);
}
function mouseClicked()
{
console.log("CLICKED!!!!");
}
function doubleClicked()
{
console.log("DOUBLECLICKED!!!!");
}
function keyTyped()
{
if(key==' ') theshape = []; // reinitialize an array
}