UF中的KochCurve代码,内含三个开关项,代码太长,解读困难,为降低难度,我将其代码精简为只整一个开关项,此精简后的代码在UF中运行后无误,我今晚试做了一下,结果不成功,扫出的图怪得很,大家帮忙看看,能否作成。榕坚兄有空时,看看,如何用GSP实现。
KochCurve {
init:
z = #pixel
x = real(z)
y = imag(z)
sq3 = sqrt(3)
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
elseif i > 2
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 Curve1"
helpfile = "sam-help/kochcurves.htm"
helptopic = "kcurve"
magn = 1.5
center = (0.0002,0)
maxiter = 50
} |