For learning purposes, I wrote a code that rotates an object in circle in pure way WITHOUT USING ANY 3RD PARTY LIB OR FUNCTION
Important code is:
Rotate an child object around a parent object:
Sub rotate( parent As ImageView, child As ImageView, latency As Int, r As Int) As ResumableSub
Dim parent_vertical_center As Double
Dim parent_horizontal_center As Double
'360 degree = 6.28319 radians
'1 degree = 0.0174533 radians
Dim angle As Double =6.28319
Do While True
If angle < 0.0174533 Then angle=6.28319
parent_vertical_center = parent.Top + ( (parent .Height - child.Height) / 2 )
parent_horizontal_center = parent.Left + ( (parent.Width - child.Width ) / 2 )
Dim x As Int = parent_horizontal_center + (r * Sin(angle) )
Dim y As Int = parent_vertical_center + (r * Cos(angle) ) 'https://stackoverflow.com/a/16802483
child.Left = x
child.Top = y
angle = angle - 0.01
Sleep(latency)
Loop
End Sub
and I called it like:
B4X:
rotate(sun, earth, 35, sun.Width+10) 'rotate earth around sun with 35 latency and distance from sun to earh is sun width + 10
rotate(earth, moon, 1, earth.Width-10) 'rotate moon around earth with 1 latency and distance from moon to earh is earth width - 10
Hope you like it