I was generating artistic depictions of mathematical concepts by programming for fun, I made some pictures of Pythagorean Spiral, and I noticed this pattern if I only show perfect squares:
Pythagorean Spiral depicting perfect squares up to 256:
Perfect squares up to 512:
Perfect squares up to 1024:
Perfect squares up to 2048:
I used the following function to calculate the spiral:
def pythogorean_spiral(iterations, mode='rim', num_colors=12, condition=None):
assert mode in ('rim', 'radial', 'triangles')
if condition:
assert condition in filters
filtered = condition(iterations)
step = 1530/num_colors
color_values = ['#'+spectrum_position(round(step*i), 1) for i in range(num_colors)]
colors = ['#ff0000']
collection = []
if not condition or 0 in filtered:
if mode == 'rim':
collection.append([(1, 0), (1, 1)])
if mode == 'radial':
collection.append([(0, 0), (1, 0)])
elif mode == 'triangles':
collection.append([(0, 0), (1, 0), (1, 1)])
cur_x, cur_y = 1, 1
for i in range(1, iterations):
radius = (cur_x ** 2 + cur_y ** 2) ** .5
new_radius = radius + 1
angle = atan2(cur_x, cur_y)
new_x, new_y = new_radius*cos(angle), new_radius*sin(angle)
new_x, new_y = rotate((new_x, new_y), 90, (cur_x, cur_y))
color = color_values[i % num_colors]
colors.append(color)
if not condition or i in filtered:
if mode == 'rim':
collection.append([(cur_x, cur_y), (new_x, new_y)])
if mode == 'radial':
collection.append([(0, 0), (cur_x, cur_y)])
elif mode == 'triangles':
collection.append([(0, 0), (cur_x, cur_y), (new_x, new_y)])
cur_x, cur_y = new_x, new_y
result = {'colors': colors}
if mode == 'rim':
result['rim'] = collection
if mode == 'radial':
result['radial'] = collection
elif mode == 'triangles':
result['triangles'] = collection
return result
Why am I seeing the triple spiral pattern?
Here is the data depicted in the image, in Python dictionary format, the key is the number, and the value is its position.
In [176]: find_squares(2048)
Out[176]:
{0: (1, 0),
1: (1, 1),
4: (-1.6308097207961918, 1.5298560894922917),
9: (-1.497112501918127, -2.7854360801498306),
16: (4.074022642113989, -0.6343023817884941),
25: (-1.1072688801027475, 4.977344234343855),
36: (-4.98458532826389, -3.4862457035120658),
49: (5.996732853004965, -3.7468913901647802),
64: (1.2030383665443862, 7.971994649309683),
81: (-8.74302530802115, -2.3578609932100782),
100: (6.317606591629188, -7.815871477538745),
121: (5.025225140018225, 9.83601099491705),
144: (-12.02537661686118, 0.6247537295991847),
169: (4.7131951151331055, -12.156717970187723),
196: (9.852134360350037, 9.996771906251038),
225: (-14.09884120422741, 5.217535500404312),
256: (1.119993543058584, -15.992048476149222),
289: (14.986552417661628, 8.08722737609624),
324: (-14.34564731859593, 10.917985299974568),
361: (-4.240153608700732, -18.547805729374634),
400: (19.62024563990485, 4.005741008826664),
441: (-12.349124780077803, 17.014673583882512),
484: (-10.871585332769126, -19.152248754449722),
529: (22.929824939835186, -2.055025116273555),
576: (-7.958753928923706, 22.66402956005053),
625: (-18.049465629543615, -17.326765147826205),
676: (24.17841787504091, -9.612705605598585),
729: (-1.3269058233345064, 26.985909674050397),
784: (-24.89305639538484, -12.858294727381011),
841: (22.812021983982696, -17.93353431430349),
900: (7.087529794682105, 29.16790910246232),
961: (-30.460426219812412, -5.844863942588621),
1024: (18.5398249709077, -26.101243074767932),
1089: (16.550145885300477, 28.56733573813433),
1156: (-33.85505726799531, 3.2916709101562596),
1225: (11.389197702942742, -33.11021255871532),
1296: (26.114611762933436, 24.799738959740765),
1369: (-34.33332875841694, 13.828323700524258),
1444: (1.7284388687767098, -37.97383966728841),
1521: (34.713383531937104, 17.80396033933651),
1600: (-31.401435769992876, 24.798182021733684),
1681: (-9.746528349261542, -39.83723365316765),
1764: (41.26708260884942, 7.875778879224264),
1849: (-24.891018197164836, 35.07758847338917),
1936: (-22.06172637665742, -38.08254494229001),
2025: (44.80188956600656, -4.334823100820575)}
I don't feel like explaining things, so here is the Wikipedia article.
Here is the full picture of the spiral with 256 triangles:
Picture of triangles in the spiral corresponding to perfect squares up to 256:
I made another image which is more descriptive, and the data it displays does indeed corroborate the accepted answer's theory: