Skip to content

Instantly share code, notes, and snippets.

@ambv
Last active July 28, 2022 17:51
Show Gist options
  • Save ambv/bf22507e95c6a73375c5d357f04beac8 to your computer and use it in GitHub Desktop.
Save ambv/bf22507e95c6a73375c5d357f04beac8 to your computer and use it in GitHub Desktop.
A tessellation inspired by the Alhambra. The exercise only made me appreciate the original piece of art more.
from turtle import *
WIDTH = 1280
HEIGHT = 800
RADIUS = 50
def init():
setup(WIDTH, HEIGHT)
setworldcoordinates(0, 0, WIDTH, HEIGHT)
hideturtle()
tracer(0, 0)
def draw_one(x, y, radius):
up()
width(1)
goto(x, y)
forward(radius)
right(90)
down()
forward(WIDTH)
backward(2 * WIDTH)
left(90)
def outline(x, y, w, outer_radius, outline_length):
def draw(*turn):
unwind = 0
for angle in turn:
unwind -= angle
left(angle)
forward(outline_length)
left(unwind)
up()
width(w)
goto(x, y)
forward(outer_radius)
down()
draw(60, 90, -60, 90, -60, 90)
init()
shift = False
for y in range(0, HEIGHT, int(3.46 * RADIUS)):
for x in range(0 if not shift else 2 * RADIUS, WIDTH, 4 * RADIUS):
for i in range(12):
draw_one(x, y, RADIUS)
right(30)
for i in range(4):
outline(x, y, 4, 1.15 * RADIUS, 0.422222 * RADIUS)
if shift:
outline(x, y, 3, 0.85 * RADIUS, 0.31 * RADIUS)
right(90)
shift = not shift
update()
done()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment