File:Fibonacci word fractal, order 18.svg

From testwiki
Jump to navigation Jump to search
    Original file (SVG file, nominally 826 × 1,979 pixels, file size: 621 KB)

    This file is from Wikimedia Commons and may be used by other projects. The description on its file description page there is shown below.

    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)
    
    1. If the word is 1, then draw a line forward.
    2. If the word is 0, then first draw a line forward
     # 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:
    Creative Commons CC-Zero 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.

    Captions

    Fibonacci word fractal, order 18, with the sub-rectangles colored

    Items portrayed in this file

    depicts

    8 February 2023

    image/svg+xml

    636,272 byte

    5436adb26a1f2b66ce13695cb6d0b822c655253c

    File history

    Click on a date/time to view the file as it appeared at that time.

    Date/TimeThumbnailDimensionsUserComment
    current01:29, 9 February 2023Thumbnail for version as of 01:29, 9 February 2023826 × 1,979 (621 KB)wikimediacommons>Cosmia NebulaUploaded own work with UploadWizard

    There are no pages that use this file.