1
我有一個繪製了一條基於音樂播放的音量上的橢圓形,其幅度JS腳本:JavaScript函數的draw()形狀像
var song, analyzer;
function preload() {
song = loadSound('sounds/masterflash.mp3');
}
function setup() {
createCanvas(250, 250);
song.loop();
// create a new Amplitude analyzer
analyzer = new p5.Amplitude();
// Patch the input to an volume analyzer
analyzer.setInput(song);
}
function draw() {
background(0, 0, 0, 0)
// Get the average (root mean square) amplitude
var rms = analyzer.getLevel();
fill(0, 0, 0, 20);
stroke(255, 255, 255);
// Draw an ellipse with size based on volume
ellipse(width/3, height/3, 10+rms*200, 10+rms*200);
}
你可以看到它做什麼這裏https://p5js.org/examples/sound-measuring-amplitude.html樣本
你可以看到它創建橢圓的最後一個代碼。我怎麼能做同樣的事情,但不是繪製橢圓,而是加載一個圓形的.png圖像?
它的工作,但現在的動畫集中在左上角,而不是中間。你可以通過播放按鈕在這裏看到它vtxfactory.org – Rui
@Rui我無法找到你在該網站上的問題,但無論如何你可以調整圖像的位置。只要看看參考如何做到這一點https://p5js.org/reference/#/p5/image –