Skip to content

Instantly share code, notes, and snippets.

@kasthor
Created March 27, 2021 01:39
Show Gist options
  • Save kasthor/096a6a3893b9bd653b3014822ba5d185 to your computer and use it in GitHub Desktop.
Save kasthor/096a6a3893b9bd653b3014822ba5d185 to your computer and use it in GitHub Desktop.
Paint with Music
let mic, timeline, minLevel, maxLevel;
function setupAudio(){
userStartAudio();
mic = new p5.AudioIn();
mic.start();
}
function setup() {
createCanvas(windowWidth, windowHeight);
timeline = [];
setupAudio();
background(30);
minLevel = 0
maxLevel = 0;
}
function draw(){
colorMode(RGB)
background(30, 1);
noStroke();
colorMode(HSB)
let micLevel = mic.getLevel();
maxLevel = max(maxLevel, micLevel)
minLevel = min(minLevel, micLevel)
fill(map(micLevel, minLevel, maxLevel, 0, 100), 100,100)
circle(mouseX, mouseY, micLevel * height * 10)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment