开关项3的代码整理如下:
KochCurve {
init:
z = #pixel
x = real(z)
y = imag(z)
sq3 = sqrt(3)
bool bail2 = false
bool bail = false
i = 0
loop:
i = i + 1
if i == 2
arg = atan2(z)
if (y + 1/sq3 > 0) && (sq3*x - y + 2/sq3 > 0) \
&& (sq3*x + y - 2/sq3 < 0)
bail = true
endif
if (-y + 1/sq3 > 0) && (sq3*x + y + 2/sq3 > 0) \
&& (sq3*x - y - 2/sq3 < 0)
bail = true
endif
if (arg > 5/6*pi) || (arg < -pi/2)
z = z*exp(1i*4/3*pi)
endif
if (arg < pi/6) && (arg > -pi/2)
z = z*exp(1i*2/3*pi)
endif
z = z - 1i*1/sq3
zz = z
z = #pixel
if |x| > 1 || x/sq3 + y - 2*sq3/3 > 0 \
|| x/sq3 + y + 2*sq3/3 < 0 || x/sq3 \
- y + 2*sq3/3 < 0 || x/sq3 - y - \
2*sq3/3 > 0
bail = true
endif
if (abs(arg) < pi/6)
z = z*exp(-1i*pi/2)
elseif (arg > pi/6) && (arg < pi/2)
z = z*exp(-1i*5*pi/6)
elseif (arg > pi/2) && (arg < 5*pi/6)
z = z*exp(1i*5*pi/6)
elseif (abs(arg) > 5*pi/6)
z = z*exp(1i*pi/2)
elseif (arg < -pi/6) && (arg > -pi/2)
z = z*exp(-1i*pi/6)
elseif (arg < -pi/2) && (arg > -5*pi/6)
z = z*exp(1i*pi/6)
endif
z = z + 1i
z = sq3*z
elseif i > 2
oldz = z
z = zz
zz = oldz
z = 3*z
x = real(z)
y = imag(z)
if (y > 0) && (sq3*x - y + sq3 > 0) \
&& (sq3*x + y - sq3 < 0)
bail2 = true
endif
z = z/3
x = real(z)
y = imag(z)
if x < -1/3
z = 3*z + 2
elseif x > 1/3
z = 3*z - 2
else
if x < 0
z = z + 1/3
z = z*exp(-1i*pi/3)
z = 3*z - 1
else
z = z - 1/3
z = z*exp(1i*pi/3)
z = 3*z + 1
endif
endif
endif
bailout:
bail == false && bail2 == false
default:
title = "Koch Curve"
helpfile = "sam-help/kochcurves.htm"
helptopic = "kcurve"
magn = 1.5
center = (0.0002,0)
maxiter = 50
}
我干了一两天,可能成了思维定式,一直查不出原因,我将图片及问题文件发上来,文件中的数据按代码顺序排列出,大家帮查查,究竟是那个判断出了问题。从扫出的图片看,只有两条边上的曲线正常,有几条边还没有。
开关顶3问题文件.gsp (45.27 KB)
|