xxxxxxxxxx
106
//music — Inochi no Namae by Joe Hisaishi
let NY;
let Mos;
let song;
let amp;
let fft;
//let notAnimating = true;
function preload() {
NY = loadImage("NY.jpg");
Mos = loadImage("MOS.jpg");
song = loadSound ("song.mp3");
}
function setup() {
createCanvas(400, 400);
NY.resize(400,400);
background(Mos);
song.play();
amp = new p5.Amplitude();
fft = new p5.FFT();
fft.setInput(song);
}
function draw() {
if (mouseIsPressed) {
let waveArray = fft.waveform();
beginShape();
noFill();
stroke(255);
for ( let i = 0; i < waveArray.length; i++) {
let x = map(i, 0, waveArray.length, 55, 350);
let y = map(waveArray[i], -1,1, -height/2, height/2);
vertex(x,y+ height/2);
}
endShape();
}
// swapImage(NY);
// notAnimating = false;
// }else{
// if(!notAnimating){
// swapImage(Mos);
// }
// }
let level = amp.getLevel();
let level2 = amp.getLevel();
level = map(level, 0, 0.3, 0, 50);
stroke(0);
fill(0);
ellipse(100, 130, level);
for (i = 0; i < 10; i++) {
let x = random (55, 350);
let y = random (166, 335);
let c = NY.get(x,y);
stroke(c);
line(x,y, x, y);
noStroke();
fill(c);
ellipse (x, y, 2, 2);
}
// function swapImage (destination) {
// for (i = 0; i < 1000; i++) {
// let x = random (width);
// let y = random (height);
// let c = destination.get(x,y);
// let a = random (1, 7);
// let b = random (1, 8);
// let r = random (1, 10);
// noStroke();
// fill(c);
// ellipse (x, y, 5, 5);
// }
}