[Tutor] fibonacci

Gregor Lingl glingl@aon.at
Wed Feb 12 05:40:03 2003


This is a multi-part message in MIME format.
--------------090705010405060909080500
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Chris Avery schrieb:

>Of course, my apologies.
>
>The Fibonacci sequence is the sequence of numbers each of which, after the 
>second, is the sum of the two previous ones.  
>
>0, 1, 1, 2, 3, 5, 8, 13, 21,...,
>
>  
>
... and if you like to *see* them, run the following (or the attached) 
script:

from turtle import *

def fibotree(n, length=110, angle=45, factor=0.62):
    if n == 0:
        return
    forward(length)
    if n > 2:
        left(angle)
        fibotree(n-2, length*factor)
        right(angle)
        right(angle)
        fibotree(n-1, length*factor)
        left(angle)
    backward(length)

reset()
left(90)
up();backward(120);down()
fibotree(10)  

It makes you also see them grow and think about them ...
Regards, Gregor


--------------090705010405060909080500
Content-Type: text/plain;
 name="fibotree.py"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="fibotree.py"

from turtle import *

def fibotree(n, length=110, angle=45, factor=0.62):
    if n == 0:
        return
    forward(length)
    if n > 2:
        left(angle)
        fibotree(n-2, length*factor)
        right(angle)
        right(angle)
        fibotree(n-1, length*factor)
        left(45)
    backward(length)

reset()
left(90)
up();backward(120);down()
fibotree(10)   

--------------090705010405060909080500--