Microsoft Small Basic

Program Listing: RPM049
' Area of Crescent
' Copyright (c) 2012 Nonki Takahashi
'
GraphicsWindow.Title = "Area of Crescent"
GraphicsWindow.BackgroundColor = "Black"
lp = 0 ' lunar phase (days)
maxlp = 29.53
x0 = 110 ' left
y0 = 40 ' top
d = 50 ' diameter of moon
GraphicsWindow.PenWidth = 0
For day = 1 To 31
x = x0 + Math.Remainder((day - 1), 7) * (d * 1.2)
y = y0 + Math.Floor((day - 1) / 7) * (d * 1.5)
a = 0 ' area of crescent [%]
If lp > 0 Then
GraphicsWindow.BrushColor = "White"
GraphicsWindow.FillEllipse(x, y, d, d)
a = 100 ' area of crescent [%]
EndIF
GraphicsWindow.BrushColor = "Black"
If 0 < lp And lp < maxlp / 2 Then
GraphicsWindow.FillRectangle(x, y, d / 2, d)
a = a - 50 ' area of crescent [%]
ElseIf maxlp / 2 < lp And lp < maxlp Then
GraphicsWindow.FillRectangle(x + d / 2, y, d / 2, d)
a = a - 50 ' area of crescent [%]
EndIF
If 0 < lp And lp < maxlp / 4 Then
s = Math.Cos(lp / maxlp * 2 * Math.Pi)
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.FillEllipse(x + d * (1 - s) / 2, y, d * s, d)
a = a - 50 * s ' area of crescent [%]
ElseIf maxlp / 4 < lp And lp < maxlp / 2 Then
s = Math.Sin((lp / maxlp - 1 / 4) * 2 * Math.Pi)
GraphicsWindow.BrushColor = "White"
GraphicsWindow.FillEllipse(x + d * (1 - s) / 2, y, d * s, d)
a = a + 50 * s ' area of crescent [%]
ElseIf maxlp / 2 < lp And lp < maxlp * 3 / 4 Then
s = Math.Cos((lp / maxlp - 1 / 2) * 2 * Math.Pi)
GraphicsWindow.BrushColor = "White"
GraphicsWindow.FillEllipse(x + d * (1 - s) / 2, y, d * s, d)
a = a + 50 * s ' area of crescent [%]
ElseIf maxlp * 3 / 4 < lp And lp < maxlp Then
s = Math.Sin((lp / maxlp - 3 / 4) * 2 * Math.Pi)
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.FillEllipse(x + d * (1 - s) / 2, y, d * s, d)
a = a - 50 * s ' area of crescent [%]
EndIf
GraphicsWindow.BrushColor = "White"
el = Shapes.AddEllipse(d, d)
Shapes.Move(el, x, y)
Shapes.SetOpacity(el, 30)
GraphicsWindow.DrawText(x + d * 0.1, y - d * 0.3, lp)
GraphicsWindow.BrushColor = "Black"
pc = Shapes.AddText((Math.Floor(a * 10) / 10) + "%")
Shapes.Move(pc, x + d * 0.1, y + d * 0.35)
lp = lp + 1
If lp >= maxlp Then
lp = lp - maxlp
EndIf
EndFor