Microsoft Small Basic

Program Listing: CXZ359
' Kepler's Second Law
' Version 0.1
' Copyright © 2016 Nonki Takahashi. The MIT License.
'
GraphicsWindow.Title = "Kepler's Second Law"
PI = Math.Pi
TWO_PI = 2 * PI
Δθ = Math.GetRadians(0.1)
Form()
DrawEllipse()
While "True"
If buttonClicked Then
e = Controls.GetTextBoxText(tboxE)
b = Math.SquareRoot(1 - e * e) * a
DrawEllipse()
buttonClicked = "False"
EndIf
EndWhile
Sub DrawEllipse
GraphicsWindow.BrushColor = "White"
GraphicsWindow.FillRectangle(0, 0, gw, gh)
xo = xc + e * a
yo = yc
s1 = PI * a * b
s2 = 0
For θ = 0 To TWO_PI + Δθ / 2 Step Δθ
x = xc + a * Math.Cos(θ)
y = yc - b * Math.Sin(θ)
If 0 < θ Then
Δs = Math.Abs((xLast - xo) * (y - yo) - (x - xo) * (yLast - yo)) / 2
s2 = s2 + Δs
If Math.Remainder(Math.Floor(s2 / (s1 / 12)), 2) = 0 Then
GraphicsWindow.BrushColor = "LightGray"
Else
GraphicsWindow.BrushColor = "Gray"
EndIf
GraphicsWindow.FillTriangle(xo, yo, x, y, xLast, yLast)
EndIf
xLast = x
yLast = y
EndFor
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.DrawText(10, 40, "πab=" + Math.Floor(s1))
GraphicsWindow.DrawText(10, 70, "Σ|r1×r2|/2=" + Math.Floor(s2))
EndSub
Sub Form
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
xc = gw / 2
yc = gh / 2 + 15
a = 180
e = 0.0934
b = Math.SquareRoot(1 - e * e) * a
GraphicsWindow.FontName = "Trebuchet MS"
GraphicsWindow.BrushColor = "Black"
txtE = Shapes.AddText("0 ≦ e < 1")
Shapes.Move(txtE, 10, 15)
tboxE = Controls.AddTextBox(75, 12)
Controls.SetTextBoxText(tboxE, e)
Controls.AddButton("Draw", 250, 10)
Controls.ButtonClicked = OnButtonClicked
EndSub
Sub OnButtonClicked
buttonClicked = "True"
EndSub