Skip to content

Instantly share code, notes, and snippets.

@categulario
Created June 20, 2015 04:22
Show Gist options
  • Select an option

  • Save categulario/ec51e27746b95b50c61b to your computer and use it in GitHub Desktop.

Select an option

Save categulario/ec51e27746b95b50c61b to your computer and use it in GitHub Desktop.
Crea el fractal de la alfombra de cantor usando la tortuga de python
from turtle import *
def square(size):
for i in range(4):
forward(size)
left(90)
def cantor(size, tolerance):
init = pos()
penup()
goto(init + (size/3, size/3))
pendown()
square(size/3)
if size/3<tolerance:
return
for i in (0, 1, 2):
for j in (0, 1, 2):
if i==1 and j == 1:
continue
penup()
goto(init + (i*size/3, j*size/3))
cantor(size/3, tolerance)
if __name__ == '__main__':
color('red', 'yellow')
speed(0)
size = 750
penup()
goto(-size/2, -size/2)
pendown()
begin_fill()
square(size)
cantor(size, 2)
end_fill()
done()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment