This project draws square spiral inside a square. Now draw a pentagon spiral inside pentagon as shown.
Source Code:
import turtle
import math
screen = turtle.Screen()
screen.title('Pentagon Spiral inside Pentagon - PythonTurtle.Academy')
screen.setup(1000,1000)
screen.setworldcoordinates(-1000,-1000,1000,1000)
turtle.speed(0)
turtle.hideturtle()
#screen.tracer(0,0)
def draw_spiral(x,y,r,direction):
if r < 10: return
d = direction
r2 = r*math.cos(math.radians(36))/math.cos(math.radians(36-alpha))
dist = r*math.sin(math.radians(36))-r2*math.sin(math.radians(36-alpha))
turtle.up()
px = x + r*math.cos(math.radians(d))
py = y + r*math.sin(math.radians(d))
turtle.goto(px,py)
turtle.down()
d += 360/5
for _ in range(5):
px = x + r*math.cos(math.radians(d))
py = y + r*math.sin(math.radians(d))
turtle.goto(px,py)
d += 360/5
draw_spiral(x,y,r2,direction+alpha)
alpha = 7
draw_spiral(0,0,900,90)