# Phyllotaxis

Fermat’s spiral,

$R=\sqrt{\theta}$

in polar coordinates where
theta is the angle from the starting horizontal line
3D spheres are placed on the spiral at 137.5 degree intervals.

i generated this one fooling around with color numbers 1-255 multiplying by 23, dividing by 255 and taking the remainder, whew, just trying to get a pattern.

'begin phyllotaxis structure
Sub draw_daisy()
Call init_polar
Dim strfunc As String
Dim r As Double, A_rad As Double
Dim X As Double, Y As Double
Dim i As Integer, n As Integer
Dim d As Double, circle_radius As Double
Dim pt() As Double

strfunc = frm_polar.txt_a2.Value
n = frm_polar.txt_n.Text
d = frm_polar.txt_d.Text
ReDim pt(1 To n * 2)

For i = 1 To n
'user works in degrees but trig functions use radians
pt(i * 2 - 1) = X: pt(i * 2) = Y
Next i

End Sub

Sub draw_circles(ByRef pt() As Double, circle_radius As Double)
Dim i As Integer, numpts As Integer
Dim x1 As Double, y1 As Double
'dbl_thickness As Double)
Dim pt1(0 To 2) As Double
numpts = UBound(pt) / 2

For i = 1 To numpts
x1 = pt(i * 2 - 1)
y1 = pt(i * 2)
pt1(0) = x1: pt1(1) = y1: pt1(2) = 0
'circleobj.Thickness = dbl_thickness
Next i

Update
End Sub

Sub draw_spheres(ByRef pt() As Double, circle_radius As Double)
Dim i As Integer, numpts As Integer
Dim x1 As Double, y1 As Double
Dim pt1(0 To 2) As Double
numpts = UBound(pt) / 2

For i = 1 To numpts
x1 = pt(i * 2 - 1)
y1 = pt(i * 2)
pt1(0) = x1: pt1(1) = y1: pt1(2) = 0
Next i

Update
End Sub

Function eval_polar_func(ByVal strfunc As String, A_rad As Double) As Double
On Error GoTo HandlError
Static errorcounter As Integer

strfunc = Replace(strfunc, "A", A_rad, , , vbTextCompare)
eval_polar_func = Evaluate(strfunc)

ExitHere:
Exit Function
'runtime error 13 type mismatch
HandlError:
If Err.number = 13 Then
MsgBox "type mismatch div by zero or bad equation"
eval_polar_func = ylim + 1
errorcounter = errorcounter + 1
If errorcounter = 3 Then
MsgBox "errorcounter at 3 - exiting"
End
End If

End If
End Function