File:Fibonacci word fractal, order 18.svg
| Uploaded by | Cosmia Nebula |
|---|---|
| Upload date | 2023-02-09T00:29:44Z |
| MIME type | image/svg+xml |
| Dimensions | 826 × 1979 px |
| File size | 621.4 KB |
Summary
| Description |
English: Fibonacci word fractal, order 18, with the sub-rectangles colored
Drawn in python. ```python from itertools import count, islice, groupby from math import floor, sqrt import matplotlib.pyplot as plt def sturm_word(ratio): xs = count(1) ys = map(lambda x : x * ratio, xs) fw = islice(groupby(map(floor, ys)), 1, None) return map(lambda x : 2 - len(list(x[1])), fw)
# if the symbol 0 is in an even position then turn left, else turn right def fib_line(fib_word, origin=(0, 0), length=1, angle=0): angle_dict = {
0: (1, 0),
90: (0, 1),
180: (-1, 0),
270: (0, -1)
}
is_even = True
x0, y0 = origin
current_angle=angle
while True:
dx, dy = angle_dict[current_angle]
x1, y1 = x0 + dx, y0 + dy
yield (x0, y0, x1, y1)
if next(fib_word) == 0:
if is_even:
current_angle += 90
else:
current_angle -= 90
current_angle %= 360
x0, y0 = x1, y1
is_even = not is_even
golden_ratio = (sqrt(5) - 1)/2 fib_word = sturm_word(golden_ratio) def fibs(n): f0, f1 = 0, 1 for _ in range(n): f0, f1 = f1, f0+f1 return f0 xfirst, yfirst, xlast, ylast = 0, 0, 0, 0 golden_ratio = (sqrt(5) - 1)/2 fib_word = sturm_word(golden_ratio) i = 0 fib_i = fibs(i) limit_i = 18 plt.figure (figsize= (20, 32)) for line_i, (x0, y0, x1, y1) in enumerate(fib_line(fib_word, origin=(0, 0), length=0.1, angle=0)): plt.plot([x0, x1], [y0, y1], 'k')
if line_i > fib_i - 2:
i, fib_i = i+1, fibs(i+1)
xfirst, yfirst, xlast, ylast = xlast, ylast, x1, y1
color = 'blue' if i % 2 == 0 else 'green'
r = plt.Rectangle((xfirst, yfirst), xlast-xfirst, ylast-yfirst, fc=color, ec='black', alpha=0.3)
plt.gca().add_patch(r)
if i > limit_i:
break
plt.gca().set_aspect('equal') plt.axis('off') plt.savefig('fib_word.svg', bbox_inches=0, transparent=True) ``` |
| Date | |
| Source | Own work |
| Author | Cosmia Nebula |
Licensing
I, the copyright holder of this work, hereby publish it under the following license:
| This file is made available under the Creative Commons CC0 1.0 Universal Public Domain Dedication. | |
| The person who associated a work with this deed has dedicated the work to the public domain by waiving all of their rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.
|