将我整的正方形陷阱UF算法,整成UF代码,发在这里:
正方形陷阱轨迹ID {
init:
int iter = 0
float Circle=0
float x = 0
float y = 0
float u = 0
float v= 0
float xa=0
float ya=0
float xb=0
float yb=0
float xc=0
float yc=0
float xd=0
float yd=0
float lac=0
float lbd=0
float Dsgd1 = 0
float ZtoPsqd = 0
float Rc = @r
float R= sqrt(2)*Rc
float m = @angle*pi/180
float H=@h
float ID=0
bool Trapped = false
loop:
iter= iter + 1
x = real(#z)
y = imag(#z)
u=R*cos(m)
v=R*sin(m)
xa=u+@o1x
ya=v+@o1y
xb=-v+@o1x
yb=u+@o1y
xc=-u+@o1x
yc=-v+@o1y
xd=v+@o1x
yd=-u+@o1y
lac=(ya-yc)*x-(xa-xc)*y+(xa*yc-ya*xc)
lbd=(yb-yd)*x-(xb-xd)*y+(xb*yd-yb*xd)
if lac>0&&lbd>0
Dsgd1=abs((ya-yd)*x-(xa-xd)*y+(xa*yd-ya*xd))/sqrt((ya-yd)^2+(xa-xd)^2)
elseif lac<0&&lbd>0
Dsgd1=abs((ya-yb)*x-(xa-xb)*y+(xa*yb-ya*xb))/sqrt((ya-yb)^2+(xa-xb)^2)
elseif lac<0&&lbd<0
Dsgd1=abs((yb-yc)*x-(xb-xc)*y+(xb*yc-yb*xc))/sqrt((yb-yc)^2+(xb-xc)^2)
elseif lac>0&&lbd<0
Dsgd1=abs((yc-yd)*x-(xc-xd)*y+(xc*yd-yc*xd))/sqrt((yc-yd)^2+(xc-xd)^2)
endif
if iter>@skip
if (@rangevar==0&&!Trapped) ||(@rangevar==1)
if Dsgd1 <H
ID=iter
ZtoPsqd= Dsgd1
Trapped= true
endif
endif
endif
final:
if !Trapped
#solid=true
else
Circle = (@off+ID%3)%4
float Ratio = ZtoPsqd/H
float ColorIndex = 29 * Ratio + Circle * 45
#index = (ColorIndex +21) % 256 /256
endif
default:
title = "正方形陷阱轨迹ID"
param r
caption = "Circle radius"
default = 0.5
endparam
param h
caption = "h"
default = 0.15
endparam
param o1x
caption = "o1x"
default =0.0000
endparam
param o1y
caption = "o1y"
default =0.0000
endparam
param rangevar
caption="range variable"
default=0
enum="先上后下" "后来居上"
endparam
param off
caption = "off"
default =1
endparam
param angle
caption = "angle"
default =0
endparam
param skip
caption = "skip"
default =0
endparam
}
用UF生成一幅J集:
|