Microsoft Small Basic

Program Listing: RVG849
' Capricornus 0.1
' Copyright (c) 2013 Nonki Takahashi. All rights reserved.
'
' History:
' 0.1 2013/01/03 Created from Serpens 0.1 (RSH103). ()
' 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.1"
GraphicsWindow.BackgroundColor = "MidnightBlue"
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
GraphicsWindow.DrawText(40, 90, "2013")
Cal_Init()
sBuf = "2013,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
' Calender | 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
' Calender | Print month
' param iM - month
' param iDoY - days of year
' param iWoY - week of year
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, 340, 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
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
' index: Flamsteed designation
' RA (Right ascension), Dec (Declination), Mag (Apparent magnitude)
star[6] = "name=α2 Cap;RA=20 18 03.22;Dec=-12 32 41.5;Mag=3.58;"
star[9] = "name=β Cap;RA=20 21 00.65;Dec=-14 46 53.0;Mag=3.05;"
star[16] = "name=ψ Cap;RA=20 46 05.77;Dec=-25 16 13.9;Mag=4.13;"
star[18] = "name=ω Cap A;RA=20 51 49.30;Dec=-26 55 08.9;Mag=4.12;"
star[34] = "name=ζ Cap;RA=21 26 40.03;Dec=-22 24 41.0;Mag=3.77;"
star[49] = "name=δ Cap;RA=21 47 02.29;Dec=-16 07 35.6;Mag=2.85;"
star[40] = "name=γ Cap;RA=21 40 05.34;Dec=-16 39 44.1;Mag=3.69;"
star[32] = "name=ι Cap;RA=21 22 14.78;Dec=-16 50 04.4;Mag=4.28;"
star[23] = "name=θ Cap;RA=21 05 56.78;Dec=-17 13 57.8;Mag=4.08;"
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;"
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)
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