[PEL] 复制代码
INPUT:
af(0.02, 0.02, 0.2,0.01);
afinit:=0.02;
bc:=barpos;
inith:=ref(h,bc-1);
initl:=ref(l,bc-1);
initc:=ref(c,bc-1);
inito:=ref(o,bc-1);
variable:dir:=0,nh:=0,ep:=0;
if initc>inito then initdir:=1;
if initc<inito then initdir=-1;
if initdir=1&&barpos=1 then Begin
ep:=inith;
sar1:=l;
end
else if initdir=-1&&barpos=1 then Begin
ep:=initl;
sar1:=h;
end
//初始ep
lep:=ref(ep,1);
if barpos>1 Then Begin
//if barpos=2&&initdir=1 then dir:=1;
//if barpos=2&&initdir=-1 then dir:=-1;
//dir:=initdir;
if initdir=1&&dir=0 then Begin
if h>ep then begin
ep:=h;
nh:=nh+1;
end
end
//if dir=1 then afnow:=afinit*(nh+1);
//if afnow>0.2 then afnow:=0.2;
if initdir=1 then Begin
afnow:=afinit*(nh+1);
if afnow>0.2 then afnow:=0.2;
sar1:=sar1[barpos-1]+afnow[barpos-1]*(ep[barpos-1]-sar1[barpos-1]);
end
//上面是初始的多sar
//下面是空初始sar
if initdir=-1&&dir=0 then Begin
if l<ep then begin
ep:=l;
nh:=nh+1;
end
end
//if dir=-1 then afnow:=afinit*(nh+1);
//if afnow>0.2 then afnow:=0.2;
if initdir=-1 then Begin
afnow:=afinit*(nh+1);
if afnow>0.2 then afnow:=0.2;
sar1:=sar1[barpos-1]-afnow[barpos-1]*(sar1[barpos-1]-ep[barpos-1]);
end
//上面的2个方向初始计算 只是为了从第一个柱子画出来第一条线.
//dir什么的设定还都没写
if (h[barpos-1]<=sar1&&h>sar1) then dir:=1;
if (l[barpos-1]>=sar1&&l<sar1) then dir:=-1;
ddd:=dir;
//金魔方cross 前面>= 现在< 不算交叉
//基于第一个线 设定方向
//后续sar的计算 ep更新 看起来都依赖方向 所以必须写这下面 不可以写上面
if dir=1&&dir[barpos-1]<>1 then Begin
ep:=h;
sar1:=ep[barpos-1];
nh:=1;
afnow:=0.02;
end
if dir=1&&dir[barpos-1]=1 then Begin
if h>ep then begin
ep:=h;
nh:=nh+1;
end
afnow:=afinit*(nh);
if afnow>0.2 then afnow:=0.2;
sar1:=sar1[barpos-1]+afnow[barpos-1]*(ep[barpos-1]-sar1[barpos-1]);
end
if dir=-1&&dir[barpos-1]<>-1 then Begin
ep:=l;
sar1:=ep[barpos-1];
nh:=1;
afnow:=0.02;
end
if dir=-1&&dir[barpos-1]=-1 then Begin
if l<ep then begin
ep:=l;
nh:=nh+1;
end
afnow:=afinit*(nh);
if afnow>0.2 then afnow:=0.2;
sar1:=sar1[barpos-1]-afnow[barpos-1]*(sar1[barpos-1]-ep[barpos-1]);
end
//if cross(h,sar1) then dir:=1;
//if cross(sar1,l) then dir:=-1;
//单柱的有正又反 前面空 没处理
if (h[barpos-1]<=sar1&&h>sar1)||(c[barpos-1]<=sar1&&c>sar1) then dir:=1;
if (l[barpos-1]>=sar1&&l<sar1)||(c[barpos-1]>=sar1&&c<sar1) then dir:=-1;
//if cross(h,sar1)||(ref(h<=sar1,1)&&h>sar1)||(ref(c<=sar1,1)&&c>sar1) then dir:=1;
//if cross(sar1,l)||(ref(l>=sar1,1)&&l<sar1)||(ref(c>=sar1,1)&&c<sar1) then dir:=-1;
sarolp:=h>=sar1&&l<=sar1;
sara1:=(dir[barpos-1]=-1&&dir[barpos-2]<>-1)&&sarolp[barpos-1]=1&&c[barpos-1]>sar1[barpos-1];
sara2:=(dir[barpos-1]=1&&dir[barpos-2]<>1)&&sarolp[barpos-1]=1&&c[barpos-1]<sar1[barpos-1];
if sara2 then dir:=-1;
if sara1 then dir:=1;
if dir=-1&&dir[barpos-1]=1 then Begin
ep:=l;
sar1:=ep[barpos-1];
nh:=1;
afnow:=0.02;
end
if dir=1&&dir[barpos-1]=-1 then Begin
ep:=h;
sar1:=ep[barpos-1];
nh:=1;
afnow:=0.02;
end
if sara1 then Begin
ep:=h;
sar1:=ep[barpos-1];
nh:=1;
afnow:=0.02;
end
if sara2 then Begin
ep:=l;
sar1:=ep[barpos-1];
nh:=1;
afnow:=0.02;
end
//if cross(h,sar1)||(ref(h<=sar1,1)&&h>sar1)||(ref(c<=sar1,1)&&c>sar1) then dir:=1;
//if cross(sar1,l)||(ref(l>=sar1,1)&&l<sar1)||(ref(c>=sar1,1)&&c<sar1) then dir:=-1;
End
if barpos=1 then hh:=h;
else if h>hh then hh:=h;
if barpos=1 then ll:=l;
else if l<ll then ll:=l;
as:ep;
as1:nh,nodraw;
as2:sar1;
as3:afnow,nodraw;
as4:=ddd,nodraw;
as5:dir,nodraw,colorgray;
//if(dir=0,sar1,nodraw),NoDrawInvalid,colorgray,Pointdot,linethick4;
//if(dir>0,sar1,nodraw),NoDrawInvalid,colorred,Pointdot,linethick4;
//if(dir<0,sar1,nodraw),NoDrawInvalid,colorgreen,Pointdot,linethick4;