Microsoft Small Basic

Program Listing: KCG090
' Sun Flower
' Copyright (c) 2014 Nonki Takahashi. The MIT License.
'
' Reference:
' [1] MathsIsFun.com, http://www.mathsisfun.com/numbers/nature-golden-ratio-fibonacci.html
'
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
GraphicsWindow.BackgroundColor = "Green"
GraphicsWindow.Title = "Sun Flower"
GraphicsWindow.PenWidth = 0
size = 200
iMax = 10
For i = 1 To iMax
x = Math.GetRandomNumber(gw)
y = Math.GetRandomNumber(gh)
GraphicsWindow.PenWidth = 1
GraphicsWindow.PenColor = "Gold"
GraphicsWindow.BrushColor = "Yellow"
AddSunFlower()
EndFor
Sub AddSunFlower
s = Math.GetRandomNumber(15) - 1
For a = s To 359 Step 15
_a = Math.GetRadians(a)
ox = x + (size * 3 / 8) * Math.Cos(_a)
oy = y + (size * 3 / 8) * Math.Sin(_a)
_w = size / 4
_h = size / 10
_x = ox - _w / 2
_y = oy - _h / 2
ell = Shapes.AddEllipse(_w, _h)
Shapes.Move(ell, _x, _y)
Shapes.Rotate(ell, a)
EndFor
GraphicsWindow.PenWidth = 0
GraphicsWindow.BrushColor = "SaddleBrown"
_w = size / 1.9
_h = size / 1.9
_x = x - _w / 2
_y = y - _h / 2
ell = Shapes.AddEllipse(_w, _h)
Shapes.Move(ell, _x, _y)
DrawSeeds()
EndSub
Sub DrawSeeds
GraphicsWindow.BrushColor = "DarkGoldenrod"
k = (Math.SquareRoot(5) - 1) / 2
a = 0
da = k * 2 * Math.Pi
scale = size / 500
_s = 6
ds = 1.006
_r = 0
For j = 1 To 13 * 9
rect = Shapes.AddRectangle(scale * _s, scale * _s)
_x = x + scale * _r * Math.Cos(a)
_y = y + scale * _r * Math.Sin(a)
Shapes.Move(rect, _x, _y)
Shapes.Rotate(rect, 2*a)
a = a + da
_r = _r + k
_s = _s * ds
EndFor
EndSub