循环整个 p5js 脚本
我想知道是否可以在 p5js Web 编辑器或 VS 代码中多次运行以下代码,并在每次运行时从预定义值数组中更改参数 a、b、A、B、H 并保存 PNG本地图像。我的目标是让脚本运行并生成各种参数不同的绘图。这是我的问题的简化版本,因此不可能在绘制循环中运行循环。有没有办法循环整个脚本?非常感谢。
//fixed
Sb = 0.3;
Vb = 1;
// noprotect
t = 0;
dt = 0.1 / 2;
t2=0
//want to vary
a = 0.03;
b = 0.04;
A = 20;
B = 20;
H = 0.15;
function setup() {
createCanvas(1000, 1000, WEBGL);
colorMode(HSB, 1);
console.log(width);
background(H, Sb, Vb);
}
function draw() {
for (i = 0; t < 200 * TAU; i++) {
W = A * sin(a * t) * B * sin(b * t );
strokeWeight(2);
point(t-width/2,W)
t += dt;
}
saveCanvas(join(['Im', 1], '_'), 'png')
noLoop()
}
I was wondering if it is possible to run the following code on the p5js web editor or within VS code multiple times and change the parameters a, b, A, B, H from an array of predefined values every time it runs and save the PNG image locally. My aim is to let the script run and generate a wide range of plots with these parameters varying. This is a simplified version of my problem so running the loop within the draw loop is not possible. Is there a way to loop the entire script? Many thanks in advance.
//fixed
Sb = 0.3;
Vb = 1;
// noprotect
t = 0;
dt = 0.1 / 2;
t2=0
//want to vary
a = 0.03;
b = 0.04;
A = 20;
B = 20;
H = 0.15;
function setup() {
createCanvas(1000, 1000, WEBGL);
colorMode(HSB, 1);
console.log(width);
background(H, Sb, Vb);
}
function draw() {
for (i = 0; t < 200 * TAU; i++) {
W = A * sin(a * t) * B * sin(b * t );
strokeWeight(2);
point(t-width/2,W)
t += dt;
}
saveCanvas(join(['Im', 1], '_'), 'png')
noLoop()
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要循环整个脚本,只需执行以下操作:
You don't need to loop the whole script, do something like this: