Microsoft Small Basic

Program Listing: ZTN256
' Turtle to Mouse
' Copyright © 2018 Nonki Takahashi. The MIT License.
' Challenge 2018-07

Timer.Interval = 100
Timer.Tick = OnTick

Sub OnTick
mx = GraphicsWindow.MouseX
my = GraphicsWindow.MouseY
tx = Turtle.X
ty = Turtle.Y
x = mx - tx
y = my - ty
Math_CartesianToPolar()
If 0 < r Then
Turtle.Angle = a + 90
If 10 < r Then
r = 10
EndIf
Turtle.Move(r)
EndIf
EndSub

Sub Math_CartesianToPolar
' Math | convert Cartesian coodinate to polar coordinate
' param x, y - Cartesian coordinate
' return r, a - polar coordinate (0<=a<360)
r = Math.SquareRoot(x * x + y * y)
If x = 0 And y > 0 Then
a = 90 ' [degree]
ElseIf x = 0 And y < 0 Then
a = -90
ElseIf x = 0 Then ' this condition is needed for SB 1.2
a = 0
Else
a = Math.ArcTan(y / x) * 180 / Math.Pi
EndIf
If x < 0 Then
a = a + 180
ElseIf x > 0 And y < 0 Then
a = a + 360
EndIf
EndSub