Microsoft Small Basic

Program Listing: FGM527
' Draw Circle Game
' Version 0.1
' Copyright © 2018 Nonki Takahashi. The MIT License.

GraphicsWindow.Title = "Draw Circle Game 0.1"
Init()
While "True"
DrawCircle()
Result()
Clear()
EndWhile

Sub Clear
Controls.SetTextBoxText(tbox, "")
GraphicsWindow.BrushColor = "White"
GraphicsWindow.FillRectangle(0, 0, gw, gh)
n = 0
x = ""
y = ""
EndSub

Sub DrawCircle
buttonClicked = "False"
GraphicsWindow.BrushColor = "Black"
While Not[buttonClicked]
If mouseMove And Mouse.IsLeftButtonDown Then
If GraphicsWindow.MouseY < gh - 120 Then
n = n + 1
x[n] = GraphicsWindow.MouseX
y[n] = GraphicsWindow.MouseY
GraphicsWindow.FillEllipse(x[n] - 2, y[n] - 2, 4, 4)
EndIf
mouseMove = "False"
EndIf
EndWhile
EndSub

Sub Init
Not = "False=True;True=False;"
CR = Text.GetCharacter(13)
LF = Text.GetCharacter(10)
dx = "1=1;2=0;3=-1;4=0;"
dy = "1=0;2=1;3=0;4=-1;"
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
GraphicsWindow.BrushColor = "Black"
tbox = Controls.AddMultiLineTextBox(10, gh - 110)
Controls.SetSize(tbox, gw - 60, 100)
Controls.AddButton("OK", gw - 40, gh - 110)
Controls.ButtonClicked = OnButtonClicked
GraphicsWindow.MouseMove = OnMouseMove
EndSub

Sub OnButtonClicked
buttonClicked = "True"
EndSub

Sub OnMouseMove
mouseMove = "True"
EndSub

Sub Result
txt = "n=" + n + CR + LF
sx = 0
sy = 0
For i = 1 To n
sx = sx + x[i]
sy = sy + y[i]
EndFor
txt = txt + "Σx=" + sx + ", Σy=" + sy + CR + LF
ax = Math.Floor(sx / n)
ay = Math.Floor(sy / n)
txt = txt + "ave(x)=" + ax + ", ave(y)=" + ay + CR + LF
GraphicsWindow.BrushColor = "Red"
GraphicsWindow.FillEllipse(ax - 2, ay - 2, 4, 4)
sr = 0
For i = 1 To n
rx = x[i] - ax
ry = y[i] - ay
r[i] = Math.SquareRoot(rx * rx + ry * ry)
sr = sr + r[i]
EndFor
sr = Math.Floor(sr)
ar = Math.Floor(sr / n)
txt = txt + "Σr=" + sr + ", ave(r)=" + ar + CR + LF
GraphicsWindow.PenColor = "Red"
GraphicsWindow.DrawEllipse(ax - ar, ay - ar, 2 * ar, 2 * ar)
se = 0
For i = 1 To n
e = Math.Abs(r[i] - ar)
se = se + e
EndFor
se = Math.Floor(se)
txt = txt + "Σe=" + se + CR + LF
txt = txt + "score=n*ave(r)/Σe=" + Math.Floor(n * ar / se)
Controls.SetTextBoxText(tbox, txt)
Wait()
EndSub

Sub Wait
buttonClicked = "False"
While Not[buttonClicked]
Program.Delay(200)
EndWhile
EndSub