xxxxxxxxxx
42
let colors;
let newColor = false;
let randomColor;
let mic;
let rotation = 0;
let x;
let y;
function setup() {
createCanvas(600, 600);
background(40);
colors = [
color(255,0,193, 100),
color(150,0,255, 100),
color(73,0,255, 100),
color(0,184,255, 100),
color(0,255,249, 100)
];
mic = new p5.AudioIn();
mic.start();
}
function draw() {
const micLevel = mic.getLevel();
if (micLevel > 0.1) {
if (!newColor) {
x = random(0, width);
y = map(micLevel, 0, 0.5, height, 0);
randomColor = colors[int(random(0, colors.length))];
newColor = true;
}
translate(x, y);
// const rotation = map(mouseX+mouseY, 0, height*2, 0, TWO_PI);
rotation += 0.1*noise(x, y);
rotate(rotation);
stroke(randomColor);
const lineLength = random(100, 400);
line(-lineLength/2, 0, lineLength/2, 0);
} else {
newColor = false;
}
}