Microsoft Small Basic

Program Listing: BVR189-0
' Kappa Cygnid
' Version 0.2
' はくちょう座κ流星群
' Copyright © 2016-2017 Nonki Takahshi. The MIT License.
' Program ID BVR189-0
'
' Reference:
' http://en.wikipedia.org/wiki/List_of_stars_in_Cygnus

title = "Kappa Cygnid"
r = 430 ' [px]
delay = 100 ' [ms]
Init()
Cal_Init()
InitStars()
ra = radiant["ra"]
dec = radiant["dec"]
Mapping()
rot = ra
tilt = dec
GraphicsWindow.Title = title + " RA=" + rot + "h Dec=" + tilt + "°"
DrawRA()
DrawDec()
Shapes_Init()
scale = 1
iMin = 1
iMax = 107
Shapes_Add()
DrawStars()
DrawCalendar()
DrawMeteorShower()
While "True"
If keyDown Then
If key = "Right" Then
rot = rot + 0.25
If 24 <= rot Then
rot = rot - 24
EndIf
ElseIf key = "Left" Then
rot = rot - 0.25
If rot < 0 Then
rot = rot + 24
EndIf
ElseIf key = "Up" Then
If tilt <= 85 Then
tilt = tilt + 5
EndIf
ElseIf key = "Down" Then
If -85 <= tilt Then
tilt = tilt - 5
EndIf
ElseIf key = "Add" Then
r = r * 1.2
ElseIf key = "Subtract" Then
r = r / 1.2
EndIf
GraphicsWindow.Title = title + " RA=" + rot + "h Dec=" + tilt + "°"
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.FillRectangle(0, 0, gw, gh)
DrawRA()
DrawDec()
DrawStars()
keyDown = "False"
EndIf
Program.Delay(delay)
EndWhile

Sub Init
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
GraphicsWindow.BackgroundColor = "Black"
ox = gw / 2
oy = gh * 0.4
rot = 0 ' rotation
tilt = 0
monthX = 40
monthY = 20
calendarX = gw - 270
calendarY = gh - 150
year = 2017
month = 8
GraphicsWindow.KeyDown = OnKeyDown
EndSub

Sub OnKeyDown
keyDown = "True"
key = GraphicsWindow.LastKey
EndSub

Sub DrawRA
GraphicsWindow.PenWidth = 1
GraphicsWindow.PenColor = "#666666"
For ra = 0 To 23
For dec = -90 To 90 Step 5
Mapping()
If -90 < dec Then
DrawLine()
EndIf
xLast = x
yLast = y
zLast = z
EndFor
EndFor
EndSub

Sub DrawDec
GraphicsWindow.PenWidth = 1
GraphicsWindow.PenColor = "#666666"
For dec = -80 To 80 Step 10
For ra = 0 To 24 Step 0.2
Mapping()
If 0 < ra Then
DrawLine()
EndIf
xLast = x
yLast = y
zLast = z
EndFor
EndFor
EndSub

Sub DrawLine
visible = "False"
If 0 <= z And 0 <= zLast Then
If 0 <= x And x < gw And 0 <= y And y < gh Then
visible = "True"
ElseIf 0 <= xLast And xLast < gw And 0 <= yLast And yLast < gh Then
visible = "True"
EndIf
EndIf
If visible Then
GraphicsWindow.DrawLine(xLast, yLast, x, y)
EndIf
EndSub

Sub DrawStars
GraphicsWindow.PenWidth = 0
GraphicsWindow.BrushColor = "White"
n = Array.GetItemCount(star)
index = Array.GetAllIndices(star)
For i = 1 To n
ra = star[index[i]]["ra"]
dec = star[index[i]]["dec"]
Mapping()
If ell[index[i]] <> "" Then
Shapes.Remove(ell[index[i]])
ell[index[i]] = ""
EndIf
If 0 <= z Then
mag = star[index[i]]["mag"]
d = 16 / mag
ell[index[i]] = Shapes.AddEllipse(d, d)
Shapes.Move(ell[index[i]], x - d / 2, y - d / 2)
EndIf
EndFor
GraphicsWindow.PenWidth = 1
GraphicsWindow.PenColor = "Blue"
n = Array.GetItemCount(edge)
index = Array.GetAllIndices(edge)
For i = 1 To n
e = edge[index[i]]
m = Text.GetIndexOf(e, "-")
ra = star[Text.GetSubText(e, 1, m - 1)]["RA"]
dec = star[Text.GetSubText(e, 1, m - 1)]["Dec"]
Mapping()
x1 = x
y1 = y
z1 = z
ra = star[Text.GetSubTextToEnd(e, m + 1)]["RA"]
dec = star[Text.GetSubTextToEnd(e, m + 1)]["Dec"]
Mapping()
x2 = x
y2 = y
z2 = z
If connect[index[i]] <> "" Then
Shapes.Remove(connect[index[i]])
connect[index[i]] = ""
EndIf
visible = "False"
If 0 <= z1 And 0 <= z2 Then
If 0 <= x1 And x1 <= gw And 0 <= y1 And y1 <= gh Then
visible = "True"
ElseIf 0 <= x2 And x2 <= gw And 0 <= y2 And y2 <= gh Then
visible = "True"
EndIf
If visible Then
connect[index[i]] = Shapes.AddLine(x1, y1, x2, y2)
EndIf
EndIf
EndFor
EndSub

Sub DrawMeteorShower
ra = radiant["RA"]
dec = radiant["Dec"]
Mapping()
rx = x
ry = y
GraphicsWindow.PenColor = "White"
While "True"
Program.Delay(2000)
angle = Math.GetRandomNumber(360)
_a = Math.GetRadians(angle)
r1 = Math.GetRandomNumber(100) + 50
r2 = r1 * 2.5
x1 = rx + r1 * Math.Sin(_a)
y1 = ry - r1 * Math.Cos(_a)
x2 = rx + r2 * Math.Sin(_a)
y2 = ry - r2 * Math.Cos(_a)
meteor = Shapes.AddLine(x1, y1, x2, y2)
For op = 100 To 0 Step -5
Shapes.SetOpacity(meteor, op)
Program.Delay(50)
EndFor
Shapes.Remove(meteor)
EndWhile
EndSub

Sub DrawCalendar
GraphicsWindow.BrushColor = "White"
If silverlight Then
Program.Delay(msWait)
EndIf
GraphicsWindow.FontSize = 30
txt = Shapes.AddText(months[month])
Shapes.Move(txt, monthX, monthY)
If silverlight Then
Program.Delay(msWait)
EndIf
GraphicsWindow.FontSize = 40
txt = Shapes.AddText(year)
Shapes.Move(txt, monthX, monthY + 30)
sBuf = year + "," + month
Command_GetArgs()
iYear = sArg[1]
if iYear = "" Then
Goto lEnd
Endif
If Math.Remainder(iYear, 4) = 0 And Math.Remainder(iYear, 100) > 0 Or Math.Remainder(iYear, 400) = 0 Then
iDoM[2] = iDoM[2] + 1
Endif
iNoL = Math.Floor((iYear - 1) / 4) - Math.Floor((iYear - 1) / 100) + Math.Floor((iYear - 1) / 400) ' number of leap year
iWoY = Math.Remainder((iYear + iNoL), 7) ' week of year
iMonth = sArg[2]
If iMonth = "" Then
iM0 = 1
iM1 = 12
Else
iM0 = iMonth
iM1 = iMonth
Endif
iDoY = 0 ' days of year
iNoM = 1 ' number of month
For iM = iM0 To iM1
While iNoM < iM
iDoY = iDoY + iDoM[iNoM]
iNoM = iNoM + 1
EndWhile
Cal_DrawMonth()
EndFor
lEnd:
EndSub

Sub Mapping
' param ra - right asension [h]
' param rot - rotation [h]
' param dec - declination [deg]
' param tilt - tilt [deg]
' param r - radius [px]
' return x, y - position in the graphics window [px]
' return z - visible if 0 <= z
If Text.IsSubText(ra, " ") Then
_ra = Text.GetSubText(ra, 1, 2)
_ra = _ra + Text.GetSubText(ra, 4, 2) / 60
_ra = _ra + Text.GetSubText(ra, 7, 5) / 3600
ra = _ra
EndIf
If Text.IsSubText(dec, " ") Then
_dec = Text.GetSubText(dec, 2, 2)
_dec = _dec + Text.GetSubText(dec, 5, 2) / 60
_dec = _dec + Text.GetSubText(dec, 8, 5) / 3600
_dec = _dec * Text.Append(Text.GetSubText(dec, 1, 1), "1")
dec = _dec
EndIf
φ = Math.GetRadians((ra - rot) * 15)
θ = Math.GetRadians(dec)
x = ox - r * Math.Sin(φ) * Math.Cos(θ)
y = oy - r * Math.Sin(θ)
z = r * Math.Cos(φ) * Math.Cos(θ)
If tilt <> 0 Then
_z = z
_y = y - oy
τ = Math.GetRadians(tilt)
z = Math.Cos(τ) * _z - Math.Sin(τ) * _y
y = oy + Math.Sin(τ) * _z + Math.Cos(τ) * _y
EndIf
EndSub

Sub InitStars
' Initialize stars in Cygnus
' index: Flamsteed designation
' RA (Right ascension), Dec (Declination), Mag (Apparent magnitude)
star["Deneb"] = "ra=20 41 25.91;dec=+45 16 49.2;mag=1.25;fd=50;"
star["γ Cyg"] = "ra=20 22 13.70;dec=+40 15 24.1;mag=2.23;fd=37;"
star["ε Cyg"] = "ra=20 46 12.43;dec=+33 58 10.0;mag=2.48;fd=53;"
star["δ Cyg"] = "ra=19 44 58.44;dec=+45 07 50.5;mag=2.86;fd=18;"
star["Albireo A"] = "ra=19 30 43.29;dec=+27 57 34.9;mag=3.05;fd=6;"
star["ζ Cyg"] = "ra=21 12 56.18;dec=+30 13 37.5;mag=3.21;fd=64;"
star["ξ Cyg"] = "ra=21 04 55.86;dec=+43 55 40.3;mag=3.72;fd=62;"
star["τ Cyg"] = "ra=21 14 47.35;dec=+38 02 39.6;mag=3.74;fd=65;"
star["ι Cyg"] = "ra=19 29 42.34;dec=+51 43 46.1;mag=3.76;fd=10;"
star["κ Cyg"] = "ra=19 17 06.11;dec=+53 22 05.4;mag=3.80;fd=1;"
star["ο1 Cyg"] = "ra=20 13 37.90;dec=+46 44 28.8;mag=3.80;fd=31;"
star["η Cyg"] = "ra=19 56 18.40;dec=+35 05 00.6;mag=3.89;fd=21;"
star["ν Cyg"] = "ra=20 57 10.41;dec=+41 10 01.9;mag=3.94;fd=58;"
star["ο2 Cyg"] = "ra=20 15 28.32;dec=+47 42 51.1;mag=3.96;fd=32;"
star["ρ Cyg"] = "ra=21 33 58.87;dec=+45 35 31.4;mag=3.98;fd=73;"
star["41 Cyg"] = "ra=20 29 23.73;dec=+30 22 06.8;mag=4.01;fd=41;"
star["52 Cyg"] = "ra=20 45 39.76;dec=+30 43 10.8;mag=4.22;fd=52;"
star["σ Cyg"] = "ra=21 17 24.95;dec=+39 23 40.9;mag=4.22;fd=67;"
star["π2 Cyg"] = "ra=21 46 47.61;dec=+49 18 34.5;mag=4.23;fd=81;"
star["33 Cyg"] = "ra=20 13 23.80;dec=+56 34 03.1;mag=4.28;fd=33;"
star["υ Cyg"] = "ra=21 17 55.07;dec=+34 53 48.8;mag=4.41;fd=66;"
star["39 Cyg"] = "ra=20 23 51.60;dec=+32 11 24.7;mag=4.43;fd=39;"
star["θ Cyg"] = "ra=19 36 26.54;dec=+50 13 13.7;mag=4.49;fd=13;"
star["λ Cyg"] = "ra=20 47 24.53;dec=+36 29 26.7;mag=4.53;fd=54;"
star["63 Cyg"] = "ra=21 06 36.09;dec=+47 38 54.3;mag=4.56;fd=63;"
star["47 Cyg A"] = "ra=20 33 54.19;dec=+35 15 03.1;mag=4.61;fd=47;"
star["φ Cyg"] = "ra=19 39 22.60;dec=+30 09 11.6;mag=4.68;fd=12;"
star["π1 Cyg"] = "ra=21 42 05.66;dec=+51 11 22.7;mag=4.69;fd=80;"
star["μ1 Cyg"] = "ra=21 44 08.59;dec=+28 44 33.4;mag=4.69;fd=78;"
star["8 Cyg"] = "ra=19 31 46.32;dec=+34 27 10.7;mag=4.74;fd=8;"
star["59 Cyg"] = "ra=20 59 49.55;dec=+47 31 15.4;mag=4.74;fd=59;"
star["P Cyg"] = "ra=20 17 47.20;dec=+38 01 58.6;mag=4.77;fd=34;"
star["30 Cyg"] = "ra=20 13 18.04;dec=+46 48 56.4;mag=4.80;fd=30;"
star["57 Cyg"] = "ra=20 53 14.75;dec=+44 23 14.2;mag=4.80;fd=57;"
star["55 Cyg"] = "ra=20 48 56.29;dec=+46 06 50.9;mag=4.81;fd=55;"
star["72 Cyg"] = "ra=21 34 46.48;dec=+38 32 01.8;mag=4.87;fd=72;"
star["15 Cyg"] = "ra=19 44 16.55;dec=+37 21 15.4;mag=4.89;fd=15;"
star["ψ Cyg"] = "ra=19 55 37.82;dec=+52 26 20.5;mag=4.91;fd=24;"
star["28 Cyg"] = "ra=20 09 25.62;dec=+36 50 22.5;mag=4.93;fd=28;"
star["29 Cyg"] = "ra=20 14 31.98;dec=+36 48 22.1;mag=4.93;fd=29;"
star["T Cyg"] = "ra=20 47 10.72;dec=+34 22 26.8;mag=4.93;"
star["ω1 Cyg"] = "ra=20 30 03.53;dec=+48 57 05.6;mag=4.94;fd=45;"
star["22 Cyg"] = "ra=19 55 51.76;dec=+38 29 12.1;mag=4.95;fd=22;"
star["HD 189276"] = "ra=19 55 55.39;dec=+58 50 45.7;mag=4.98;"
star["2 Cyg"] = "ra=19 24 07.57;dec=+29 37 16.7;mag=4.99;fd=2;"
star["17 Cyg"] = "ra=19 46 25.58;dec=+33 43 43.3;mag=5.00;fd=17;"
star["20 Cyg"] = "ra=19 50 37.73;dec=+52 59 17.4;mag=5.03;fd=20;"
star["68 Cyg"] = "ra=21 18 27.18;dec=+43 56 45.5;mag=5.04;fd=68;"
star["74 Cyg"] = "ra=21 36 56.98;dec=+40 24 48.6;mag=5.04;fd=74;"
star["26 Cyg"] = "ra=20 01 21.55;dec=+50 06 16.8;mag=5.06;fd=26;"
star["56 Cyg"] = "ra=20 50 04.83;dec=+44 03 32.3;mag=5.06;fd=56;"
star["75 Cyg"] = "ra=21 40 11.06;dec=+43 16 25.7;mag=5.09;fd=75;"
star["Albireo B"] = "ra=19 30 45.40;dec=+27 57 55.0;mag=5.12;fd=6;"
star["23 Cyg"] = "ra=19 53 17.37;dec=+57 31 24.5;mag=5.14;fd=23;"
star["35 Cyg"] = "ra=20 18 39.07;dec=+34 58 58.0;mag=5.14;fd=35;"
star["25 Cyg"] = "ra=19 59 55.20;dec=+37 02 34.4;mag=5.15;fd=25;"
star["4 Cyg"] = "ra=19 26 09.12;dec=+36 19 04.3;mag=5.17;fd=4;"
star["19 Cyg"] = "ra=19 50 33.99;dec=+38 43 19.8;mag=5.18;fd=19;"
star["61 Cyg A"] = "ra=21 06 50.84;dec=+38 44 29.4;mag=5.20;fd=61;"
star["71 Cyg"] = "ra=21 29 26.91;dec=+46 32 25.2;mag=5.22;fd=71;"
star["70 Cyg"] = "ra=21 27 21.36;dec=+37 07 00.5;mag=5.30;fd=70;"
star["27 Cyg"] = "ra=20 06 21.93;dec=+35 58 24.7;mag=5.38;fd=27;"
star["60 Cyg"] = "ra=21 01 10.92;dec=+46 09 20.8;mag=5.38;fd=60;"
star["9 Cyg"] = "ra=19 34 50.92;dec=+29 27 46.5;mag=5.39;fd=9;"
star["14 Cyg"] = "ra=19 39 26.47;dec=+42 49 05.6;mag=5.41;fd=14;"
star["51 Cyg"] = "ra=20 42 12.63;dec=+50 20 24.1;mag=5.41;fd=51;"
star["ω2 Cyg"] = "ra=20 31 18.81;dec=+49 13 13.3;mag=5.44;fd=46;"
star["49 Cyg"] = "ra=20 41 02.60;dec=+32 18 28.0;mag=5.51;fd=49;"
star["49 Cyg"] = "ra=20 41 02.54;dec=+32 18 26.3;mag=5.53;fd=49;"
star["V1942 Cyg"] = "ra=22 02 56.68;dec=+44 38 59.8;mag=5.57;"
star["36 Cyg"] = "ra=20 18 28.63;dec=+36 59 59.1;mag=5.58;fd=36;"
star["V389 Cyg"] = "ra=21 08 38.87;dec=+30 12 20.5;mag=5.60;"
star["V1768 Cyg"] = "ra=20 04 36.18;dec=+32 13 07.0;mag=5.62;"
star["40 Cyg"] = "ra=20 27 34.27;dec=+38 26 25.9;mag=5.63;fd=40;"
star["V380 Cyg"] = "ra=19 50 37.33;dec=+40 35 59.2;mag=5.68;"
star["V2140 Cyg"] = "ra=20 55 49.81;dec=+47 25 03.6;mag=5.68;"
star["79 Cyg"] = "ra=21 43 25.63;dec=+38 17 01.0;mag=5.69;fd=79;"
star["7 Cyg"] = "ra=19 27 25.97;dec=+52 19 13.8;mag=5.73;fd=7;"
star["Gl 777"] = "ra=20 03 36.95;dec=+29 53 53.1;mag=5.73;"
star["43 Cyg"] = "ra=20 27 02.21;dec=+49 22 59.6;mag=5.73;fd=43;"
star["77 Cyg"] = "ra=21 42 22.94;dec=+41 04 37.3;mag=5.73;fd=77;"
star["DT Cyg"] = "ra=21 06 30.24;dec=+31 11 04.8;mag=5.77;"
star["V2015 Cyg"] = "ra=20 33 54.84;dec=+46 41 37.9;mag=5.78;"
star["V2119 Cyg"] = "ra=20 23 44.37;dec=+37 28 35.2;mag=5.87;"
star["V1762 Cyg"] = "ra=19 08 25.88;dec=+52 25 33.1;mag=5.88;"
star["V1143 Cyg"] = "ra=19 38 41.15;dec=+54 58 24.2;mag=5.89;"
star["V1334 Cyg"] = "ra=21 19 22.18;dec=+38 14 14.9;mag=5.89;"
star["42 Cyg"] = "ra=20 29 20.39;dec=+36 27 17.0;mag=5.90;fd=42;"
star["69 Cyg"] = "ra=21 25 47.02;dec=+36 40 02.7;mag=5.93;fd=69;"
star["W Cyg"] = "ra=21 36 02.44;dec=+45 22 28.5;mag=5.96;"
star["V460 Cyg"] = "ra=21 42 01.08;dec=+35 30 36.7;mag=5.98;"
star["16 Cyg A"] = "ra=19 41 49.09;dec=+50 31 31.6;mag=5.99;fd=16;"
star["V1743 Cyg"] = "ra=19 33 41.60;dec=+49 15 44.4;mag=6.00;"
star["11 Cyg"] = "ra=19 35 48.30;dec=+36 56 40.4;mag=6.03;fd=11;"
star["61 Cyg B"] = "ra=21 06 52.19;dec=+38 44 03.9;mag=6.05;fd=61;"
star["V2130 Cyg"] = "ra=20 39 33.31;dec=+40 34 46.8;mag=6.07;"
star["76 Cyg"] = "ra=21 41 34.27;dec=+40 48 19.2;mag=6.07;fd=76;"
star["V1339 Cyg"] = "ra=21 42 08.35;dec=+45 45 56.7;mag=6.11;"
star["μ2 Cyg"] = "ra=21 44 08.46;dec=+28 44 34.5;mag=6.12;fd=78;"
star["V2093 Cyg"] = "ra=19 50 46.87;dec=+37 49 34.7;mag=6.13;"
star["V2100 Cyg"] = "ra=19 59 15.34;dec=+52 03 20.5;mag=6.14;"
star["CP Cyg"] = "ra=21 37 27.88;dec=+44 41 47.8;mag=6.19;"
star["V1619 Cyg"] = "ra=21 51 04.97;dec=+39 32 11.9;mag=6.20;"
star["44 Cyg"] = "ra=20 30 59.23;dec=+36 56 09.1;mag=6.21;fd=44;"
star["16 Cyg"] = "ra=19 41 52.10;dec=+50 31 04.5;mag=6.25;fd=16;"
star["V819 Cyg"] = "ra=19 53 01.25;dec=+47 48 27.9;mag=6.30;"
star["48 Cyg"] = "ra=20 37 31.77;dec=+31 34 21.1;mag=6.32;fd=48;"
star["V2136 Cyg"] = "ra=20 49 54.64;dec=+46 39 40.8;mag=6.33;"
star["V1817 Cyg"] = "ra=19 31 13.56;dec=+55 43 54.8;mag=6.37;"
star["V2090 Cyg"] = "ra=19 44 38.17;dec=+34 24 51.0;mag=6.39;"
star["V2173 Cyg"] = "ra=21 57 02.20;dec=+48 40 07.0;mag=6.42;"
star["V1351 Cyg"] = "ra=19 42 04.13;dec=+55 27 47.9;mag=6.42;"
star["V1765 Cyg"] = "ra=19 48 50.60;dec=+33 26 14.3;mag=6.42;"
star["V1773 Cyg"] = "ra=20 18 49.67;dec=+46 19 20.0;mag=6.46;"
star["HD 203857"] = "ra=21 23 48.39;dec=+37 21 05.4;mag=6.46;"
star["X Cyg"] = "ra=20 43 24.20;dec=+35 35 16.1;mag=6.48;"
star["V1276 Cyg"] = "ra=19 42 49.10;dec=+29 19 54.0;mag=6.49;"
star["V1584 Cyg"] = "ra=20 19 56.04;dec=+46 50 14.3;mag=6.49;"
star["HD 185269"] = "ra=19 37 11.74;dec=+28 29 59.5;mag=6.67;"
star["HD 197037"] = "ra=20 39 33s;dec=+42 14 55″;mag=6.81;"
edge = "1=Deneb-γ Cyg;2=γ Cyg-ε Cyg;3=ε Cyg-ζ Cyg;4=ζ Cyg-μ1 Cyg;"
edge = edge + "5=γ Cyg-δ Cyg;6=δ Cyg-θ Cyg;7=θ Cyg-ι Cyg;8=ι Cyg-κ Cyg;"
edge = edge + "9=γ Cyg-η Cyg;10=η Cyg-Albireo A;"
radiant = "ra=19 00 00.00;dec=+55 00 00.0;"
EndSub

Sub Cal_Init
' Calendar | Initialize days of month
WQ = Text.GetCharacter(34)
CRLF = Text.GetCharacter(13) + Text.GetCharacter(10)
iDoM = "1=31;2=28;3=31;4=30;5=31;6=30;7=31;8=31;9=30;10=31;11=30;12=31;"
months = "1=January;2=February;3=March;4=April;5=May;6=June;7=July;"
months = months + "8=August;9=September;10=October;11=November;12=December;"
symbols = "1=♑;2=♒;3=♓;4=♈;5=♉;6=♊;7=♋;8=♌;9=♍;10=♎;11=♏;12=♐;"
EndSub

Sub Cal_DrawMonth
' Calendar | Print month
' param iM - month
' param iDoY - days of year
' param iWoY - week of year
If silverlight Then
Program.Delay(msWait)
EndIf
GraphicsWindow.FontSize = 16
GraphicsWindow.FontName = "Consolas"
iW = Math.Remainder((iDoY + iWoY), 7)
line = "SUN MON TUE WED THU FRI SAT" + CRLF
iWoM = 0
While iWoM < iW
line = line + " "
iWoM = iWoM + 1
EndWhile
For iD = 1 To iDoM[iM]
If iD < 10 Then
line = line + " " + iD + " "
Else
line = line + " " + iD + " "
EndIf
If Math.Remainder(iWoM, 7) = 6 Then
line = line + CRLF
EndIf
iWoM = iWoM + 1
EndFor
If Math.Remainder(iWoM, 7) > 0 Then
line = line + CRLF
EndIf
cal = Shapes.AddText(line)
Shapes.Move(cal, calendarX, calendarY)
EndSub

Sub Command_GetArgs
' Command line | Get arguments
' param sBuf - input buffer
' return sArg[] - arguments
' return iN - number of arguments
iP = 1 ' buffer pointer
iN = 1 ' number of args
iC = Text.GetIndexOf(sBuf, ",") ' index of comma
While iC > iP
sArg[iN] = Text.GetSubText(sBuf, iP, iC - iP)
iP = iC + 1
iN = iN + 1
iC = Text.GetIndexOf(sBuf, ",")
EndWhile
iE = Text.GetLength(sBuf) + 1 ' end of buffer
sArg[iN] = Text.GetSubText(sBuf, iP, iE - iP)
EndSub

Sub Math_CartesianToPolar
' Math | convert cartesian coodinate to polar coordinate
' param x, y - cartesian coordinate
' return r, a - polar coordinate
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 Then
a = 0
Else
a = Math.ArcTan(y / x) * 180 / Math.Pi
EndIf
If x < 0 Then
a = a + 180
ElseIf x > 0 And y < 0 Then
a = a + 360
EndIf
EndSub

Sub SB_RotateWorkaround
' Small Basic | Rotate workaround for Silverlight
' param shp - current shape
' param x, y - original coordinate
' param alpha - angle [radian]
' returns x, y - workaround coordinate
If shp["func"] = "tri" Then
x1 = -Math.Floor(shp["x3"] / 2)
y1 = -Math.Floor(shp["y3"] / 2)
ElseIf shp["func"] = "line" Then
x1 = -Math.Floor(Math.Abs(shp["x1"] - shp["x2"]) / 2)
y1 = -Math.Floor(Math.Abs(shp["y1"] - shp["y2"]) / 2)
EndIf
ox = x - x1
oy = y - y1
x = x1 * Math.Cos(alpha) - y1 * Math.Sin(alpha) + ox
y = x1 * Math.Sin(alpha) + y1 * Math.Cos(alpha) + oy
EndSub

Sub SB_Workaround
' Small Basic | Workaround for Silverlight
' returns silverlight - "True" if in remote
color = GraphicsWindow.GetPixel(0, 0)
If Text.GetLength(color) > 7 Then
silverlight = "True"
msWait = 300
Else
silverlight = "False"
EndIf
EndSub

Sub Shapes_Add
' Shapes | add shapes as shapes data
' param iMin, iMax - shape indices to add
' param shape - array of shapes
' param scale - 1 if same scale
' return shWidth, shHeight - total size of shapes
' return shAngle - current angle of shapes
Stack.PushValue("local", i)
Stack.PushValue("local", x)
Stack.PushValue("local", y)
Shapes_CalcWidthAndHeight()
s = scale
For i = iMin To iMax
shp = shape[i]
GraphicsWindow.PenWidth = shp["pw"] * s
If shp["pw"] > 0 Then
GraphicsWindow.PenColor = shp["pc"]
EndIf
If Text.IsSubText("rect|ell|tri|text", shp["func"]) Then
GraphicsWindow.BrushColor = shp["bc"]
EndIf
If shp["func"] = "rect" Then
shp["obj"] = Shapes.AddRectangle(shp["width"] * s, shp["height"] * s)
ElseIf shp["func"] = "ell" Then
shp["obj"] = Shapes.AddEllipse(shp["width"] * s, shp["height"] * s)
ElseIf shp["func"] = "tri" Then
shp["obj"] = Shapes.AddTriangle(shp["x1"] * s, shp["y1"] * s, shp["x2"] * s, shp["y2"] * s, shp["x3"] * s, shp["y3"] * s)
ElseIf shp["func"] = "line" Then
shp["obj"] = Shapes.AddLine(shp["x1"] * s, shp["y1"] * s, shp["x2"] * s, shp["y2"] * s)
ElseIf shp["func"] = "text" Then
If silverlight Then
fs = Math.Floor(shp["fs"] * 0.9)
Else
fs = shp["fs"]
EndIf
GraphicsWindow.FontSize = fs * s
GraphicsWindow.FontName = shp["fn"]
shp["obj"] = Shapes.AddText(shp["text"])
EndIf
x = shp["x"]
y = shp["y"]
shp["rx"] = x
shp["ry"] = y
If silverlight And Text.IsSubText("tri|line", shp["func"]) Then
alpha = Math.GetRadians(shp["angle"])
SB_RotateWorkaround()
shp["wx"] = x
shp["wy"] = y
EndIf
Shapes.Move(shp["obj"], shX + x * s, shY + y * s)
If Text.IsSubText("rect|ell|tri|text", shp["func"]) And (shp["angle"] <> 0) And (shp["angle"] <> "") Then
Shapes.Rotate(shp["obj"], shp["angle"])
EndIf
shape[i] = shp
EndFor
shAngle = 0
y = Stack.PopValue("local")
x = Stack.PopValue("local")
i = Stack.PopValue("local")
EndSub

Sub Shapes_CalcWidthAndHeight
' Shapes | Calculate total width and height of shapes
' param iMin, iMax - shape indices to add
' return shWidth, shHeight - total size of shapes
For i = iMin To iMax
shp = shape[i]
If shp["func"] = "tri" Or shp["func"] = "line" Then
xmin = shp["x1"]
xmax = shp["x1"]
ymin = shp["y1"]
ymax = shp["y1"]
If shp["x2"] < xmin Then
xmin = shp["x2"]
EndIf
If xmax < shp["x2"] Then
xmax = shp["x2"]
EndIf
If shp["y2"] < ymin Then
ymin = shp["y2"]
EndIf
If ymax < shp["y2"] Then
ymax = shp["y2"]
EndIf
If shp["func"] = "tri" Then
If shp["x3"] < xmin Then
xmin = shp["x3"]
EndIf
If xmax < shp["x3"] Then
xmax = shp["x3"]
EndIf
If shp["y3"] < ymin Then
ymin = shp["y3"]
EndIf
If ymax < shp["y3"] Then
ymax = shp["y3"]
EndIf
EndIf
shp["width"] = xmax - xmin
shp["height"] = ymax - ymin
EndIf
If i = 1 Then
shWidth = shp["x"] + shp["width"]
shHeight = shp["y"] + shp["height"]
Else
If shWidth < shp["x"] + shp["width"] Then
shWidth = shp["x"] + shp["width"]
EndIf
If shHeight < shp["y"] + shp["height"] Then
shHeight = shp["y"] + shp["height"]
EndIf
EndIf
shape[i] = shp
EndFor
EndSub

Sub Shapes_Init
' Shapes | Initialize shapes data
' return shX, shY - current position of shapes
' return shape - array of shapes
shX = 60 ' x offset
shY = 131 ' y offset
shape = ""
shape[1] = "func=tri;x=201;y=38;x1=9;y1=0;x2=0;y2=78;x3=19;y3=78;angle=22;bc=#F0F0F0;pw=0;"
shape[2] = "func=tri;x=10;y=126;x1=9;y1=0;x2=0;y2=78;x3=19;y3=78;angle=290;bc=#F0F0F0;pw=0;"
shape[3] = "func=ell;x=44;y=151;width=68;height=30;angle=325;bc=#F0F0F0;pw=0;"
shape[4] = "func=ell;x=137;y=105;width=68;height=30;angle=352;bc=#F0F0F0;pw=0;"
shape[5] = "func=tri;x=114;y=126;x1=22;y1=0;x2=0;y2=66;x3=45;y3=66;angle=145;bc=#F0F0F0;pw=0;"
shape[6] = "func=ell;x=147;y=178;width=15;height=17;bc=#F0F0F0;pw=0;"
shape[7] = "func=rect;x=137;y=150;width=15;height=38;angle=329;bc=#F0F0F0;pw=0;"
shape[8] = "func=rect;x=158;y=185;width=15;height=38;angle=327;bc=#F0F0F0;pw=0;"
shape[9] = "func=ell;x=167;y=202;width=25;height=38;angle=329;bc=#F0F0F0;pw=0;"
shape[10] = "func=ell;x=214;y=32;width=7;height=47;angle=17;bc=#F0F0F0;pw=0;"
shape[11] = "func=ell;x=0;y=135;width=7;height=47;angle=293;bc=#F0F0F0;pw=0;"
shape[12] = "func=ell;x=0;y=126;width=7;height=47;angle=298;bc=#F0F0F0;pw=0;"
shape[13] = "func=ell;x=3;y=120;width=7;height=47;angle=304;bc=#F0F0F0;pw=0;"
shape[14] = "func=ell;x=10;y=116;width=7;height=47;angle=309;bc=#F0F0F0;pw=0;"
shape[15] = "func=ell;x=20;y=115;width=7;height=47;angle=312;bc=#F0F0F0;pw=0;"
shape[16] = "func=ell;x=205;y=36;width=7;height=47;angle=11;bc=#F0F0F0;pw=0;"
shape[17] = "func=ell;x=198;y=42;width=7;height=47;angle=2;bc=#F0F0F0;pw=0;"
shape[18] = "func=ell;x=191;y=46;width=7;height=47;angle=355;bc=#F0F0F0;pw=0;"
shape[19] = "func=ell;x=184;y=48;width=7;height=47;angle=350;bc=#F0F0F0;pw=0;"
shape[20] = "func=tri;x=15;y=135;x1=16;y1=0;x2=0;y2=45;x3=33;y3=45;angle=126;bc=#D4D4D4;pw=0;"
shape[21] = "func=tri;x=181;y=60;x1=16;y1=0;x2=0;y2=45;x3=33;y3=45;angle=180;bc=#D4D4D4;pw=0;"
shape[22] = "func=ell;x=178;y=52;width=7;height=47;angle=345;bc=#F0F0F0;pw=0;"
shape[23] = "func=ell;x=172;y=55;width=7;height=47;angle=342;bc=#F0F0F0;pw=0;"
shape[24] = "func=ell;x=166;y=59;width=7;height=47;angle=342;bc=#F0F0F0;pw=0;"
shape[25] = "func=ell;x=160;y=62;width=7;height=47;angle=342;bc=#F0F0F0;pw=0;"
shape[26] = "func=ell;x=155;y=67;width=7;height=47;angle=339;bc=#F0F0F0;pw=0;"
shape[27] = "func=ell;x=26;y=111;width=7;height=47;angle=315;bc=#F0F0F0;pw=0;"
shape[28] = "func=ell;x=34;y=109;width=7;height=47;angle=319;bc=#F0F0F0;pw=0;"
shape[29] = "func=ell;x=39;y=104;width=7;height=47;angle=319;bc=#F0F0F0;pw=0;"
shape[30] = "func=ell;x=46;y=101;width=7;height=47;angle=321;bc=#F0F0F0;pw=0;"
shape[31] = "func=ell;x=55;y=102;width=7;height=47;angle=324;bc=#F0F0F0;pw=0;"
shape[32] = "func=rect;x=30;y=119;width=57;height=44;angle=332;bc=#D4D4D4;pw=0;"
shape[33] = "func=rect;x=141;y=74;width=57;height=40;angle=326;bc=#D4D4D4;pw=0;"
shape[34] = "func=ell;x=148;y=66;width=7;height=47;angle=336;bc=#F0F0F0;pw=0;"
shape[35] = "func=ell;x=140;y=64;width=7;height=47;angle=336;bc=#F0F0F0;pw=0;"
shape[36] = "func=ell;x=132;y=61;width=7;height=47;angle=336;bc=#F0F0F0;pw=0;"
shape[37] = "func=ell;x=124;y=61;width=7;height=47;angle=336;bc=#F0F0F0;pw=0;"
shape[38] = "func=ell;x=116;y=59;width=7;height=47;angle=336;bc=#F0F0F0;pw=0;"
shape[39] = "func=ell;x=58;y=98;width=7;height=47;angle=327;bc=#F0F0F0;pw=0;"
shape[40] = "func=ell;x=63;y=93;width=7;height=47;angle=327;bc=#F0F0F0;pw=0;"
shape[41] = "func=ell;x=68;y=87;width=7;height=47;angle=332;bc=#F0F0F0;pw=0;"
shape[42] = "func=ell;x=74;y=84;width=7;height=47;angle=332;bc=#F0F0F0;pw=0;"
shape[43] = "func=rect;x=61;y=102;width=49;height=36;angle=323;bc=#D4D4D4;pw=0;"
shape[44] = "func=rect;x=112;y=83;width=49;height=36;angle=350;bc=#D4D4D4;pw=0;"
shape[45] = "func=ell;x=199;y=68;width=8;height=39;angle=17;bc=#F0F0F0;pw=0;"
shape[46] = "func=ell;x=193;y=69;width=8;height=39;angle=10;bc=#F0F0F0;pw=0;"
shape[47] = "func=ell;x=186;y=74;width=8;height=39;angle=5;bc=#F0F0F0;pw=0;"
shape[48] = "func=ell;x=178;y=78;width=8;height=39;angle=3;bc=#F0F0F0;pw=0;"
shape[49] = "func=ell;x=170;y=86;width=8;height=39;angle=354;bc=#F0F0F0;pw=0;"
shape[50] = "func=ell;x=29;y=146;width=8;height=39;angle=296;bc=#F0F0F0;pw=0;"
shape[51] = "func=ell;x=35;y=140;width=8;height=39;angle=303;bc=#F0F0F0;pw=0;"
shape[52] = "func=ell;x=43;y=136;width=8;height=39;angle=308;bc=#F0F0F0;pw=0;"
shape[53] = "func=ell;x=49;y=131;width=8;height=39;angle=314;bc=#F0F0F0;pw=0;"
shape[54] = "func=ell;x=58;y=130;width=8;height=39;angle=321;bc=#F0F0F0;pw=0;"
shape[55] = "func=ell;x=164;y=87;width=8;height=39;angle=344;bc=#F0F0F0;pw=0;"
shape[56] = "func=ell;x=156;y=88;width=8;height=39;angle=344;bc=#F0F0F0;pw=0;"
shape[57] = "func=ell;x=149;y=92;width=8;height=39;angle=344;bc=#F0F0F0;pw=0;"
shape[58] = "func=ell;x=141;y=94;width=8;height=39;angle=344;bc=#F0F0F0;pw=0;"
shape[59] = "func=ell;x=134;y=95;width=8;height=39;angle=336;bc=#F0F0F0;pw=0;"
shape[60] = "func=ell;x=65;y=128;width=8;height=39;angle=329;bc=#F0F0F0;pw=0;"
shape[61] = "func=ell;x=72;y=124;width=8;height=39;angle=329;bc=#F0F0F0;pw=0;"
shape[62] = "func=ell;x=79;y=120;width=8;height=39;angle=329;bc=#F0F0F0;pw=0;"
shape[63] = "func=ell;x=86;y=116;width=8;height=39;angle=329;bc=#F0F0F0;pw=0;"
shape[64] = "func=ell;x=93;y=115;width=8;height=39;angle=329;bc=#F0F0F0;pw=0;"
shape[65] = "func=rect;x=41;y=141;width=65;height=19;angle=328;bc=#D4D4D4;pw=0;"
shape[66] = "func=rect;x=132;y=102;width=65;height=19;angle=352;bc=#D4D4D4;pw=0;"
shape[67] = "func=ell;x=191;y=98;width=8;height=26;angle=17;bc=#F0F0F0;pw=0;"
shape[68] = "func=ell;x=183;y=99;width=8;height=26;angle=10;bc=#F0F0F0;pw=0;"
shape[69] = "func=ell;x=175;y=102;width=8;height=26;angle=10;bc=#F0F0F0;pw=0;"
shape[70] = "func=ell;x=166;y=103;width=8;height=26;bc=#F0F0F0;pw=0;"
shape[71] = "func=ell;x=157;y=106;width=8;height=26;angle=358;bc=#F0F0F0;pw=0;"
shape[72] = "func=ell;x=149;y=107;width=8;height=26;angle=351;bc=#F0F0F0;pw=0;"
shape[73] = "func=ell;x=139;y=106;width=8;height=26;angle=350;bc=#F0F0F0;pw=0;"
shape[74] = "func=ell;x=130;y=110;width=8;height=26;angle=348;bc=#F0F0F0;pw=0;"
shape[75] = "func=ell;x=48;y=160;width=8;height=26;angle=308;bc=#F0F0F0;pw=0;"
shape[76] = "func=ell;x=53;y=155;width=8;height=26;angle=315;bc=#F0F0F0;pw=0;"
shape[77] = "func=ell;x=62;y=152;width=8;height=26;angle=315;bc=#F0F0F0;pw=0;"
shape[78] = "func=ell;x=68;y=148;width=8;height=26;angle=317;bc=#F0F0F0;pw=0;"
shape[79] = "func=ell;x=77;y=144;width=8;height=26;angle=317;bc=#F0F0F0;pw=0;"
shape[80] = "func=ell;x=85;y=139;width=8;height=26;angle=322;bc=#F0F0F0;pw=0;"
shape[81] = "func=ell;x=90;y=133;width=8;height=26;angle=324;bc=#F0F0F0;pw=0;"
shape[82] = "func=ell;x=98;y=130;width=8;height=26;angle=335;bc=#F0F0F0;pw=0;"
shape[83] = "func=tri;x=186;y=230;x1=6;y1=0;x2=0;y2=29;x3=12;y3=29;angle=147;bc=#FF9E42;pw=0;"
shape[84] = "func=tri;x=179;y=227;x1=7;y1=0;x2=0;y2=9;x3=14;y3=9;angle=354;bc=#000000;pw=0;"
shape[85] = "func=ell;x=182;y=222;width=6;height=5;bc=#000000;pw=0;"
shape[86] = "func=ell;x=89;y=6;width=9;height=54;angle=344;bc=#F0F0F0;pw=0;"
shape[87] = "func=ell;x=80;y=4;width=9;height=54;angle=341;bc=#F0F0F0;pw=0;"
shape[88] = "func=ell;x=70;y=2;width=9;height=54;angle=340;bc=#F0F0F0;pw=0;"
shape[89] = "func=ell;x=62;y=5;width=9;height=54;angle=339;bc=#F0F0F0;pw=0;"
shape[90] = "func=ell;x=58;y=15;width=9;height=54;angle=335;bc=#F0F0F0;pw=0;"
shape[91] = "func=ell;x=53;y=23;width=9;height=54;angle=334;bc=#F0F0F0;pw=0;"
shape[92] = "func=tri;x=54;y=25;x1=22;y1=0;x2=0;y2=35;x3=45;y3=35;angle=337;bc=#D4D4D4;pw=0;"
shape[93] = "func=ell;x=68;y=41;width=61;height=107;angle=337;bc=#F0F0F0;pw=0;"
shape[94] = "func=rect;x=62;y=63;width=10;height=30;angle=304;bc=#2E2E2E;pw=0;"
shape[95] = "func=rect;x=103;y=45;width=10;height=30;angle=9;bc=#2E2E2E;pw=0;"
shape[96] = "func=rect;x=112;y=47;width=9;height=33;angle=336;bc=#2E2E2E;pw=0;"
shape[97] = "func=rect;x=58;y=70;width=9;height=33;angle=343;bc=#2E2E2E;pw=0;"
shape[98] = "func=tri;x=54;y=93;x1=14;y1=0;x2=0;y2=26;x3=28;y3=26;angle=345;bc=#2E2E2E;pw=0;"
shape[99] = "func=tri;x=112;y=69;x1=13;y1=0;x2=0;y2=25;x3=27;y3=25;angle=329;bc=#2E2E2E;pw=0;"
shape[100] = "func=ell;x=58;y=103;width=5;height=26;angle=11;bc=#000000;pw=0;"
shape[101] = "func=ell;x=67;y=100;width=5;height=26;angle=345;bc=#000000;pw=0;"
shape[102] = "func=ell;x=75;y=96;width=5;height=26;angle=307;bc=#000000;pw=0;"
shape[103] = "func=ell;x=127;y=76;width=5;height=26;angle=335;bc=#000000;pw=0;"
shape[104] = "func=ell;x=118;y=80;width=5;height=26;angle=6;bc=#000000;pw=0;"
shape[105] = "func=ell;x=136;y=70;width=5;height=26;angle=295;bc=#000000;pw=0;"
shape[106] = "func=ell;x=52;y=64;width=11;height=14;bc=#2E2E2E;pw=0;"
shape[107] = "func=ell;x=106;y=42;width=11;height=14;bc=#2E2E2E;pw=0;"
EndSub