原代码内含开关项,鄙人将不是帖图的开关项赐除,其余几乎没动过,结果常老师尝试,好似成功了。UF原装代码如下:
hilbert-curve {
; Kerry Mitchell 15jul2001
;
; Draws a Hilbert curve in the #z plane and colors by the
; orbit's relationship to the curve. Only uses the last
; iterate. Allows you to change the locations of the 4
; sub-square centers, and the point where the curve enters
; and exits the block of 4 squares.
;
init:
float x=0.0
float y=0.0
float r=0.0
float rmin=1e20
float u=0.0
float v=0.0
float msb=0.0
t=(0,0)
int iter=0
int nlast=0
int n=0
int fac3=0
int fac4=0
int power4=0
zh=(0,0)
zh0=(0,0)
;
; set up endpoints for the lines
;
float h=@fourcorners
float ooh=1/h
float ooomh=1/(1-h)
float hoomh=h/(1-h)
z0a=@enterexit*h
z0b=flip(@enterexit*h)
x=real(@centerll)*h
y=imag(@centerll)*h
z1=x+flip(y)
x=real(@centerul)*h
y=imag(@centerul)*(1-h)+h
z2=x+flip(y)
x=real(@centerur)*(1-h)+h
y=imag(@centerur)*(1-h)+h
z3=x+flip(y)
x=real(@centerlr)*(1-h)+h
y=imag(@centerlr)*h
z4=x+flip(y)
z5=1+flip(@enterexit*h)
loop:
final:
iter=0
zh0=#z*0.25+(0.5,0.5)
zh=zh0
while(iter<@niter)
iter=iter+1
x=real(zh)
y=imag(zh)
;
; lower left sub-square: shrink, flip horizontally, rotate by -90 degrees
;
if((x<h)&&(y<h))
nlast=3
u=ooh*y
v=ooh*x
;
; upper left sub-square: just shrink
;
elseif((x<h)&&(y>=h))
nlast=2
u=ooh*x
v=ooomh*y-hoomh
;
; upper right sub-square: shrink & flip horizontally
;
elseif((x>=h)&&(y>=h))
nlast=1
u=ooomh-ooomh*x
v=ooomh*y-hoomh
;
; lower right sub-square: shrink, rotate by 90 degrees
;
elseif((x>=h)&&(y<h))
nlast=4
u=ooh*y
v=ooomh-ooomh*x
else
nlast=-1
u=x
v=y
endif
zh=u+flip(v)
msb=(msb+nlast-1)/4
n=n*4+nlast-1
endwhile
if(n<0)
#solid=true
else
if(@colorby==1) ; least significant bit
#index=n/(4^@niter)
elseif(@colorby==2) ; most significat bit
#index=msb
elseif(@colorby==3) ; distance from initial z
#index=cabs(zh-zh0)
elseif(@colorby==4) ; angle from initial z
r=atan2(zh-zh0)/#pi
if(r<0.0)
r=r+2
endif
#index=r/2
else ; distance to curve
;
; determine how to start line 0-1
;
z0=z0a
iter=0
fac3=2
fac4=1
power4=4
while(iter<@niter)
iter=iter+1
if(iter%2==1)
if(n%power4==fac3)
z0=z0b
endif
else
if(n%power4==fac3)
z0=z0a
endif
endif
power4=4*power4
fac4=4*fac4
fac3=fac3+2*fac4
endwhile
;
; line from enter to lower left sub-square
;
t=(zh-z0)/(z1-z0)
x=real(t)
y=imag(t)
if(x<0.0)
r=sqr(x)+sqr(y)
elseif(x>1.0)
r=sqr(x-1.0)+sqr(y)
else
r=sqr(y)
endif
r=sqrt(r)*cabs(z1-z0)
if(r<rmin)
rmin=r
endif
;
; line from lower left to upper left sub-squares
;
t=(zh-z1)/(z2-z1)
x=real(t)
y=imag(t)
if(x<0.0)
r=sqr(x)+sqr(y)
elseif(x>1.0)
r=sqr(x-1.0)+sqr(y)
else
r=sqr(y)
endif
r=sqrt(r)*cabs(z2-z1)
if(r<rmin)
rmin=r
endif
;
; line from upper left to upper right sub-squares
;
t=(zh-z2)/(z3-z2)
x=real(t)
y=imag(t)
if(x<0.0)
r=sqr(x)+sqr(y)
elseif(x>1.0)
r=sqr(x-1.0)+sqr(y)
else
r=sqr(y)
endif
r=sqrt(r)*cabs(z3-z2)
if(r<rmin)
rmin=r
endif
;
; line from upper right to lower right sub-squares
;
t=(zh-z3)/(z4-z3)
x=real(t)
y=imag(t)
if(x<0.0)
r=sqr(x)+sqr(y)
elseif(x>1.0)
r=sqr(x-1.0)+sqr(y)
else
r=sqr(y)
endif
r=sqrt(r)*cabs(z4-z3)
if(r<rmin)
rmin=r
endif
;
; line from lower right sub-square to exit
;
t=(zh-z4)/(z5-z4)
x=real(t)
y=imag(t)
if(x<0.0)
r=sqr(x)+sqr(y)
elseif(x>1.0)
r=sqr(x-1.0)+sqr(y)
else
r=sqr(y)
endif
r=sqrt(r)*cabs(z5-z4)
if(r<rmin)
rmin=r
endif
;
#index=rmin
endif
endif
default:
title="Hilbert curve"
param centerll
caption="lower left center"
default=(0.5,0.5)
hint="Center of the lower left sub-square. Make both coordinates \
between 0 & 1; use (0.5,0.5) for standard Hilbert curve."
endparam
param centerul
caption="upper left center"
default=(0.5,0.5)
hint="Center of the upper left sub-square. Make both coordinates \
between 0 & 1; use (0.5,0.5) for standard Hilbert curve."
endparam
param centerur
caption="upper right center"
default=(0.5,0.5)
hint="Center of the upper right sub-square. Make both coordinates \
between 0 & 1; use (0.5,0.5) for standard Hilbert curve."
endparam
param centerlr
caption="lower right center"
default=(0.5,0.5)
hint="Center of the lower right sub-square. Make both coordinates \
between 0 & 1; use (0.5,0.5) for standard Hilbert curve."
endparam
param enterexit
caption="enter/exit"
default=0.5
min=0.0
max=1.0
hint="Where the curve enters and exits the block of 4 sub-squares. \
Between 0 & 1; use 0.5 for standard Hilbert curve."
endparam
param fourcorners
caption="4 corners"
default=0.5
hint="Where the 4 corners meet. Between 0 & 1; use 0.5 for standard \
Hilbert curve."
endparam
param niter
caption="iterations"
default=0
min=0
endparam
param colorby
caption="color by"
default=0
enum="distance" "last = lsb" "last = msb" "distance from z" "angle from z"
endparam
}
|