Microsoft Small Basic

Program Listing: NCF628
' Flag of Brazil
' Version 0.21
' Copyright © 2016 Nonki Takahashi. The MIT License.

GraphicsWindow.Title = "Flag of Brazil"
Init()

' circle color
GraphicsWindow.BackgroundColor = color["Blue"]

' stars
DrawStars()

' ribon
cx = iw * 0.404
cy = iw * 0.680
r = iw * 0.393
w = iw * 0.023
GraphicsWindow.PenWidth = w
GraphicsWindow.PenColor = color["White"]
GraphicsWindow.DrawEllipse(cx - r, cy - r, 2 * r, 2 * r)

' text
txt = "ORDEM_ _E PROGRESSO"
tc = color["Green"] ' text color
r = r * 0.985
a = -8
gap = 0.7 * scale
fs = w * 0.9
GraphicsWindow.FontSize = fs
DrawRoundText()

' circle
w = iw * 0.093
size = iw * 0.394 + w / 2
GraphicsWindow.PenWidth = w
GraphicsWindow.PenColor = color["Yellow"]
GraphicsWindow.DrawEllipse(xo - size / 2, yo - size / 2, size, size)
width = iw * 0.3
GraphicsWindow.BrushColor = color["Yellow"]
GraphicsWindow.FillRectangle(0, 0, width, ih)
GraphicsWindow.FillRectangle(iw - width, 0, width, ih)

' diamond
width = iw * 0.63
height = iw * 0.406
GraphicsWindow.BrushColor = color["Green"]
GraphicsWindow.FillTriangle(width, 0, 0, height, 0, 0)
GraphicsWindow.FillTriangle(iw - width, 0, iw, height, iw, 0)
GraphicsWindow.FillTriangle(width, ih, 0, ih - height, 0, ih)
GraphicsWindow.FillTriangle(iw - width, ih, iw, ih - height, iw, ih)

Sub Init
scale = 1.5
iw = 598 * scale
ih = iw * 0.7
GraphicsWindow.Width = iw
GraphicsWindow.Height = ih
xo = iw / 2
yo = ih / 2
color = "Green=#009B3A;Yellow=#FEDF00;Blue=#002776;White=#FFFFFF;"
star[1] = "x=0.357;y=0.319;size=0.017;" ' 1 Canis Minor Procyon 1
star[2] = "x=0.39;y=0.381;size=0.01;" ' 2 Canis Major γ 4
star[3] = "x=0.373;y=0.391;size=0.017;" ' 2 Canis Major Sirius 1
star[4] = "x=0.351;y=0.408;size=0.013;" ' 2 Canis Major β 2
star[5] = "x=0.41;y=0.41;size=0.013;" ' 2 Canis Major ε 2
star[6] = "x=0.404;y=0.427;size=0.013;" ' 2 Canis Major δ 2
star[7] = "x=0.43;y=0.443;size=0.017;" ' 3 Carina Canopus 1
star[8] = "x=0.555;y=0.295;size=0.017;" ' 4 Vergo Spica 1
star[9] = "x=0.548;y=0.34;size=0.011;" ' 5 Hydra γ 2
star[10] = "x=0.434;y=0.356;size=0.013;" ' 5 Hydra Alphard 3
star[11] = "x=0.52;y=0.393;size=0.013;" ' 6 Crux β 1
star[12] = "x=0.482;y=0.393;size=0.013;" ' 6 Crux δ 3
star[13] = "x=0.5;y=0.378;size=0.013;" ' 6 Crux γ 2
star[14] = "x=0.491;y=0.406;size=0.010;" ' 6 Crux ε 4
star[15] = "x=0.5;y=0.428;size=0.017;" ' 6 Crux α 1
star[16] = "x=0.5;y=0.487;size=0.005;" ' 7 Octans σ 5
star[17] = "x=0.538;y=0.448;size=0.011;" ' 8 Triangulum Australe β 3
star[18] = "x=0.552;y=0.468;size=0.013;" ' 8 Triangulum Australe α 2
star[19] = "x=0.568;y=0.452;size=0.011" ' 8 Triangulum Australe γ 3
star[20] = "x=0.619;y=0.44;size=0.013;" ' 9 Scorpius λ 2
star[21] = "x=0.605;y=0.45;size=0.011" ' 9 Scorpius κ 3
star[22] = "x=0.588;y=0.48;size=0.011" ' 9 Scorpius ι 3
star[23] = "x=0.588;y=0.462;size=0.013" ' 9 Scorpius θ 2
star[24] = "x=0.587;y=0.447;size=0.011" ' 9 Scorpius μ 3
star[25] = "x=0.63;y=0.427;size=0.013;" ' 9 Scorpius ε 2
star[26] = "x=0.623;y=0.411;size=0.017;" ' 9 Scorpius Antares 1
star[27] = "x=0.647;y=0.412;size=0.011" ' 9 Scorpius β 3
' width/height [%] of each character in Arial font
GraphicsWindow.FontName = "Arial"
ratio = "32=56;33=61;34=76;35=84;36=84;37=117;38=100;39=52;40=61;"
ratio = ratio + "41=61;42=67;43=87;44=56;45=61;46=56;47=56;48=84;"
ratio = ratio + "49=84;50=84;51=84;52=84;53=84;54=84;55=84;56=84;"
ratio = ratio + "57=84;58=61;59=61;60=87;61=87;62=87;63=89;64=126;"
ratio = ratio + "65=100;66=100;67=100;68=100;69=95;70=89;71=106;"
ratio = ratio + "72=100;73=56;74=84;75=100;76=89;77=111;78=100;"
ratio = ratio + "79=106;80=95;81=106;82=100;83=95;84=89;85=100;86=95;"
ratio = ratio + "87=123;88=95;89=95;90=89;91=61;92=56;93=61;94=87;"
ratio = ratio + "95=84;96=61;97=84;98=89;99=84;100=89;101=84;102=61;"
ratio = ratio + "103=89;104=89;105=56;106=56;107=84;108=56;109=117;"
ratio = ratio + "110=89;111=89;112=89;113=89;114=67;115=84;116=61;"
ratio = ratio + "117=89;118=84;119=106;120=84;121=84;122=78;123=67;"
ratio = ratio + "124=56;125=67;126=87;160=56;161=61;162=84;163=84;"
ratio = ratio + "164=84;165=84;166=56;167=84;168=61;169=102;170=65;"
ratio = ratio + "171=84;172=87;173=28;174=102;175=83;176=68;177=83;"
ratio = ratio + "178=61;179=61;180=61;181=86;182=84;183=61;184=61;"
ratio = ratio + "185=61;186=65;187=84;188=112;189=112;190=112;191=89;"
ratio = ratio + "192=100;193=100;194=100;195=100;196=100;197=100;"
ratio = ratio + "198=128;199=100;200=95;201=95;202=95;203=95;204=56;"
ratio = ratio + "205=56;206=56;207=56;208=100;209=100;210=106;"
ratio = ratio + "211=106;212=106;213=106;214=106;215=87;216=106;"
ratio = ratio + "217=100;218=100;219=100;220=100;221=95;222=95;"
ratio = ratio + "223=89;224=84;225=84;226=84;227=84;228=84;229=84;"
ratio = ratio + "230=117;231=84;232=84;233=84;234=84;235=84;236=56;"
ratio = ratio + "237=56;238=56;239=56;240=89;241=89;242=89;243=89;"
ratio = ratio + "244=89;245=89;246=89;247=83;248=89;249=89;250=89;"
ratio = ratio + "251=89;252=89;253=84;254=89;255=84;"
EndSub

Sub DrawStars
n = Array.GetItemCount(star)
GraphicsWindow.BrushColor = color["White"]
For j = 1 To n
size = iw * star[j]["size"]
x = iw * star[j]["x"]
y = iw * star[j]["y"]
DrawStar()
'GraphicsWindow.FillEllipse(x - size / 2, y - size / 2, size, size)
EndFor
EndSub

Sub DrawStar
' param x, y - center of the star
' param size - size of the star
θ = Math.GetRadians(18)
r = size / 2
x1 = x + 0
y1 = y - r
x2 = x - r * Math.Sin(θ)
y2 = y
x3 = x + r * Math.Sin(θ)
y3 = y
For i = 1 To 5
angle = (i - 1) * 72
DrawRotateTriangle()
EndFor
EndSub

Sub DrawRotateTriangle
_a = Math.GetRadians(angle)
rx1 = x + Math.Cos(_a) * (x1 - x) - Math.Sin(_a) * (y1 - y)
ry1 = y + Math.Sin(_a) * (x1 - x) + Math.Cos(_a) * (y1 - y)
rx2 = x + Math.Cos(_a) * (x2 - x) - Math.Sin(_a) * (y2 - y)
ry2 = y + Math.Sin(_a) * (x2 - x) + Math.Cos(_a) * (y2 - y)
rx3 = x + Math.Cos(_a) * (x3 - x) - Math.Sin(_a) * (y3 - y)
ry3 = y + Math.Sin(_a) * (x3 - x) + Math.Cos(_a) * (y3 - y)
GraphicsWindow.FillTriangle(rx1, ry1, rx2, ry2, rx3, ry3)
EndSub

Sub DrawRoundText
' param txt - text array
' param tc - text color
' param cx, cy - center position
' param r - radius
' param a - angle
' param gap - pixels between characters

' calculate width of each text in pixel
tw = 2 * Math.Pi * r ' full text width [pixel]
len = Text.GetLength(txt)

' draw each character
GraphicsWindow.BrushColor = tc
fs0 = fs
For p = 1 To len
_a = Math.GetRadians(a)
ch[p] = Text.GetSubText(txt, p, 1)
If ch[p] = "_" Then
fs0 = fs * 0.9
Else
fw[p] = fs0 * ratio[Text.GetCharacterCode(ch[p])] / 100
GraphicsWindow.FontSize = fs0
x = cx + (r + fs0 / 3) * Math.Sin(_a) - fw[p] / 2
y = cy - (r + fs0 / 3) * Math.Cos(_a) - fs0 / 2
shp = Shapes.AddText(ch[p])
Shapes.Move(shp, x, y)
Shapes.Rotate(shp, a)
fs0 = fs
a = a + 360 * (fw[p] + gap) / tw
EndIf
EndFor
EndSub