- UID
- 7
- 帖子
- 2888
- 精华
- 10
- 积分
- 2836
|
这是陷阱法做的吗?能不能把它给简化一下,这代码太长了,看了都吓人。
predictor-general-julia {
; Kerry Mitchell 26sep99
init:
c=@julparam
z1=#pixel
z2=(0.0,0.0)
z3=(0.0,0.0)
z4=(0.0,0.0)
zp=(0.0,0.0)
zlast=(0.0,0.0)
int iter=0
bool done=false
float logn=log(@nexp)
float llbail=log(log(@bailout))+log(0.5)
float k=0.0
float kfrac=0.0
float fac1=0.0
float fac2=0.0
weight1=(0.0,0.0)
weight2=(0.0,0.0)
weight3=(0.0,0.0)
weight4=(0.0,0.0)
err=(0.0,0.0)
relerr=(0.0,0.0)
toterr=(0.0,0.0)
totrelerr=(0.0,0.0)
;
; set up constants
;
if(@npp==1) ; 2 point predictor
z2=z1^@nexp+c
f1of1=@f1ofz(1)
f1of2=@f1ofz(2)
f1of3=@f1ofz(3)
weight1=(f1of3-f1of2)/(f1of1-f1of2)
weight2=(f1of3-f1of1)/(f1of2-f1of1)
elseif(@npp==2) ; 3 point predictor
z2=z1^@nexp+c
z3=z2^@nexp+c
f1of1=@f1ofz(1)
f1of2=@f1ofz(2)
f1of3=@f1ofz(3)
f1of4=@f1ofz(4)
f2of1=@f2ofz(1)
f2of2=@f2ofz(2)
f2of3=@f2ofz(3)
f2of4=@f2ofz(4)
weight1=(f1of4-f1of2)/(f1of1-f1of2)*(f2of4-f2of3)/(f2of1-f2of3)
weight2=(f1of4-f1of3)/(f1of2-f1of3)*(f2of4-f2of1)/(f2of2-f2of1)
weight3=(f1of4-f1of1)/(f1of3-f1of1)*(f2of4-f2of2)/(f2of3-f2of2)
elseif(@npp==3) ; 4 point predictor
z2=z1^@nexp+c
z3=z2^@nexp+c
z4=z3^@nexp+c
f1of1=@f1ofz(1)
f1of2=@f1ofz(2)
f1of3=@f1ofz(3)
f1of4=@f1ofz(4)
f1of5=@f1ofz(5)
f2of1=@f2ofz(1)
f2of2=@f2ofz(2)
f2of3=@f2ofz(3)
f2of4=@f2ofz(4)
f2of5=@f2ofz(5)
f3of1=@f3ofz(1)
f3of2=@f3ofz(2)
f3of3=@f3ofz(3)
f3of4=@f3ofz(4)
f3of5=@f3ofz(5)
weight1=(f1of5-f1of2)/(f1of1-f1of2)*(f2of5-f2of3)/(f2of1-f2of3)
weight1=weight1*(f3of5-f3of4)/(f3of1-f3of4)
weight2=(f1of5-f1of3)/(f1of2-f1of3)*(f2of5-f2of4)/(f2of2-f2of4)
weight2=weight2*(f3of5-f3of1)/(f3of2-f3of1)
weight3=(f1of5-f1of4)/(f1of3-f1of4)*(f2of5-f2of1)/(f2of3-f2of1)
weight3=weight3*(f3of5-f3of2)/(f3of3-f3of2)
weight4=(f1of5-f1of1)/(f1of4-f1of1)*(f2of5-f2of2)/(f2of4-f2of2)
weight4=weight4*(f3of5-f3of3)/(f3of4-f3of3)
endif
loop:
iter=iter+1
;
; find new predicted value, zp
;
if(@npp==1) ; 2 point predictor
zp=weight1*z1+weight2*z2
z1=z2
z2=z2^@nexp+c
zlast=z2
elseif(@npp==2) ; 3 point predictor
zp=weight1*z1+weight2*z2+weight3*z3
z1=z2
z2=z3
z3=z3^@nexp+c
zlast=z3
elseif(@npp==3) ; 4 point predictor
zp=weight1*z1+weight2*z2+weight3*z3+weight4*z4
z1=z2
z2=z3
z3=z4
z4=z4^@nexp+c
zlast=z4
else ; bypass predictor logic
z1=z1^@nexp+c
zlast=z1
endif
err=zp-zlast
relerr=err/zlast
toterr=toterr+err
totrelerr=totrelerr+relerr
;
; set z value for coloring
;
if(@ztype==1) ; z = absolute error
z=err
elseif(@ztype==2) ; z = relative error
z=relerr
elseif(@ztype==3) ; z = mean absolute error
z=toterr/iter
elseif(@ztype==4) ; z = mean relative error
z=totrelerr/iter
else ; z = iterate
z=zlast
endif
;
; bailout
; if mean error chosen, perform one more iteration and use
; renormalization smoothing
;
if(|zlast|>@bailout)
done=true
if(@ztype>2)
iter=iter+1
fac1=log(log(cabs(zlast)))-llbail
if(@npp==1) ; 2 point predictor
zp=weight1*z1+weight2*z2
z1=z2
z2=z2^@nexp+c
zlast=z2
elseif(@npp==2) ; 3 point predictor
zp=weight1*z1+weight2*z2+weight3*z3
z1=z2
z2=z3
z3=z3^@nexp+c
zlast=z3
elseif(@npp==3) ; 4 point predictor
zp=weight1*z1+weight2*z2+weight3*z3+weight4*z4
z1=z2
z2=z3
z3=z4
z4=z4^@nexp+c
zlast=z4
else ; bypass predictor logic
z1=z1^@nexp+c
zlast=z1
endif
err=zp-zlast
relerr=err/zlast
fac2=log(log(cabs(zlast)))-llbail-logn
k=exp((fac1+fac2)/2.0)
kfrac=(k-1.0)/(@nexp-1.0)
if(@ztype==3) ; mean absolute error
z=kfrac*toterr/iter+(1.0-kfrac)*(toterr+err)/(iter+1)
elseif(@ztype==4) ; mean relative error
z=kfrac*totrelerr/iter+(1.0-kfrac)*(totrelerr+relerr)/(iter+1)
endif
endif
endif
bailout:
done==false
default:
title="Predictor General Julia"
maxiter=100
periodicity=0
center=(0.0,0.0)
magn=1.0
angle=0
param julparam
caption="Julia Parameter"
default=(0.0,1.0)
endparam
param bailout
caption="bailout value"
default=1000000.0
min=0.0
endparam
param nexp
caption="exponent"
default=2.0
hint="z exponent, > 1.0"
min=1.0
endparam
param ztype
caption="z type"
default=4
enum="iterate" "last error" "last relative error" \
"average error" "average relative error"
endparam
param npp
caption="predictor points"
default=1
enum="none" "2" "3" "4"
hint="Number of predictor points. Choose 'none' to bypass \
predictor logic."
endparam
func f1ofz
caption="first function"
default=ident()
hint="Use indent() for linear interpolation."
endfunc
func f2ofz
caption="second function"
default=ident()
hint="Used with 3 & 4 point predictor. Use indent() for linear interpolation."
endfunc
func f3ofz
caption="third function"
default=ident()
hint="Only used with 4 point predictor. Use indent() for linear interpolation."
endfunc
switch:
type="predictor-general-mandelbrot"
bailout=@bailout
nexp=@nexp
ztype=@ztype
npp=@npp
f1ofz=@f1ofz
f2ofz=@f2ofz
f3ofz=@f3ofz
} |
|