xxxxxxxxxx
54
// Ref 17.4 Amplitude Analysis + Point to text
let song;
let button;
let jumpButton;
let font;
let fontSize = 200;
let word = ["bc"];
function preload() {
font = loadFont("soundwave.ttf");
}
function setup() {
createCanvas(900, 600);
song = loadSound("San_Holo_-_We_Rise.mp3", loaded);
amp = new p5.Amplitude();
background(0);
noStroke();
points = font.textToPoints(word[0], 0, 0, fontSize);
index = 0;
}
function loaded() {
button = createButton("play");
button.mousePressed(togglePlaying);
console.log(loaded);
}
function togglePlaying() {
if (!song.isPlaying()) {
song.play();
song.setVolume(0.3);
button.html("pause");
} else {
song.pause();
button.html("play");
}
}
function draw() {
background(51);
noStroke();
let vol = amp.getLevel();
let diam = map(vol, 0, 0.3, 50, 300);
translate(200, 400);
for (let pt of points) {
fill(100 - diam, 150, 255 - diam);
rect(pt.x, pt.y, 2, -diam);
}
}