Microsoft Small Basic

Program Listing: RQP548
' Internatinal Code of Signals
' Copyright © 2019 Nonki Takahashi. The MIT Licnese.

GraphicsWindow.Title = "International Code of Signals"
gw = GraphicsWindow.Width
gh = GraphicsWindow.Height
bg = "LightGray"
GraphicsWindow.BackgroundColor = bg
fw = 60
fh = 40
cols = 7
rows = 4
Init()
For row = 1 To rows
oy = row * gh / (rows + 1)
For col = 1 To cols
ox = col * gw / (cols + 1)
k = k + 1
If Text.GetLength(alpha) < k Then
col = cols
row = rows
Else
flag = Text.GetSubText(alpha, k, 1)
x = ox - fw / 2
y = oy - fh / 2
ICS()
EndIf
EndFor
EndFor

Sub ICS
_x = x
_y = y
If flag = "A" Then
bc = "White"
width = fh / 2
height = fh
FillRectangle()
x = x + width
width = fw - width
height = fh / 2
bc = "Blue"
vertex = "bottom"
FillTriangle()
y = y + height
vertex = "top"
FillTriangle()
y = y - height
height = fh
width = width / 2
FillRectangle()
ElseIf flag = "B" Then
bc = "Red"
width = fw / 2 + fh / 4
height = fh
FillRectangle()
x = x + fh / 2
width = fw - fh / 2
height = fh / 2
vertex = "bottom"
FillTriangle()
y = y + height
vertex = "top"
FillTriangle()
ElseIf flag = "C" Then
bc = "Blue"
width = fw
height = fh
FillRectangle()
bc = "White"
y = y + fh / 5
height = fh * 3 / 5
FillRectangle()
bc = "Red"
y = y + fh / 5
height = fh / 5
FillRectangle()
ElseIf flag = "D" Then
bc = "Yellow"
width = fw
height = fh
FillRectangle()
bc = "Blue"
y = y + fh / 5
height = fh * 3 / 5
FillRectangle()
ElseIf flag = "E" Then
bc = "Blue"
width = fw
height = fh
FillRectangle()
bc = "Red"
y = y + fh / 2
height = fh / 2
FillRectangle()
ElseIf flag = "F" Then
bc = "White"
width = fw
height = fh
FillRectangle()
bc = "Red"
vertex = "top"
height = fh / 2
FillTriangle()
vertex = "bottom"
y = y + height
FillTriangle()
ElseIf flag = "G" Then
bc = "Yellow"
width = fw
height = fh
FillRectangle()
bc = "Blue"
width = fw / 6
x = x - width
For i = 1 To 3
x = x + width * 2
FillRectangle()
EndFor
ElseIf flag = "H" Then
bc = "White"
width = fw
height = fh
FillRectangle()
bc = "Red"
width = fw / 2
x = x + width
FillRectangle()
ElseIf flag = "I" Then
bc = "Yellow"
width = fw
height = fh
FillRectangle()
bc = "Black"
size = fh * 0.6
ox = x + fw / 2
oy = y + fh / 2
FillCircle()
ElseIf flag = "J" Then
bc = "Blue"
width = fw
height = fh
FillRectangle()
bc = "White"
y = y + fh / 3
height = fh / 3
FillRectangle()
ElseIf flag = "K" Then
bc = "Yellow"
width = fw
height = fh
FillRectangle()
bc = "Blue"
width = fw / 2
x = x + width
FillRectangle()
ElseIf flag = "L" Then
bc = "Yellow"
width = fw
height = fh
FillRectangle()
bc = "Black"
width = fw / 2
height = fh / 2
x = x + width
FillRectangle()
x = x - width
y = y + height
FillRectangle()
ElseIf flag = "M" Then
bc = "White"
width = fw
height = fh
FillRectangle()
bc = "Blue"
x = _x + w * fw
width = (1 - 2 * w) * fw
height = (0.5 - w) * fh
vertex = "bottom"
FillTriangle()
vertex = "top"
y = _y + fh - height
FillTriangle()
x = _x
y = _y + w * fh
width = (0.5 - w) * fw
height = (1 - 2 * w) * fh
vertex = "right"
FillTriangle()
vertex = "left"
x = _x + fw - width
FillTriangle()
ElseIf flag = "N" Then
bc = "Blue"
width = fw
height = fh
FillRectangle()
bc = "White"
width = fw / 4
height = fh / 4
fill = "False"
For j = 1 To 4
y = _y + (j - 1) * height
For i = 1 To 4
If fill Then
x = _x + (i - 1) * width
FillRectangle()
EndIf
fill = Not[fill]
EndFor
fill = Not[fill]
EndFor
ElseIf flag = "O" Then
bc = "Yellow"
width = fw
height = fh
FillRectangle()
bc = "Red"
vertex = "topright"
FillTriangle()
ElseIf flag = "P" Then
bc = "Blue"
width = fw
height = fh
FillRectangle()
bc = "White"
x = x + fw / 3
y = y + fh / 3
width = fw / 3
height = fh / 3
FillRectangle()
ElseIf flag = "Q" Then
bc = "Yellow"
width = fw
height = fh
FillRectangle()
ElseIf flag = "R" Then
bc = "Red"
width = fw
height = fh
FillRectangle()
bc = "Yellow"
y = y + fh * 2 / 5
height = fh / 5
FillRectangle()
width = fh / 5
height = fh
x = _x + (fw - width) / 2
y = _y
FillRectangle()
ElseIf flag = "S" Then
bc = "White"
width = fw
height = fh
FillRectangle()
bc = "Blue"
x = x + fw / 3
y = y + fh / 3
width = fw / 3
height = fh / 3
FillRectangle()
ElseIf flag = "T" Then
bc = "Red"
width = fw
height = fh
FillRectangle()
bc = "White"
x = x + fw / 3
width = fw / 3
FillRectangle()
bc = "Blue"
x = x + fw / 3
FillRectangle()
ElseIf flag = "U" Then
bc = "Red"
width = fw
height = fh
FillRectangle()
bc = "White"
width = fw / 2
height = fh / 2
x = x + width
FillRectangle()
x = x - width
y = y + height
FillRectangle()
ElseIf flag = "V" Then
bc = "Red"
width = fw
height = fh
FillRectangle()
bc = "White"
x = _x + w * fw
y = y - 1
width = (1 - 2 * w) * fw
height = (0.5 - w) * fh
vertex = "bottom"
FillTriangle()
vertex = "top"
y = _y + fh - height
FillTriangle()
x = _x
y = _y + w * fh
width = (0.5 - w) * fw
height = (1 - 2 * w) * fh
vertex = "right"
FillTriangle()
vertex = "left"
x = _x + fw - width
FillTriangle()
ElseIf flag = "W" Then
bc = "Blue"
width = fw
height = fh
FillRectangle()
bc = "White"
x = x + fw / 5
y = y + fh / 5
width = fw * 3 / 5
height = fh * 3 / 5
FillRectangle()
bc = "Red"
x = x + fw / 5
y = y + fh / 5
width = fw / 5
height = fh / 5
FillRectangle()
ElseIf flag = "X" Then
bc = "White"
width = fw
height = fh
FillRectangle()
bc = "Blue"
y = y + fh * 2 / 5
height = fh / 5
FillRectangle()
width = fh / 5
height = fh
x = _x + (fw - width) / 2
y = _y
FillRectangle()
ElseIf flag = "Y" Then
bc = "Yellow"
width = fw
height = fh
FillRectangle()
bc = "Red"
vertex = "bottomright"
FillTriangle()
For i = 4 To 1 Step -1
width = fw * i / 5
height = fh * i / 5
If Math.Remainder(i, 2) = 0 Then
bc = "Red"
Else
bc = "Yellow"
EndIf
x = _x
y = _y
vertex = "topleft"
FillTriangle()
If Math.Remainder(i, 2) = 0 Then
bc = "Yellow"
Else
bc = "Red"
EndIf
x = _x + fw * (5 - i) / 5
y = _y + fh * (5 - i) / 5
vertex = "bottomright"
FillTriangle()
EndFor
ElseIf flag = "Z" Then
bc = "Yellow"
width = fw
height = fh
FillRectangle()
bc = "Black"
vertex = "right"
width = fw / 2
FillTriangle()
bc = "Blue"
vertex = "left"
x = _x + width
FillTriangle()
bc = "Red"
vertex = "top"
width = fw
height = fh / 2
x = _x
y = _y + height
FillTriangle()
EndIf
x = _x
y = _y + fh * 1.1
DrawLetter()
EndSub

Sub DrawLetter
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.DrawText(x, y, flag)
EndSub

Sub FillCircle
SetAttribute()
GraphicsWindow.FillEllipse(ox - size / 2, oy - size / 2, size, size)
EndSub

Sub FillRectangle
SetAttribute()
GraphicsWindow.FillRectangle(x, y, width, height)
EndSub

Sub FillTriangle
SetAttribute()
If vertex = "top" Then
x1 = x + width / 2
y1 = y
x2 = x
y2 = y + height
x3 = x + width
y3 = y2
ElseIf vertex = "topleft" Then
x1 = x
y1 = y
x2 = x + width
y2 = y
x3 = x
y3 = y + height
ElseIf vertex = "topright" Then
x1 = x + width
y1 = y
x2 = x
y2 = y
x3 = x + width
y3 = y + height
ElseIf vertex = "bottom" Then
x1 = x + width / 2
y1 = y + height
x2 = x
y2 = y
x3 = x + width
y3 = y2
ElseIf vertex = "bottomright" Then
x1 = x + width
y1 = y + height
x2 = x + width
y2 = y
x3 = x
y3 = y + height
ElseIf vertex = "left" Then
x1 = x
y1 = y + height / 2
x2 = x + width
y2 = y
x3 = x + width
y3 = y + height
ElseIf vertex = "right" Then
x1 = x + width
y1 = y + height / 2
x2 = x
y2 = y
x3 = x
y3 = y + height
EndIf
GraphicsWindow.FillTriangle(x1, y1, x2, y2, x3, y3)
EndSub

Sub Init
Not = "False=True;True=False;"
alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
GraphicsWindow.FontName = "Trebuchet MS"
GraphicsWindow.FontSize = fh / 3
w = 0.1
EndSub

Sub SetAttribute
GraphicsWindow.BrushColor = bc
EndSub