- UID
- 7
- 帖子
- 2888
- 精华
- 10
- 积分
- 2836
|
64# xiaongxp
HilbertCurve(BOTH) {
; By Samuel Monnier, 2.9.00
init:
z = 0
int i = 0
int ttype = 0
float d = -1e20
loop:
final:
z = #z/2
z = abs(z) - (.5,.5)
while i < @niter
i = i + 1
if ttype == 0
if real(z) < 0 && imag(z) < 0
z = 2*z + (.5,.5)
z = -conj(z)
elseif real(z) > 0 && imag(z) < 0
z = 2*z + (-.5,.5)
z = 1i*z
elseif real(z) > 0 && imag(z) > 0
z = 2*z + (-.5,-.5)
z = 1i*conj(z)
elseif real(z) < 0 && imag(z) > 0
z = 2*z + (.5,-.5)
ttype = 1
endif
else
if real(z) < 0 && imag(z) < 0
z = 2*z + (.5,.5)
z = 1i*z
ttype = 0
elseif real(z) > 0 && imag(z) < 0
z = 2*z + (-.5,.5)
z = -1i*conj(z)
ttype = 0
elseif real(z) > 0 && imag(z) > 0
z = 2*z + (-.5,-.5)
ttype = 0
elseif real(z) < 0 && imag(z) > 0
z = 2*z + (.5,-.5)
z = -conj(z)
ttype = 0
endif
endif
endwhile
if @style == 0
z = z + (1,1)
if ttype == 0
if abs(real(z))-1 > d
d = abs(real(z))-1
endif
if abs(imag(z))-1 > d
d = abs(imag(z))-1
endif
else
d = imag(z)-1
endif
elseif @style == 1 || @style == 2
if ttype == 0
d = cabs(z+(.5,.5))-.5
else
if @style == 1
d = imag(z)
else
d = imag(z) - (real(z)^2-.25)^2*3
endif
endif
elseif @style == 3
if ttype == 0
z = z + (.5,.5)
d = abs(real(z)) + abs(imag(z)) - .5
else
;d = imag(z)-.5
d = abs(real(z)) - imag(z) - .5
endif
endif
#index = abs(d)^@power
default:
title = "Hilbert Curve"
helpfile = "sam-help/hilbert.htm"
param style
caption = "Style"
default = 0
enum = "Square" "Round I" "Round II" "Diagonal"
endparam
param power
caption = "Thickness"
default = .1
endparam
param niter
caption = "Number of Iterations"
default = 4
endparam
} |
|