【发布时间】:2016-03-03 09:19:44
【问题描述】:
我今天学习了Processing,并编写了一个程序来生成双缝干涉图案。在稍微调整一下这些值之后,它就可以工作了,但是生成的模式比其他一些程序中可能的模式更模糊。截图如下:
如您所见,边缘并不像我认为的那样光滑。我希望它们看起来像 this 或 this。
这是我的代码:
// All quantities in mm
float slit_separation = 0.005;
float screen_dist = 50;
float wavelength = 5e-4f;
PVector slit1, slit2;
float scale = 1e+1f;
void setup() {
size(500, 500);
colorMode(HSB, 360, 100, 1);
noLoop();
background(255);
slit_separation *= scale;
screen_dist *= scale;
wavelength *= scale;
slit1 = new PVector(-slit_separation / 2, 0, -screen_dist);
slit2 = new PVector(slit_separation / 2, 0, -screen_dist);
}
void draw() {
translate(width / 2, height / 2);
for (float x = -width / 2; x < width / 2; x++) {
for (float y = -height / 2; y < height / 2; y++) {
PVector pos = new PVector(x, y, 0);
float path_diff = abs(PVector.sub(slit1, pos).mag() - PVector.sub(slit2, pos).mag());
float parameter = map(path_diff % wavelength, 0, wavelength, 0, 2 * PI);
stroke(100, 100, pow(cos(parameter), 2));
point(x, y);
}
}
}
我的代码在数学上是正确的,所以我想知道我在将物理值转换为屏幕上的像素时是否有问题。
【问题讨论】:
标签: graphics drawing processing