Python Turtle Spiral Drawing

Viewed 278

I want to draw a spiral in the output instead of a regular spiral. However, I'm confused about how to change the spiral function to get my desired output of a spiral like this - [![fibo][1]][1]

from turtle import Turtle, Screen
import math

t = Turtle()
s = Screen()
t.speed(0)


def spiral(x, y, stLength, k): 
    t.up()
    t.setpos(x, y)
    t.seth(90)
    t.down()
    for i in range(k):
        t.forward(stLength)
        t.left(15)
        stLength -=0.2


spiral(250,-120,40,200) 


s.exitonclick()

1 Answers

I did this for hour and I made shape and this spiral, but I am still stuck on this fibonacci spiral. It doesn't works that good. But it works good as you paint.

from turtle import Turtle, Screen

t = Turtle()
s = Screen()
t.speed(5)

def rectangle(x, y, side_a, side_b):
    t.setpos(x, y)
    t.forward(side_b)
    t.right(90)
    t.forward(side_a)
    t.right(90)
    t.forward(side_b)
    t.right(90)
    t.forward(side_a)
    t.right(90)

def squares_in_rectangle():
    t.penup()
    t.goto(200, 0)
    t.pendown()
    t.right(90)
    t.forward(200)
    t.penup()
    t.goto(200, -110)
    t.left(90)
    t.pendown()
    t.forward(100)
    t.penup()
    t.goto(230, -110)
    t.right(90)
    t.pendown()
    t.forward(90)
    t.penup()
    t.goto(200, -140)
    t.left(90)
    t.pendown()
    t.forward(30)
    t.penup()
    t.goto(220, -110)
    t.right(90)
    t.pendown()
    t.forward(30)
    t.penup()
    t.goto(220, -120)
    t.left(90)
    t.pendown()
    t.forward(10)


def spiral(x, y, stLength, k):
    t.up()
    t.setpos(x, y)
    t.seth(225)
    t.down()
    for i in range(k):
        something = 60
        something += 10
        t.left(something)
        something += 3
        stLength /= 0.7
        t.forward(stLength)

rectangle(0, 0, 200, 300)
squares_in_rectangle()
spiral(225, -120, 35, 6)


s.exitonclick()
Related