xxxxxxxxxx
46
function preload() {
sound = loadSound('./20201005.mp3')
}
function setup() {
canvas = createCanvas(600, 600);
canvas.mousePressed(onClickPlay)
amplitude = new p5.Amplitude();
colorMode(HSB)
rowVolumeColor = color(100, 255, 255)
highVolumeColor = color(0, 100, 100)
}
function draw() {
background(0, 80);
const level = amplitude.getLevel()
const peak = sound.getPeaks(1)
text(level, 100, 100)
textSize(32)
noStroke()
fill(isSpecifiedMax(level, peak))
ellipse(width / 2, height / 2, level * width)
push()
fill(100, 100, level*100)
ellipse(width / 2, height / 2, level * width / 3)
pop()
}
function onClickPlay () {
if(sound.isPlaying()) {
sound.stop()
return
}
sound.play()
}
function isSpecifiedMax (level, peak) {
if(level > peak - 0.2) {
return highVolumeColor
} else {
return rowVolumeColor
}
}