Microsoft Small Basic

Program Listing: RDJ626-0
' Arrows
' Copyright © 2017 Nonki Takahashi. The MIT License.
' Challenge 2017-06
' Last update 2017-06-26
' Program ID RDJ626-0

GraphicsWindow.Title = "Arrows"
Init()
While "True"
If mouseMove Then
For i = 1 To nArrow
arw = arrow[i]
x = mx - arw["x"]
y = my - arw["y"]
Math_CartesianToPolar()
Shapes.Rotate(arw["tail"], a + 135)
Shapes.Rotate(arw["head"], a + 135)
EndFor
mouseMove = "False"
Else
Program.Delay(100)
EndIf
EndWhile

Sub AddArrow
' param x, y - point
GraphicsWindow.PenWidth = 2
GraphicsWindow.PenColor = "Black"
tail = Shapes.AddLine(-20, -20, 0, 0)
GraphicsWindow.PenWidth = 0
GraphicsWindow.BrushColor = "Black"
head = Shapes.AddTriangle(-25, -25, -20, -10, -10, -20)
Shapes.Move(tail, x, y)
Shapes.Move(head, x, y)
arw["tail"] = tail
arw["head"] = head
arw["x"] = x
arw["y"] = y
nArrow = nArrow + 1
arrow[nArrow] = arw
EndSub

Sub Init
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
cx = gw / 2
cy = gh / 2
For y = cy - 160 To cy + 160 Step 80
For x = cx - 240 To cx + 240 Step 80
AddArrow()
EndFor
EndFor
GraphicsWindow.MouseMove = OnMouseMove
EndSub

Sub OnMouseMove
mouseMove = "True"
mx = GraphicsWindow.MouseX
my = GraphicsWindow.MouseY
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 And y = 0 Then
a = 0
Else
a = Math.ArcTan(y / x) * 180 / Math.Pi
EndIf
' at this point -90<=a<=90
If x < 0 Then
a = a + 180
ElseIf x >= 0 And y < 0 Then
a = a + 360
EndIf
' at this point 0<=a<360
EndSub