Python Forum
Fibonacci Sequence on Turtle
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fibonacci Sequence on Turtle
#1
Hey, 
I am trying to draw a series of fibonacci squares using turtles.
I am new to python but am using loops to try to draw them.
This is what I have so far...

import turtle
wn = turtle.Screen()
wn.bgcolor("lightgreen")
tess = turtle.Turtle()
tess.color("blue")

squares = input("How many squares do you want?")

n = 10
for sqs in range(int(squares)):
   for i in range(6):  #it has 6 turns (not 4) because the next square begins from the corner diagonal to the corner the preceding square began
      tess.forward(n)
      tess.left(90)
   tess.right(90)      #this points the turtle in the right direction to start the next square!

wn.mainloop()
I can code the fibonacci sequence to get integer terms but am stuck on how to nest this within my loop so that each square is drawn with side lengths in accordance with the fibonacci sequence.

Can anyone help?!?

I have added some other code but it still is not increasing the size of each square as it goes on...

import turtle
wn = turtle.Screen()
wn.bgcolor("lightgreen")
tess = turtle.Turtle()
tess.color("blue")

squares = input("How many squares do you want?")

def recur_fibo(n):
if n <= 1:
return n
else:
return(recur_fibo(n-1) + recur_fibo(n-2))

n = 10
for sqs in range(int(squares)):
for i in range(6):
tess.forward(recur_fibo(n))
tess.left(90)
tess.right(90)


wn.mainloop()
Reply


Messages In This Thread
Fibonacci Sequence on Turtle - by JRod - Feb-01-2017, 10:17 PM
RE: Fibonacci Sequence on Turtle - by ichabod801 - Feb-01-2017, 10:36 PM
RE: Fibonacci Sequence on Turtle - by Larz60+ - Feb-02-2017, 01:48 AM
RE: Fibonacci Sequence on Turtle - by JRod - Feb-02-2017, 07:36 AM
RE: Fibonacci Sequence on Turtle - by JRod - Feb-02-2017, 10:32 AM
RE: Fibonacci Sequence on Turtle - by ichabod801 - Feb-02-2017, 10:38 PM
RE: Fibonacci Sequence on Turtle - by JRod - Feb-03-2017, 07:51 AM
RE: Fibonacci Sequence on Turtle - by JRod - Feb-04-2017, 08:20 AM
RE: Fibonacci Sequence on Turtle - by ichabod801 - Feb-04-2017, 11:30 AM
RE: Fibonacci Sequence on Turtle - by JRod - Feb-06-2017, 01:24 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Fibonacci Yasunaga 7 3,134 May-16-2021, 02:36 PM
Last Post: csr
  wn = turtle.screen() AttributeError: module 'turtle' has no attribute 'screen' Shadower 1 6,313 Feb-06-2019, 01:25 AM
Last Post: woooee
  Help! Turtle not working, even when we click the turtle demo in IDLE nothing happens. BertyBee 3 5,797 Jan-04-2019, 02:44 AM
Last Post: SheeppOSU
  fibonacci ***Time limit exceeded*** frequency 18 10,664 Nov-29-2018, 09:03 PM
Last Post: frequency
  Fibonacci sequence Darbandiman123 2 2,801 Sep-26-2018, 02:32 PM
Last Post: Darbandiman123
  Help debug my fibonacci implementation dineshpabbi10 6 4,168 May-16-2018, 12:12 PM
Last Post: dineshpabbi10

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020