' Challenge of the Month - by NaochanON LKL810-0 added spinning simulation
' October 2016 Make an animation of a top rotating and moving in the GraphicsWindow
make_top()
CenterPosition()
While "True"
Top_move()
Program.Delay(25)
endwhile
Sub Top_move
Shapes.Move(el0,Shapes.GetLeft(el0)+pmX*ddx,Shapes.Gettop(el0)+pmY*ddY)
XYC="X="+(Shapes.GetLeft(el0)+4)+";Y="+ (Shapes.Gettop(el0)+4) ' base point
For i=1 To Array.GetItemCount(shp)
If dat[i]["fn"] = "rc" then
shx=XYC["X"]+DR[i]*Math.cos( math.GetRadians(DS0[i]+pmx*5))-dat[i]["w"]*s/2
shy=XYC["Y"]+DR[i]*Math.sin( math.GetRadians(DS0[i]+pmx*5))-dat[i]["h"]*s/2
ElseIf dat[i]["fn"] = "tr" then
shx=XYC["X"]+DR[i]*Math.cos( math.GetRadians(DS0[i]+pmx*5))-cntr[i]["X"]
shy=XYC["Y"]+DR[i]*Math.sin( math.GetRadians(DS0[i]+pmx*5))-cntr[i]["Y"]
EndIf
Shapes.Move(shp[i],shx,shy)
Shapes.Rotate(shp[i],pmX*5) ' in this case it rotates only +5 or -5 degrees
EndFor
'----------------------------------------------------------------------------------------------
NN=NN+1
shx=XYC["X"]+DR[12]*Math.cos( math.GetRadians(DS0[12]+pmx*5))-dat[12]["w"]*s/2+NN*rot*math.Cos(math.GetRadians(pmx*5))
shy=XYC["Y"]+DR[12]*Math.sin( math.GetRadians(DS0[12]+pmx*5))-dat[12]["h"]*s/2+pmx*NN*rot*math.sin(math.GetRadians(math.Abs(pmx*5)))
Shapes.Move(shp[12],shx,shy) ' spinning simulation
If NN> dat[2]["w"]*s/rot-2 Then
NN=0
EndIf
'----------------------------------------------------------------------------------------------
If Shapes.GetLeft(el0)<0 or (Shapes.GetLeft(shp[2])+dat[2]["w"]*s)>1200 Then ' X edge
pmX=-pmX
EndIf
If Shapes.Gettop(el0)<0 or (Shapes.Gettop(shp[11])+dat[11]["y3"]*s)>650 Then ' Y edge
pmY=-pmY
EndIf
EndSub
Sub CenterPosition
For i= 1 To array.GetItemCount(SHP)
If dat[i]["fn"] = "rc" then
X[i]=Shapes.GetLeft(SHP[i])+dat[i]["w"]*s/2 ' center of the shape ... X
Y[i]=Shapes.GetTop(SHP[i])+dat[i]["h"]*s/2 ' center of the shape ... Y
ElseIf dat[i]["fn"] = "tr" then
X[i]=Shapes.GetLeft(SHP[i])+cntr[i]["X"] ' center of the shape ... X
Y[i]=Shapes.GetTop(SHP[i])+ cntr[i]["Y"] ' center of the shape ... Y
EndIf
DS0[i]=math.GetDegrees(Math.ArcTan((Y[i]-XYC["Y"])/(X[i]-XYC["X"]))) ' degree // angle of the shape_Center from XYC position
DR[i]=Math.SquareRoot((X[i]-XYC["X"])*(X[i]-XYC["X"])+(Y[i]-XYC["Y"])*(Y[i]-XYC["Y"])) ' radius
endfor
endsub