I testing that code (take on other thread, and modify).
I do not get same angle, if you know why...
#option_explicit
SetWindowTitle( "Orbits" )
SetVirtualResolution ( 1024, 768 )
SetSyncRate ( 60, 1 )
#constant EARTHDISTANCE = 300
#constant MOONDISTANCE = 70
global sunx as float = 512.0
global sunz as float = 384.0
global earthx as float
global earthz as float
global moonx as float
global moonz as float
global earthangle# as float
global moonangle# as float
global angle#
global anglemoon#
global angle_calcul#
global distanceX#
global distanceY#
global distanceTotal
angle# = 0
anglemoon#=0
global testx
global testz
testx = sunx + cos ( earthangle# ) * EARTHDISTANCE
testz = sunz + sin ( earthangle# ) * EARTHDISTANCE
repeat
earthangle# = angle#
moonangle# = anglemoon#
//earthangle = fmod ( earthangle + 0.5, 360.0 )
//moonangle = fmod ( moonangle + 1.5, 360.0 )
earthx = sunx + cos ( earthangle# ) * EARTHDISTANCE
earthz = sunz + sin ( earthangle# ) * EARTHDISTANCE
moonx = earthx + cos ( moonangle# ) * MOONDISTANCE
moonz = earthz + sin ( moonangle# ) * MOONDISTANCE
DrawEllipse ( testx, testz, 45, 45, MakeColor ( 255, 0, 0 ), MakeColor ( 255, 255, 0 ), 1 )
DrawEllipse ( sunx, sunz, 45, 45, MakeColor ( 255, 0, 0 ), MakeColor ( 255, 255, 0 ), 1 )
DrawEllipse ( earthx, earthz, 20, 20, MakeColor ( 0, 0, 255 ), MakeColor ( 0, 255, 255 ), 1 )
DrawEllipse ( moonx, moonz, 8, 8, MakeColor ( 255, 255, 255 ), MakeColor ( 100, 100, 100 ), 1 )
distanceX# = sunx - earthx
distanceY# = sunz - earthz
distanceTotal = Sqrt(distanceX# * distanceX# + distanceY# * distanceY#)
//SetSpritePosition(button_sprite, planet_sprite_x#, planet_sprite_y#)
angle_calcul# = ATanFull(testx - earthx, testz - earthz)
angle#=angle#+0.5
anglemoon#=anglemoon#+1
if angle# > 360
angle#=0
endif
if anglemoon# > 360
anglemoon#=0
endif
Print(angle#)
Print(anglemoon#)
Print(angle_calcul#)
Print(distanceTotal)
Sync()
until GetRawKeyPressed ( 57 ) or getrawkeypressed ( 27 )
end