Microsoft Small Basic

Program Listing: XFF651
' Dart Board
' Version 0.1
' Copyright © 2018 Nonki Takahashi. The MIT Licnese.
' Last update 2018-03-12

GraphicsWindow.Title = "Dart Board"
Init()
r = 150
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.FillEllipse(x1 - r, y1 - r, 2 * r, 2 * r)
GraphicsWindow.PenWidth = 8
GraphicsWindow.PenColor = "#CC0000"
r = 124
GraphicsWindow.DrawEllipse(x1 - r, y1 - r, 2 * r, 2 * r)
r = 64
GraphicsWindow.DrawEllipse(x1 - r, y1 - r, 2 * r, 2 * r)
r = 128
GraphicsWindow.BrushColor = "LemonChiffon"
GraphicsWindow.PenWidth = 8
GraphicsWindow.PenColor = "#006600"
param = "x=" + x1 + ";y=" + y1 + ";da=6;"
For a = 9 To 351 Step 18
n = n + 1
_a = Math.GetRadians(a)
x2 = x1 + r * Math.Sin(_a)
y2 = y1 - r * Math.Cos(_a)
If Math.Remainder(n, 2) = 0 Then
GraphicsWindow.FillTriangle(x1, y1, x2, y2, x3, y3)
param["a1"] = a - 108
param["a2"] = a - 90
param["r"] = 124
GW_DrawArc()
param["r"] = 64
GW_DrawArc()
EndIf
x3 = x2
y3 = y2
EndFor
GraphicsWindow.PenColor = "Gray"
GraphicsWindow.PenWidth = 2
For a = 9 To 351 Step 18
_a = Math.GetRadians(a)
x2 = x1 + r * Math.Sin(_a)
y2 = y1 - r * Math.Cos(_a)
GraphicsWindow.DrawLine(x1, y1, x2, y2)
EndFor
GraphicsWindow.DrawEllipse(x1 - r, y1 - r, 2 * r, 2 * r)
r = 120
GraphicsWindow.DrawEllipse(x1 - r, y1 - r, 2 * r, 2 * r)
r = 68
GraphicsWindow.DrawEllipse(x1 - r, y1 - r, 2 * r, 2 * r)
r = 60
GraphicsWindow.DrawEllipse(x1 - r, y1 - r, 2 * r, 2 * r)
r = 10
GraphicsWindow.BrushColor = "#006600"
GraphicsWindow.FillEllipse(x1 - r, y1 - r, 2 * r, 2 * r)
GraphicsWindow.DrawEllipse(x1 - r, y1 - r, 2 * r, 2 * r)
r = 5
GraphicsWindow.BrushColor = "#CC0000"
GraphicsWindow.FillEllipse(x1 - r, y1 - r, 2 * r, 2 * r)
GraphicsWindow.DrawEllipse(x1 - r, y1 - r, 2 * r, 2 * r)
GraphicsWindow.BrushColor = "Gray"
GraphicsWindow.FontName = "Trebuchet MS"
fs = 16
GraphicsWindow.FontSize = fs
score = "1=20;2=1;3=18;4=4;5=13;6=6;7=10;8=15;9=2;10=17;"
score = score + "11=3;12=19;13=7;14=16;15=8;16=11;17=14;18=9;19=12;20=5;"
r = 140
i = 1
For a = 0 To 342 Step 18
s = score[i]
dx = Text.GetLength(s) / 2 * fs * 0.6
_a = Math.GetRadians(a)
x = x1 + r * Math.Sin(_a) - dx
y = y1 - r * Math.Cos(_a) - fs / 2
GraphicsWindow.DrawText(x, y, s)
i = i + 1
EndFor

Sub Init
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
x1 = gw / 2
y1 = gh / 2
EndSub

Sub GW_DrawArc
' GraphicsWindow | Draw arc
' param["x"] - center x coordinate [px]
' param["y"] - center y coordinate [px]
' param["r"] - radius [px]
' param["a1"] - start angle [°]
' param["a2"] - end angle [°]
' param["da"] - delta (step) angle [°]
' param["ct"] - cap type ("Round" for round, otherwise for flat)
Stack.PushValue("local", local)
Stack.PushValue("local", a)
local["pw"] = GraphicsWindow.PenWidth
local["bc"] = GraphicsWindow.BrushColor
GraphicsWindow.BrushColor = GraphicsWindow.PenColor
For a = param["a1"] To param["a2"] Step param["da"]
local["rad"] = Math.GetRadians(a)
local["x2"] = param["x"] + param["r"] * Math.Cos(local["rad"])
local["y2"] = param["y"] + param["r"] * Math.Sin(local["rad"])
If param["a1"] <> a Then
GraphicsWindow.DrawLine(local["x1"], local["y1"], local["x2"], local["y2"])
EndIf
If ((param["a1"] <> a) And (a <> param["a2"])) Or Text.ConvertToLowerCase(param["ct"]) = "round" Then
GraphicsWindow.PenWidth = 0
GraphicsWindow.FillEllipse(local["x2"] - local["pw"] / 2, local["y2"] - local["pw"] / 2, local["pw"], local["pw"])
GraphicsWindow.PenWidth = local["pw"]
EndIf
local["x1"] = local["x2"]
local["y1"] = local["y2"]
EndFor
GraphicsWindow.BrushColor = local["bc"]
a = Stack.PopValue("local")
local = Stack.PopValue("local")
EndSub