Microsoft Small Basic

Program Listing: RVG849-1
' Capricornus 0.21
' やぎ
' January
' Copyright © 2013-2016 Nonki Takahashi. The MIT License.
'
' History:
' 0.21 2016-01-06 Changed calendar for 2016. (RVG849-1)
' 0.1 2013-01-03 Created from Serpens 0.1 (RSH103). (RVG849)
' 0.0 2013-01-03 19:47:07 Generated by Shapes 1.5
'
' Reference:
' http://en.wikipedia.org/wiki/List_of_stars_in_Capricornus
'
GraphicsWindow.Title = "Capricornus 0.21"
GraphicsWindow.BackgroundColor = "MidnightBlue"
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
InitStars()
num = Array.GetItemCount(edge)
index = Array.GetAllIndices(edge)
Shapes_Init() ' initialize shapes
scale = 1.2
Shapes_Add() ' add shapes
angle = 0
DrawGrids()
GraphicsWindow.PenWidth = 1
GraphicsWindow.PenColor = "DarkGray"
For i = 1 To num
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"]
RADec2XY()
x1 = x
y1 = y
ra = star[Text.GetSubTextToEnd(e, m + 1)]["RA"]
dec = star[Text.GetSubTextToEnd(e, m + 1)]["Dec"]
RADec2XY()
x2 = x
y2 = y
Shapes.AddLine(x1, y1, x2, y2)
EndFor
num = Array.GetItemCount(star)
index = Array.GetAllIndices(star)
GraphicsWindow.BrushColor = "White"
For i = 1 To num
ra = star[index[i]]["RA"]
dec = star[index[i]]["Dec"]
RADec2XY()
mag = star[index[i]]["Mag"]
d = 20 / mag
ell = Shapes.AddEllipse(d, d)
Shapes.Move(ell, x - d / 2, y - d / 2)
EndFor
GraphicsWindow.BrushColor = "White"
GraphicsWindow.FontSize = 30
GraphicsWindow.DrawText(40, 50, "January")
GraphicsWindow.FontSize = 40
year = 2016
GraphicsWindow.DrawText(40, 90, year)
Cal_Init()
sBuf = year + ",1"
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:
' Blink start
While "True"
Program.Delay(2900)
Shapes.HideShape(shape[12]["obj"])
Program.Delay(100)
Shapes.ShowShape(shape[12]["obj"])
EndWhile
' end of main
Sub Cal_Init
' Calendar | Initialize days of month
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;"
EndSub
Sub Cal_DrawMonth
' Calendar | Print month
' param iM - month
' param iDoY - days of year
' param iWoY - week of year
GraphicsWindow.FontSize = 16
GraphicsWindow.FontName = "Courier New"
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, 324, 260)
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 DrawGrids
GraphicsWindow.PenWidth = 1
GraphicsWindow.PenColor = "DimGray"
y1 = 0
y2 = GraphicsWindow.Height
For ra = 19 To 22
RADec2XY()
Shapes.AddLine(x, y1, x, y2)
EndFor
x1 = 0
x2 = GraphicsWindow.Width
For dec = -30 To 0 Step 10
If dec > 0 Then
dec = Text.Append("+", Math.Abs(dec))
EndIf
RADec2XY()
Shapes.AddLine(x1, y, x2, y)
EndFor
EndSub
Sub RADec2XY
' param ra, dec
' return x, y
x = Text.GetSubText(ra, 1, 2)
x = x + Text.GetSubText(ra, 4, 2) / 60
x = x + Text.GetSubText(ra, 7, 5) / 3600
x = 30 - (x - 22) * 3600 / 24
y = Text.GetSubText(dec, 2, 2)
y = y + Text.GetSubText(dec, 5, 2) / 60
y = y + Text.GetSubText(dec, 8, 5) / 3600
y = y * Text.Append(Text.GetSubText(dec, 1, 1), "1")
y = 100 - y * 3600 / 360
EndSub
Sub InitStars
' Initialize stars in Capricornus
' index: Flamsteed designation
' RA (Right ascension), Dec (Declination), Mag (Apparent magnitude)
star[49] = "name=δ Cap;ra=21 47 02.29;dec=-16 07 35.6;mag=2.85;"
star[9] = "name=β1 Cap;ra=20 21 00.65;dec=-14 46 53.0;mag=3.05;"
star[6] = "name=α2 Cap;ra=20 18 03.22;dec=-12 32 41.5;mag=3.58;"
star[40] = "name=γ Cap;ra=21 40 05.34;dec=-16 39 44.1;mag=3.69;"
star[34] = "name=ζ Cap;ra=21 26 40.03;dec=-22 24 41.0;mag=3.77;"
star[23] = "name=θ Cap;ra=21 05 56.78;dec=-17 13 57.8;mag=4.08;"
star[18] = "name=ω Cap;ra=20 51 49.30;dec=-26 55 08.9;mag=4.12;"
star[16] = "name=ψ Cap;ra=20 46 05.77;dec=-25 16 13.9;mag=4.13;"
star[32] = "name=ι Cap;ra=21 22 14.78;dec=-16 50 04.4;mag=4.27;"
star[5] = "name=α1 Cap;ra=20 17 38.86;dec=-12 30 29.6;mag=4.30;"
star[24] = "name=24 Cap;ra=21 07 07.69;dec=-25 00 20.7;mag=4.49;"
star[36] = "name=36 Cap;ra=21 28 43.32;dec=-21 48 25.8;mag=4.50;"
star[39] = "name=ε Cap;ra=21 37 04.82;dec=-19 27 57.6;mag=4.51;"
star[43] = "name=κ Cap;ra=21 42 39.42;dec=-18 51 58.7;mag=4.72;"
star[8] = "name=ν Cap;ra=20 20 39.81;dec=-12 45 32.6;mag=4.77;"
star[11] = "name=ρ Cap;ra=20 28 51.62;dec=-17 48 49.2;mag=4.77;"
star[22] = "name=η Cap;ra=21 04 24.32;dec=-19 51 17.8;mag=4.82;"
star[51] = "name=μ Cap;ra=21 53 17.58;dec=-13 33 06.5;mag=5.07;"
star[10] = "name=π Cap;ra=20 27 19.20;dec=-18 12 42.1;mag=5.08;"
star[46] = "name=46 Cap;ra=21 45 00.25;dec=-09 04 56.7;mag=5.10;"
star[15] = "name=υ Cap;ra=20 40 02.96;dec=-18 08 19.0;mag=5.15;"
star[42] = "name=42 Cap;ra=21 41 32.93;dec=-14 02 48.7;mag=5.16;"
star[28] = "name=φ Cap;ra=21 15 37.89;dec=-20 39 06.1;mag=5.17;"
star[14] = "name=τ2 Cap;ra=20 39 16.32;dec=-14 57 17.0;mag=5.24;"
star[41] = "name=41 Cap;ra=21 42 00.64;dec=-23 15 45.5;mag=5.24;"
star[7] = "name=σ Cap;ra=20 19 23.60;dec=-19 07 06.6;mag=5.28;"
star[25] = "name=χ Cap;ra=21 08 33.61;dec=-21 11 36.7;mag=5.30;"
star[29] = "name=29 Cap;ra=21 15 44.83;dec=-15 10 17.4;mag=5.31;"
star[33] = "name=33 Cap;ra=21 24 09.60;dec=-20 51 05.6;mag=5.38;"
star[30] = "name=30 Cap;ra=21 17 57.28;dec=-17 59 06.5;mag=5.40;"
star[48] = "name=λ Cap;ra=21 46 32.08;dec=-11 21 57.4;mag=5.57;"
star[37] = "name=37 Cap;ra=21 34 51.07;dec=-20 05 03.8;mag=5.70;"
star[19] = "name=19 Cap;ra=20 54 47.85;dec=-17 55 22.3;mag=5.78;"
star[35] = "name=35 Cap;ra=21 27 14.83;dec=-21 11 46.1;mag=5.78;"
star[2] = "name=ξ2 Cap;ra=20 12 25.76;dec=-12 37 01.3;mag=5.84;"
star[4] = "name=4 Cap;ra=20 18 01.38;dec=-21 48 35.6;mag=5.86;"
star[44] = "name=44 Cap;ra=21 43 04.40;dec=-14 23 59.1;mag=5.88;"
star[17] = "name=17 Cap;ra=20 46 09.97;dec=-21 30 50.4;mag=5.91;"
star[12] = "name=ο Cap A;ra=20 29 53.89;dec=-18 34 58.7;mag=5.94;"
star[45] = "name=45 Cap;ra=21 44 00.98;dec=-14 44 57.8;mag=5.96;"
star[47] = "name=47 Cap;ra=21 46 16.26;dec=-09 16 33.4;mag=6.00;"
star[21] = "name=21 Cap;ra=21 00 51.78;dec=-17 31 51.1;mag=6.07;"
star[27] = "name=27 Cap;ra=21 09 32.93;dec=-20 33 22.8;mag=6.25;"
star[20] = "name=20 Cap;ra=20 59 36.13;dec=-19 02 06.8;mag=6.26;"
star[3] = "name=3 Cap;ra=20 16 22.80;dec=-12 20 13.5;mag=6.30;"
star[1] = "name=ξ1 Cap;ra=20 11 57.90;dec=-12 23 32.5;mag=6.34;"
star[12] = "name=ο Cap B;ra=20 29 52.58;dec=-18 35 10.2;mag=6.74;"
star[13] = "name=τ1 Cap;ra=20 37 21.16;dec=-15 08 50.0;mag=6.76;"
star[50] = "name=50 Cap;ra=21 46 42.09;dec=-11 41 52.2;mag=7.01;"
star[31] = "name=31 Cap;ra=21 18 15.64;dec=-17 27 44.2;mag=7.07;"
edge = "1=6-9;2=9-16;3=16-18;4=18-34;5=34-49;6=49-40;7=40-32;"
edge = edge + "8=32-23;9=23-9;"
EndSub
Sub Shapes_Init
' Shapes | Initialize shapes data
' return shX, shY - current position of shapes
' return shape - array of shapes
shX = 10 ' x offset
shY = 121 ' y offset
shape = ""
shape[1] = "func=rect;x=191;y=68;width=44;height=86;bc=#83809C;pw=0;"
shape[2] = "func=tri;x=179;y=6;x1=8;y1=0;x2=0;y2=73;x3=17;y3=73;angle=339;bc=#83809C;pw=0;"
shape[3] = "func=tri;x=207;y=0;x1=8;y1=0;x2=0;y2=73;x3=17;y3=73;angle=343;bc=#83809C;pw=0;"
shape[4] = "func=line;x=171;y=144;x1=26;y1=46;x2=0;y2=0;pc=#83809C;pw=16;"
shape[5] = "func=line;x=193;y=188;x1=0;y1=0;x2=58;y2=24;pc=#83809C;pw=16;"
shape[6] = "func=line;x=149;y=145;x1=21;y1=68;x2=0;y2=0;pc=#83809C;pw=16;"
shape[7] = "func=line;x=102;y=200;x1=64;y1=6;x2=0;y2=0;pc=#83809C;pw=16;"
shape[8] = "func=ell;x=1;y=82;width=97;height=99;bc=#83809C;pw=0;"
shape[9] = "func=ell;x=59;y=72;width=144;height=87;angle=351;bc=#83809C;pw=0;"
shape[10] = "func=tri;x=0;y=54;x1=39;y1=0;x2=0;y2=73;x3=79;y3=73;angle=173;bc=#83809C;pc=#191970;pw=4;"
shape[11] = "func=ell;x=35;y=123;width=15;height=16;bc=#191970;pw=0;"
shape[12] = "func=ell;x=210;y=93;width=15;height=16;bc=#191970;pw=0;"
shape[13] = "func=tri;x=155;y=63;x1=20;y1=0;x2=0;y2=20;x3=41;y3=20;angle=206;bc=#83809C;pw=0;"
shape[14] = "func=tri;x=223;y=67;x1=20;y1=0;x2=0;y2=20;x3=41;y3=20;angle=164;bc=#83809C;pw=0;"
shape[15] = "func=line;x=208;y=141;x1=0;y1=0;x2=8;y2=18;pc=#191970;pw=4;"
shape[16] = "func=tri;x=192;y=151;x1=6;y1=0;x2=0;y2=38;x3=13;y3=38;angle=181;bc=#83809C;pw=0;"
shape[17] = "func=tri;x=29;y=91;x1=24;y1=0;x2=0;y2=47;x3=48;y3=47;angle=172;bc=#83809C;pw=0;"
shape[18] = "func=line;x=211;y=101;x1=0;y1=0;x2=12;y2=0;pc=#191970;pw=4;"
shape[19] = "func=text;x=380;y=-80;text=♑;fs=100;bc=#83809C;"
EndSub
Sub Shapes_Add
' Shapes | Add shapes as shapes data
' param shape - array of shapes
' param scale - to zoom
' return nShapes - number of shapes
' return shAngle - current angle of shapes
Stack.PushValue("local", i)
nShapes = Array.GetItemCount(shape)
s = scale
For i = 1 To nShapes
GraphicsWindow.PenWidth = shape[i]["pw"] * s
If shape[i]["pw"] > 0 Then
GraphicsWindow.PenColor = shape[i]["pc"]
EndIf
If shape[i]["func"] = "rect" Then
GraphicsWindow.BrushColor = shape[i]["bc"]
shape[i]["obj"] = Shapes.AddRectangle(shape[i]["width"]* s, shape[i]["height"] * s)
ElseIf shape[i]["func"] = "ell" Then
GraphicsWindow.BrushColor = shape[i]["bc"]
shape[i]["obj"] = Shapes.AddEllipse(shape[i]["width"]* s, shape[i]["height"] * s)
ElseIf shape[i]["func"] = "tri" Then
GraphicsWindow.BrushColor = shape[i]["bc"]
shape[i]["obj"] = Shapes.AddTriangle(shape[i]["x1"] * s, shape[i]["y1"] * s, shape[i]["x2"] * s, shape[i]["y2"] * s, shape[i]["x3"] * s, shape[i]["y3"] * s)
ElseIf shape[i]["func"] = "line" Then
shape[i]["obj"] = Shapes.AddLine(shape[i]["x1"] * s, shape[i]["y1"] * s, shape[i]["x2"] * s, shape[i]["y2"] * s)
ElseIf shape[i]["func"] = "text" Then
GraphicsWindow.BrushColor = shape[i]["bc"]
GraphicsWindow.FontSize = shape[i]["fs"]
shape[i]["obj"] = Shapes.AddText(shape[i]["text"])
EndIf
Shapes.Move(shape[i]["obj"], shX + shape[i]["x"] * s, shY + shape[i]["y"] * s)
If Text.IsSubText("rect|ell|tri", shape[i]["func"]) And shape[i]["angle"] <> 0 Then
Shapes.Rotate(shape[i]["obj"], shape[i]["angle"])
EndIf
shape[i]["rx"] = shape[i]["x"]
shape[i]["ry"] = shape[i]["y"]
EndFor
shAngle = 0
i = Stack.PopValue("local")
EndSub