Ask Your Question
3

Penrose tilings with Sage

asked 2012-10-22 16:42:41 +0100

niles gravatar image

I would like to make a poster from a Penrose tiling. Google didn't give me any Sage code for doing this, but I wonder if someone here knows of such a thing!

edit retag flag offensive close merge delete

Comments

You could try http://preshing.com/20110831/penrose-tiling-explained. An internet search for "penrose tiling algorithm" seems likely to be fruitful.

John Palmieri gravatar imageJohn Palmieri ( 2012-10-22 22:15:03 +0100 )edit

Well, yes. I was hoping for some enterprising person to turn the explanation into code for me! ;) And in fact I'd like code which lets me color the tiling in some enlightening way.

niles gravatar imageniles ( 2012-10-23 16:46:49 +0100 )edit

What would the input be to such desired code?

benjaminfjones gravatar imagebenjaminfjones ( 2012-10-25 23:17:57 +0100 )edit

Inputs would be size of the output image, and maybe some options for how the picture is colored (highlight symmetry, or highlight method of construction, perhaps).

niles gravatar imageniles ( 2012-10-26 14:49:14 +0100 )edit

Sorry, I meant how is the Penrose tiling represented?

benjaminfjones gravatar imagebenjaminfjones ( 2012-10-26 15:28:11 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
4

answered 2013-03-23 19:08:26 +0100

araichev gravatar image
# Adapted from http://preshing.com/20110831/penrose-tiling-explained

golden_ratio = (1 + sqrt(5))/2

def subdivide(triangles):
    result = []
    for color, A, B, C in triangles:
        if color == 0:
            # Subdivide red triangle
            P = A + (B - A) / golden_ratio
            result += [(0, C, P, B), (1, P, C, A)]
        else:
            # Subdivide blue triangle
            Q = B + (A - B) / golden_ratio
            R = B + (C - B) / golden_ratio
            result += [(1, R, C, A), (1, Q, R, B), (0, R, Q, A)]
    return result

# Create wheel of red triangles around the origin
triangles = []
for i in xrange(10):
    B = exp((2*i - 1)*pi/10*I)
    C = exp((2*i + 1)*pi/10*I)
    if i % 2 == 0:
        B, C = C, B  # Make sure to mirror every second triangle
    triangles.append((0, 0, B, C))

# Draw n iterates
n = 5
for i in range(n):
    P = Graphics()
    for verts in triangles:
        #P += polygon([(z.real(), z.imag()) for z in verts[1:]], color=['red', 'blue'][verts[0]])
        P += line([(z.real(), z.imag()) for z in (verts[3], verts[1], verts[2])], color='black', thickness=2)
    P.show(axes=False, aspect_ratio=1)
    triangles = subdivide(triangles)
edit flag offensive delete link more

Comments

Nice code ! Actually, the code is much faster if you replace the symbolic constants (sqrt(5) and the exponential) by real numbers.

vdelecroix gravatar imagevdelecroix ( 2013-03-29 08:54:05 +0100 )edit

Thanks! I updated the code to allow various coloring schemes, draw circular sectors on the tiles, and output the graphics object so that differing levels of iteration can be overlaid: http://www.nilesjohnson.net/aperiodic-tilings.html

niles gravatar imageniles ( 2013-04-28 15:27:37 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-10-22 16:42:41 +0100

Seen: 1,426 times

Last updated: Mar 23 '13