[英]Add interactivity with microphone input
I want to add interactivity to the soundwaves visual so that when it interacts with the microphone, it moves with the amplitude...我想为声波视觉添加交互性,以便当它与麦克风交互时,它会随着幅度移动......
Here is a link to the sketch:这是草图的链接:
https://www.openprocessing.org/sketch/950912 https://www.openprocessing.org/sketch/950912
Code here:代码在这里:
int ranges = 100;
void setup() {
fullScreen();
background(0);
}
void draw() {
background(0);
noFill();
strokeWeight(1);
for (int i = 1; i < ranges; i++) {
float paint = map(i, 0, ranges, 1, 125);
stroke(paint);
beginShape();
for (int x = -100; x < width + 11; x += 20) {
float n = noise(x * 0.001, i * 0.01, frameCount * 0.01);
float y = map(n, 0.1, 1, 10, height);
vertex(x, y);
}
endShape();
}
}
The code you have is for Processing and you have to convert it for p5.您拥有的代码用于处理,您必须将其转换为 p5。
var sketch = function (p) { with(p) { var ranges = 100; p.setup = function() { //fullScreen(); background(0); }; p.draw = function() { background(0); noFill(); strokeWeight(1); for (var i = 1; i < ranges; i++) { var paint = map(i, 0, ranges, 1, 125); stroke(paint); beginShape(); for (var x = -100; x < width + 11; x += 20) { var n = noise(x * 0.001, i * 0.01, frameCount * 0.01); var y = map(n, 0.1, 1, 10, height); vertex(x, y); } endShape(); } }; } }; let node = document.createElement('div'); window.document.getElementById('p5-container').appendChild(node); new p5(sketch, node);
body { background-color:#efefef; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.1.9/p5.js"></script> <div id="p5-container"></div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.