如何控制花动画?
let angle = 0
let mic;
let fft;
function setup() {
createCanvas(400, 400);
mic = new p5.AudioIn(); //AUDIO SETTING
mic.start();
fft = new p5.FFT();
fft.setInput(mic);
}
function draw() {
background(220);
petals();
noStroke();
fill(255);
ellipse(200, 200, 100, 100); // the center of flower
function petals() {
push()
translate(200, 200); // flower leaves
rotate(angle);
noStroke();
const colors = ['magenta','red', 'orange','#7fff00','#0f0','#0ff','blue','#bf49ff'];
let waveform = fft.waveform();
for (let i=0; i<8; i++) {
let y = 100 - waveform[i]*100; //i want those flower leaves to rotate responds to mic
let color = colors[i];
fill(color)
ellipse(100, 0, 200, 60)
rotate(radians(45));
angle = angle +0.003
}
pop()
}
}
//我希望我的叶子能够响应麦克风实时声音输入的响应。我认为我应该使用PFF,但是...它不起作用。请帮助我TT
let angle = 0
let mic;
let fft;
function setup() {
createCanvas(400, 400);
mic = new p5.AudioIn(); //AUDIO SETTING
mic.start();
fft = new p5.FFT();
fft.setInput(mic);
}
function draw() {
background(220);
petals();
noStroke();
fill(255);
ellipse(200, 200, 100, 100); // the center of flower
function petals() {
push()
translate(200, 200); // flower leaves
rotate(angle);
noStroke();
const colors = ['magenta','red', 'orange','#7fff00','#0f0','#0ff','blue','#bf49ff'];
let waveform = fft.waveform();
for (let i=0; i<8; i++) {
let y = 100 - waveform[i]*100; //i want those flower leaves to rotate responds to mic
let color = colors[i];
fill(color)
ellipse(100, 0, 200, 60)
rotate(radians(45));
angle = angle +0.003
}
pop()
}
}
//I want my leaves to rotate in response to the loudness of real-time sound input from the microphone. I think I should use pff but... it doesn't work. Please help me TT
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下是一种设计,其伪造的计算将FFT输出转换为旋转速率。 (实际麦克风输入不会在片段中运行)
重点是:(1)演示如何旋转图形,(b)显示如何解开FFT数学和图形。
编辑
我第一次尝试了P5声音库。有些事情要注意:(1)由于摘要无法访问客户端麦克风,因此它在堆栈溢出片段中无法使用。 (2)请记住,在下面的HTML中导入P5声音附加组件,(3)如果您只想总幅度,则不需要FFT,只需从P5 MIC获得MIC级别即可。 (4)我构成了一个在本地机器上运行正常的功能,剪裁低幅度和高振幅(尽管1.0可能是最大输出的最大输出)。
Below is a design with a fake calculation transforming FFT output to a rotational rate. (real mic input won't run in snippets)
The point is to: (1) demonstrate how to rotate the drawing, and (b) show how untangle the FFT math and the graphics.
EDIT
I tried the p5 sound library for the first time. Some things to note: (1) it won't work in stack overflow snippets, since the snippet can't access the client mic. (2) remember to import the p5 sound add-on, shown in the html below, (3) if you just want total amplitude, there's no need for FFT, just get the mic level from the p5 mic. (4) I made up a function that works ok on my local machine, clipping the low and high amplitudes (though 1.0 is probably the max output by default).