【发布时间】:2020-06-26 23:05:13
【问题描述】:
我正在使用处理 3.5.3,我正在使用 beginShape、curveVertex、endShape 绘制曲线。我的窗口是 1200 像素宽,我正在绘制一系列具有均匀间隔 x 值的点。 x 值之间的间距为 1200/2000,小于一个像素。我知道,这是对curveVertex 的严重滥用,但它确实有效。每一帧都需要十秒钟的时间来渲染(因为我使用的数学,而不是因为处理),我将每一帧保存为.png。
问题是我在应该有曲线的地方得到了这些直线补丁。看起来大范围的 x 值被跳过了。我知道它会跳过多个顶点,因为直接的补丁跨越多个 x 像素,最坏的情况可能是五十个左右。大多数帧都很好,但是会有一个帧丢失了巨大的补丁。知道是什么原因造成的吗?
编辑:这是代码和一些显示问题的框架。最相关的部分在draw()。
float r; // parameter for recurence
float dr; // change in r per frame
int lod = 2000; // level of detail for curves
int k; // recurrence depth
float yscale = 16; // scale down the y-axis by this factor
// transforms from [0, 1] to screen coordinates
void vertex(float x, float y) {
curveVertex(x * width, (1 - y) * height);
}
void setup() {
size(1200, 800);
background(0);
stroke(255);
noFill();
r = 3.7;
k = 30;
dr = 0.0005;
}
void draw() {
background(0);
// animate r
r += dr;
if (r >= 4) {
exit();
}
// draw the pdf of Xk
stroke(255);
beginShape();
vertex(0, fn(0, k) / yscale);
for (int i = 0; i <= lod; i++) {
float x = i / (float)lod;
vertex(x, fn(x, k) / yscale);
}
vertex(1, fn(1, k) / yscale);
endShape();
textSize(24);
text(String.format("r = %.4f", r), 24, 24);
saveFrame("output/frame_#####.png");
}
// pdf of Xn+1 = r*Xn*(1-Xn), where X0 is uniform
float fn(float x, int n) {
if (n == 0) {
return 1;
}
else if (x > r/4) {
return 0;
}
else {
float d = sqrt(1 - 4/r*x);
return (fn(0.5 + 0.5*d, n-1) + fn(0.5 - 0.5*d, n-1)) / (r*d);
}
}
【问题讨论】:
-
邮政编码和图片输出。
-
@micycle 已发布,谢谢
标签: processing curve