ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 28 Apr 2013 15:27:37 +0200Penrose tilings with Sagehttps://ask.sagemath.org/question/9455/penrose-tilings-with-sage/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!Mon, 22 Oct 2012 16:42:41 +0200https://ask.sagemath.org/question/9455/penrose-tilings-with-sage/Comment by benjaminfjones for <p>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!</p>
https://ask.sagemath.org/question/9455/penrose-tilings-with-sage/?comment=18816#post-id-18816What would the input be to such desired code?Thu, 25 Oct 2012 23:17:57 +0200https://ask.sagemath.org/question/9455/penrose-tilings-with-sage/?comment=18816#post-id-18816Comment by John Palmieri for <p>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!</p>
https://ask.sagemath.org/question/9455/penrose-tilings-with-sage/?comment=18835#post-id-18835You could try http://preshing.com/20110831/penrose-tiling-explained. An internet search for "penrose tiling algorithm" seems likely to be fruitful.Mon, 22 Oct 2012 22:15:03 +0200https://ask.sagemath.org/question/9455/penrose-tilings-with-sage/?comment=18835#post-id-18835Comment by benjaminfjones for <p>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!</p>
https://ask.sagemath.org/question/9455/penrose-tilings-with-sage/?comment=18811#post-id-18811Sorry, I meant how is the Penrose tiling represented? Fri, 26 Oct 2012 15:28:11 +0200https://ask.sagemath.org/question/9455/penrose-tilings-with-sage/?comment=18811#post-id-18811Comment by niles for <p>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!</p>
https://ask.sagemath.org/question/9455/penrose-tilings-with-sage/?comment=18788#post-id-18788Oh, I have no particular preference; a collection of polygons I suppose.Mon, 29 Oct 2012 11:42:16 +0100https://ask.sagemath.org/question/9455/penrose-tilings-with-sage/?comment=18788#post-id-18788Comment by niles for <p>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!</p>
https://ask.sagemath.org/question/9455/penrose-tilings-with-sage/?comment=18827#post-id-18827Well, 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.Tue, 23 Oct 2012 16:46:49 +0200https://ask.sagemath.org/question/9455/penrose-tilings-with-sage/?comment=18827#post-id-18827Comment by niles for <p>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!</p>
https://ask.sagemath.org/question/9455/penrose-tilings-with-sage/?comment=18812#post-id-18812Inputs 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).Fri, 26 Oct 2012 14:49:14 +0200https://ask.sagemath.org/question/9455/penrose-tilings-with-sage/?comment=18812#post-id-18812Answer by araichev for <p>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!</p>
https://ask.sagemath.org/question/9455/penrose-tilings-with-sage/?answer=14679#post-id-14679 # 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)
Sat, 23 Mar 2013 19:08:26 +0100https://ask.sagemath.org/question/9455/penrose-tilings-with-sage/?answer=14679#post-id-14679Comment by niles for <pre><code># 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)
</code></pre>
https://ask.sagemath.org/question/9455/penrose-tilings-with-sage/?comment=17793#post-id-17793Thanks! 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.htmlSun, 28 Apr 2013 15:27:37 +0200https://ask.sagemath.org/question/9455/penrose-tilings-with-sage/?comment=17793#post-id-17793Comment by vdelecroix for <pre><code># 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)
</code></pre>
https://ask.sagemath.org/question/9455/penrose-tilings-with-sage/?comment=17994#post-id-17994Nice code ! Actually, the code is much faster if you replace the symbolic constants (sqrt(5) and the exponential) by real numbers.Fri, 29 Mar 2013 08:54:05 +0100https://ask.sagemath.org/question/9455/penrose-tilings-with-sage/?comment=17994#post-id-17994