' Recursively draw a binary tree branch.
Private Sub DrawBranch(ByVal gr As Graphics, ByVal depth As _
Integer, ByVal X As Integer, ByVal Y As Integer, ByVal _
length As Double, ByVal theta As Double, ByVal _
length_scale As Double, ByVal dtheta As Double)
Dim x1 As Integer
Dim y1 As Integer
' See where this branch should end.
x1 = CInt(X + length * Cos(theta))
y1 = CInt(Y + length * Sin(theta))
gr.DrawLine(Pens.Black, X, Y, x1, y1)
' If depth > 1, draw the attached branches.
If depth > 1 Then
DrawBranch(gr, depth  1, x1, y1, length * _
length_scale, theta + dtheta, length_scale, _
dtheta)
DrawBranch(gr, depth  1, x1, y1, length * _
length_scale, theta  dtheta, length_scale, _
dtheta)
End If
End Sub
