from turtle import *
import math
speed(0)      
hideturtle()  

part_ratio = 2 * math.cos(math.radians(72))
side_ratio = 1 / (part_ratio + 2)

hide_turtles = True   
path_color =   
fill_color =   


def pentagon(t, s):
  t.color(path_color, fill_color)
  t.pendown()
  t.right(36)
  t.begin_fill()
  for i in range(5):
    t.forward(s)
    t.right(72)
  t.end_fill()


def sierpinski(i, t, s):
  t.setheading(0)
  new_size = s * side_ratio

  if i > 1:
    i -= 1

    
    for j in range(4):
      t.right(36)
      short = s * side_ratio / part_ratio
      dist = [short, s, s, short][j]

      
      spawn = Turtle()
      if hide_turtles:spawn.hideturtle()
      spawn.penup()
      spawn.setposition(t.position())
      spawn.setheading(t.heading())
      spawn.forward(dist)

      
      sierpinski(i, spawn, new_size)

    
    sierpinski(i, t, new_size)

  else:
    
    pentagon(t, s)
    
    del t

def main():
  t = Turtle()
  t.hideturtle()
  t.penup()
  screen = t.getscreen()
  y = screen.window_height()
  t.goto(0, y/2-20)

  i = 5       
  size = 300  

  
  size *= part_ratio

  
  sierpinski(i, t, size)

main()