Microsoft Small Basic

Program Listing: TCC509
' Frog
' Version 0.1
' Copyright © 2016 Nonki Takahashi. The MIT License.

Init()
ex[1] = gw / 2 - er
ey[1] = gh / 2 - er
ex[2] = gw / 2 + er
ey[2] = gh / 2 - er
GraphicsWindow.BrushColor = "DarkRed"
GraphicsWindow.FillEllipse(ex[1] - 2 * er, ey[2] + er, 6 * er, 2 * er)
GraphicsWindow.PenWidth = 40
GraphicsWindow.PenColor = "Lime"
GraphicsWindow.DrawEllipse(ex[1] - 2 * er, ey[2] + er, 6 * er, 2 * er)
GraphicsWindow.PenWidth = 0
For i = 1 To 2
GraphicsWindow.BrushColor = "White"
GraphicsWindow.FillEllipse(ex[i] - er, ey[i] - er, 2 * er, 2 * er)
GraphicsWindow.BrushColor = "Black"
eye[i] = Shapes.AddEllipse(er, er)
Shapes.Move(eye[i], ex[i] - er / 2, ey[i] - er / 2)
EndFor
GraphicsWindow.MouseMove = OnMouseMove
While "True"
If mouseMove Then
For i = 1 To 2
x = mx - ex[i]
y = my - ey[i]
Math_CartesianToPolar()
r = Math.Min(r, er / 2)
_a = Math.GetRadians(a)
x = ex[i] + r * Math.Cos(_a)
y = ey[i] + r * Math.Sin(_a)
Shapes.Move(eye[i], x - er / 2, y - er / 2)
EndFor
mouseMove = "False"
Else
Program.Delay(200)
EndIf
EndWhile

Sub OnMouseMove
mx = GraphicsWindow.MouseX
my = GraphicsWindow.MouseY
mouseMove = "True"
EndSub

Sub Init
GraphicsWindow.Title = "Frog 0.1"
GraphicsWindow.BackgroundColor = "Teal"
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
er = 50
EndSub

Sub Math_CartesianToPolar
' Math | convert cartesian coodinate to polar coordinate
' param x, y - cartesian coordinate
' return r, a - polar coordinate
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
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