A not very useful animated pendulum.
(it is smoother on a real device in release mode)
(it is smoother on a real device in release mode)
B4X:
Sub Activity_Create(FirstTime As Boolean)
Dim cvs As Canvas
cvs.Initialize(Activity)
DrawPendulum (cvs, 50%x, 20%y, 40%x, -45, Colors.Red)
DrawPendulum (cvs, 50%x, 60%y, 30%x, 45, Colors.Blue)
DrawPendulum (cvs, 150dip, 10dip, 20%x, 70, Colors.Green)
End Sub
Sub DrawPendulum (cvs As Canvas, cx As Float, cy As Float, l As Float, ZeroAngle As Float, clr As Int)
Dim teta0 As Float = ZeroAngle / 180 * cPI
Dim start As Long = DateTime.Now
Dim w As Float = Sqrt(1000 / l) / 1000
Dim x2, y2 As Float
Do While True
Sleep(10)
Dim t As Int = DateTime.Now - start
Dim teta As Float = teta0 * Cos(w * t)
cvs.DrawLine(cx, cy, x2, y2, Colors.Transparent, 2dip)
cvs.DrawCircle(x2, y2, 20dip, Colors.Transparent, True, 1dip)
x2 = cx + l * Sin(teta)
y2 = cy + l * Cos(teta)
cvs.DrawLine(cx, cy, x2, y2, Colors.White, 2dip)
cvs.DrawCircle(x2, y2, 20dip, clr, True, 1dip)
Activity.Invalidate
Loop
End Sub