UF中科赫雪花的第二个开关项抽出后的代码如下:
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 |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
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
elseif (x < 0)&&(x>-1/3)
z = z + 1/3
z = z*exp(-1i*pi/3)
z = 3*z - 1
elseif (x > 0)&&(x<1/3)
z = z - 1/3
z = z*exp(1i*pi/3)
z = 3*z + 1
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
}
第一个开关项的科氏雪花作出后,这第二个开关项,是顺理成章的事,估计难度不是很大了。 |