bezier-curve {
; Kerry Mitchell 08apr00
;
; Colors by the orbit's closest approach to a user-defined Bezier curve.
; The curve is determined by specifying beginning and ending anchor points,
; through which the curve passes, and 2 control points, which influence the
; shape of the curve.
;
init:
float x0=real(@z0)
float y0=imag(@z0)
float x1=real(@z1)
float y1=imag(@z1)
float x2=real(@z2)
float y2=imag(@z2)
float x3=real(@z3)
float y3=imag(@z3)
float cx=3*(x1-x0)
float bx=3*(x2-x1)-cx
float ax=x3-x0-cx-bx
float cy=3*(y1-y0)
float by=3*(y2-y1)-cy
float ay=y3-y0-cy-by
float t=0.0
float r=0.0
float x=0.0
float y=0.0
float u=0.0
float v=0.0
int iter=0
float rmin=1.0e20
int itermin=0
zmin=(0.0,0.0)
loop:
iter=iter+1
u=real(#z)
v=imag(#z)
;
; The curve is parameterized with x(t) and y(t). Step through several t
; values to find the nearest approach of the orbit to the curve.
;
t=0.0
while(t<=1.0)
x=((ax*t+bx)*t+cx)*t+x0
y=((ay*t+by)*t+cy)*t+y0
r=(x-u)*(x-u)+(y-v)*(y-v)
if(r<rmin)
rmin=r
itermin=iter
zmin=#z
endif
t=t+@dt
endwhile
final:
if(@colorby==1) ; iteration @ min
#index=0.01*itermin
elseif(@colorby==2) ; angle @ min
t=atan2(zmin)
t=t/pi
if(t<0.0)
t=t+2.0
endif
#index=0.5*t
elseif(@colorby==3) ; draw section
u=real(#pixel)
v=imag(#pixel)
t=0.0
rmin=1e20
while(t<=1.0)
x=((ax*t+bx)*t+cx)*t+x0
y=((ay*t+by)*t+cy)*t+y0
r=(x-u)*(x-u)+(y-v)*(y-v)
if(r<rmin)
rmin=r
endif
t=t+@dt
endwhile
#index=rmin^@nexp
else ; minimum distance
#index=rmin^@nexp
endif
default:
title="Bezier Curve"
helpfile="lkm-help\lkm-bezier.html"
param z0
caption="1st anchor point"
default=(1.0,0.0)
hint="Curve starts at this point."
endparam
param z1
caption="1st control point"
default=(1.0,1.0)
hint="Influences the shape of the curve."
endparam
param z2
caption="2nd control point"
default=(0.0,0.0)
hint="Influences the shape of the curve."
endparam
param z3
caption="2nd anchor point"
default=(0.0,1.0)
hint="Curve ends at this point."
endparam
param dt
caption="step size"
default=0.1
hint="Decrease for smoother line, increase \
to see dots. Should be between 0 & 1."
min=0.0
max=1.0
endparam
param nexp
caption="power"
default=0.1
min=0.0
hint="Decrease to make thinner lines. Use \
with 'minimum distance' coloring."
endparam
param colorby
caption="color by"
default=0
enum="minimum distance" "iteration @ min" \
"angle @ min" "show curve"
endparam
}
UF中效果图:
我干了两天,劳而无功。 |