Microsoft Small Basic

Program Listing: GBQ812
' Moon Phase Animation
' Version 0.1
' Copyright © 2016 Nonki Takahashi. The MIT License.
'
GraphicsWindow.Title = "Moon Phase Animation"
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
xo = gw / 2
yo = gh / 2
GraphicsWindow.BackgroundColor = "Black"
a = 180
n = 90
GraphicsWindow.PenWidth = 0
GraphicsWindow.BrushColor = "White"
white[0] = Shapes.AddEllipse(2 * a, 2 * a)
Shapes.Move(white[0], xo - a, yo - a)
GraphicsWindow.BrushColor = "Black"
left = Shapes.AddRectangle(a + 1, 2 * (a + 1))
Shapes.Move(left, xo - (a + 1), yo - (a + 1))
Shapes.HideShape(left)
right = Shapes.AddRectangle(a + 1, 2 * (a + 1))
Shapes.Move(right, xo, yo - (a + 1))
Shapes.HideShape(right)
For i = 1 To n - 1
θ = Math.GetRadians(90 * i / n)
b = a * Math.Cos(θ)
GraphicsWindow.BrushColor = "Black"
black[i] = Shapes.AddEllipse(2 * b, 2 * a)
Shapes.Move(black[i], xo - b, yo - a)
Shapes.HideShape(black[i])
GraphicsWindow.BrushColor = "White"
white[i] = Shapes.AddEllipse(2 * b, 2 * a)
Shapes.Move(white[i], xo - b, yo - a)
Shapes.HideShape(white[i])
EndFor
white[n] = Shapes.AddEllipse(2 * a, 2 * a)
Shapes.Move(white[n], xo - a, yo - a)
Shapes.SetOpacity(white[n], 15)
i = 0 ' lp / 4n
While "True"
If i = 0 Then
Shapes.HideShape(right)
Shapes.HideShape(white[2 * n - i + 1])
ElseIf i = 1 Then
Shapes.ShowShape(white[i])
Shapes.ShowShape(left)
ElseIf 1 < i And i < n Then
Shapes.ShowShape(white[i])
Shapes.HideShape(white[i - 1])
ElseIf i = n Then
Shapes.HideShape(white[i - 1])
ElseIf i = n + 1 Then
Shapes.ShowShape(black[2 * n - i])
ElseIf n + 1 < i And i < 2 * n Then
Shapes.ShowShape(black[2 * n - i])
Shapes.HideShape(black[2 * n - i + 1])
ElseIf i = 2 * n Then
Shapes.ShowShape(right)
Shapes.HideShape(black[2 * n - i + 1])
ElseIf i = 2 * n + 1 Then
Shapes.ShowShape(black[i - 2 * n])
Shapes.HideShape(left)
ElseIf 2 * n + 1 < i And i < 3 * n Then
Shapes.ShowShape(black[i - 2 * n])
Shapes.HideShape(black[i - 2 * n - 1])
ElseIf i = 3 * n Then
Shapes.HideShape(black[i - 2 * n - 1])
ElseIf i = 3 * n + 1 Then
Shapes.ShowShape(white[4 * n - i])
ElseIf 3 * n + 1 < i And i < 4 * n Then
Shapes.ShowShape(white[4 * n - i])
Shapes.HideShape(white[4 * n - i + 1])
EndIf
i = i + 1
If 4 * n <= i Then
i = 0
EndIf
Program.Delay(20)
EndWhile