0
我今天拿起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);
}
}
}
我的代碼在數學上是正確的,所以我想知道如果有什麼問題,我在做轉化的物理值的像素在屏幕上。
謝謝你嘗試回答。我期望在明亮條紋和黑暗條紋之間的過渡更加平滑,就像抖動的漸變,這將是預期的結果。不幸的是,這個問題不能縮小到特定的代碼行,但如果我猜測,我會把注意力集中在最後三行上。讓我用預期的結果更新我的問題。 – duci9y
@ duci9y當我說「線」時,我不是指「代碼行」 - 我的意思是單一的線條。在你的情況下,也許是一個單一的點? –
我不知道繪製一條線還是一個點會使問題變得明顯,因爲只有繪製更大的區域時纔會出現問題。我相信我的代碼是一個MCVE,嵌套for循環不會降低可讀性/可重複性,並且是程序運行所必需的。 – duci9y