'Challenge of the Month - November 2017 -- Animation Challenge -- by NaochanON
'WXB487 --> SLG752-1 --> SLG752-3 moving around using legs
GraphicsWindow.Left=10
GraphicsWindow.top=10
GraphicsWindow.width=1000
GraphicsWindow.height=650
GraphicsWindow.BackgroundColor="#BADCAD"
data()
addshapes()
partsposition() ' all position
dir="-1:1=Left-Up;1:1=Right-Up;-1:-1=Left-Down;1:-1=Right-Down"
rot="-1:1=0;1:1=0;-1:-1=3.14;1:-1=3.14"
NN=3
PM=1
While "True"
NN=NN+1
dY=dY+(3-Math.GetRandomNumber(3))
dX=dX+(5-Math.GetRandomNumber(8))
If C_Y<0 or C_Y>600 Then
dY=dY-5*C_Y/Math.Abs(C_Y)
dY=-dY
EndIf
If C_X<0 or C_X>1000 Then
dX=dX-5
dX=-dX
EndIf
_dir=math.Floor(dx/Math.Abs(dX))+":"+Math.Floor(dY/Math.Abs(dY))'4 patterns -1:-1 , -1:1 ,1:-1 ,1:1
dS=-math.ArcTan(dx/(dy+0.000000000001))+rot[_dir] '
deg=Math.GetDegrees(dS)
GraphicsWindow.Title="Moving direcion.... "+dir[_dir]+ " : angle= "+math.floor(-deg)
ddx=-dX/(NN+3)
ddy=dY/(NN+3)
shapes_move()
k=K+PM
LRLegs_moving()
Program.Delay(50)
If NN>10 Then
NN=3
EndIf
If k>4 Or K<1 Then
PM=-PM
EndIf
EndWhile
Sub LRLegs_moving
name="1=L1;2=L2;3=L3;4=R1;5=R2;6=R3;7=L;8=R"
stNMB="1=0;2=5;3=9;4=13;5=18;6=22;7=37;8=40"
MaxNMB="1=5;2=4;3=4;4=5;5=4;6=4;7=3;8=3"
For L=1 To 8
For j=1 To maxnmb[L]
newdeg[L][j]=L_ang["1"+name[L] ][j] +(L_ang["2"+name[L] ][j] - L_ang["1"+name[L] ][j])/5*k - deg '<----------
EndFor
_xL=Shapes.GetLeft(shp[stnmb[L]+1])+shape[stnmb[L]+1]["wd"]/2*s -shape[stnmb[L]+1]["ht"]/2*Math.Sin(Math.GetRadians(newdeg[L][1]))*s 'left anker
_yL=Shapes.Gettop(shp[stnmb[L]+1]) +shape[stnmb[L]+1]["ht"]/2*s +shape[stnmb[L]+1]["ht"]/2*Math.cos(Math.GetRadians(newdeg[L][1]))*s '
For j=1 To maxnmb[L]
_cx=_xL+shape[stnmb[L]+j]["ht"]/2*Math.Sin(Math.GetRadians(newdeg[L][j]))*s
_cy=_yL-shape[stnmb[L]+j]["ht"]/2*Math.cos(Math.GetRadians(newdeg[L][j]))*s
Shapes.Move(shp[stnmb[L]+j],_cx -shape[stnmb[L]+j]["wd"]/2*s,_cy-shape[stnmb[L]+j]["ht"]/2*s)
Shapes.Rotate(shp[stnmb[L]+j],newdeg[L][j])
_xL=_cx+shape[stnmb[L]+j]["ht"]/2*Math.Sin(Math.GetRadians(newdeg[L][j]))*s'new left anker
_yL=_cy-shape[stnmb[L]+j]["ht"]/2*Math.cos(Math.GetRadians(newdeg[L][j]))*s
EndFor
EndFor
EndSub
Sub shapes_move
Shapes.Move(ell[0], Shapes.GetLeft(ell[0])-ddx,Shapes.Gettop(ell[0])-ddy)
C_X=shapes.GetLeft( ell[0])+2
C_Y=shapes.Gettop( ell[0])+2
snmb="02:03:04:05:07:08:09:11:12:13:15:16:17:18:20:21:22:24:25:26:39:40:42:43:"
For i=1 to Array.GetItemCount(shape)
If Text.IsSubText(snmb,text.GetSubTextToEnd(100+i,2))="False" Then
Shapes.Move(ell[i],C_X+DR[i]*Math.Sin(rad[i]+dS)-2,C_Y+DR[i]*Math.cos(rad[i]+dS)-2)
elx=shapes.GetLeft(ell[i])
ely=shapes.Gettop(ell[i])
Shapes.Move(shp[i],elx +2 - shape[i]["wd"]/2*s,ely+2 - shape[i]["ht"]/2*s)
Shapes.Rotate(shp[i],-deg+shape[i]["ag"])
EndIf
EndFor
EndSub
Sub partsposition
For j=1 To Array.GetItemCount(shape)
If Text.IsSubText("rect:ell:", shape[J]["fn"]) Then
dx=C_X-(Shapes.GetLeft(shp[j])+shape[j]["wd"]/2*s)
dy=C_Y-(Shapes.Gettop(shp[j])+shape[j]["ht"]/2*s)
ElseIf shape[J]["fn"]="tri" Then
dx=C_X-( Shapes.GetLeft(shp[j])+ (shape[j]["x1"]+shape[j]["x2"])/2*s )
dy=C_Y-( Shapes.Gettop(shp[j]) + (shape[j]["y1"]+shape[j]["y3"])/2*s )
EndIf
ell[j]=Shapes.AddEllipse(4,4)
Shapes.Move(ell[j], C_X-2-dx,C_Y-2-dy)
Shapes.SetOpacity(ell[j],0)
DR[j]=Math.SquareRoot(dx*dx+dy*dy) ' length
rad[j]=math.ArcTan(dx/(dy+0.000000000001))-Math.pi' angle
EndFor
EndSub
Sub addshapes
s=0.65
shx=300
shy=300
C_X= shx + shape[27]["x"]*s + shape[27]["wd"]/2*s
C_Y= shy + shape[27]["y"]*s + shape[27]["ht"]*s
GraphicsWindow.PenWidth=0
GraphicsWindow.brushColor="Red"
ell[0]= Shapes.AddEllipse(8,8)
Shapes.SetOpacity(ell[0],50)
Shapes.Move(ell[0], C_X-4, C_Y-4)
For i=1 To Array.GetItemCount(shape)
GraphicsWindow.Penwidth =0
GraphicsWindow.BrushColor = shape[i]["bc"]
GraphicsWindow.penColor = shape[i]["pc"]
If shape[i]["fn"]="ell" Then
shp[i] = Shapes.AddEllipse(shape[i]["wd"]*s, shape[i]["ht"]*s)
ElseIf shape[i]["fn"]="rec" Then
shp[i] = Shapes.Addrectangle(shape[i]["wd"]*s, shape[i]["ht"]*s)
ElseIf shape[i]["fn"]="tri" Then
shp[i] = Shapes.Addtriangle(shape[i]["x1"]*s, shape[i]["y1"]*s,shape[i]["x2"]*s, shape[i]["y2"]*s,shape[i]["x3"]*s, shape[i]["y3"]*s)
EndIf
Shapes.Animate(shp[i], shape[i]["x"]*s+shX, shape[i]["y"]*s+shY, 100)
shapes.Rotate(shp[i],shape[i]["ag"])
EndFor
EndSub