# Zeckendorf Representations

**URL:** <https://discourse.processing.org/t/zeckendorf-representations/31567>\
**Category:** Gallery\
**Created:** [August 3, 2021, 9:55pm UTC](https://discourse.processing.org/t/zeckendorf-representations/31567 "2021-08-03T21:55:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![javagar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/javagar/32/11434_2.png) [@javagar](https://discourse.processing.org/u/javagar)\
**Post date:** [August 3, 2021, 9:55pm UTC](https://discourse.processing.org/t/zeckendorf-representations/31567/1 "2021-08-03T21:55:53Z")

</div>

The following image is a graph of Zeckendorf representations of numbers 1 through 232:

 ![Zeckendorf](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/1/18ec08105d3b738146e522fd9f9cbaffec9a62c6.png)

> “Zeckendorf’s theorem states that every [positive integer](https://en.wikipedia.org/wiki/Positive_integer) can be represented [uniquely](https://en.wikipedia.org/wiki/Uniqueness_quantification) as the sum of _one or more_ distinct Fibonacci numbers in such a way that the sum does not include any two consecutive Fibonacci numbers.”

The above is quoted from:

> **[Zeckendorf's theorem](https://en.wikipedia.org/wiki/Zeckendorf%27s_theorem)**
>
> In mathematics, Zeckendorf's theorem, named after Belgian amateur mathematician Edouard Zeckendorf, is a theorem about the representation of integers as sums of Fibonacci numbers.
> Zeckendorf's theorem states that every positive integer can be represented uniquely as the sum of one or more distinct Fibonacci numbers in such a way that the sum does not include any two consecutive Fibonacci numbers. More precisely, if N is any positive integer, there exist positive integers ci ≥ 2, with ci + 1 \> c...

The graph is constructed of vertical bars that represent the Fibonacci numbers that comprise the Zeckendorf representations of integers, _n_. The values of _n_ range from 1 through 232 from left to right. Bars are drawn downward from the top of the graph. The height of each bar is proportional to the value of the Fibonacci number that it represents. For each _n_, the bars are drawn in order from tallest to shortest, with shorter bars superimposed over upper portions of taller ones, leaving the lower portions all bars at least partially visible.

The hue of the fill of each bar is based on the value of the Fibonacci number that it represents. The bars are drawn with no stroke, so adjacent bars that represent equal values merge to form areas of uniform color.

Code for Processing Python Mode:

```auto
# Graph of Zeckendorf Representations

# Set the phase of the hue cycle
hue_phase = 9

# Create a list of positive Fibonacci numbers
def fib(n):
    # modified from https://www.python.org/
    f = []
    a, b = 1, 2
    while a <= n:
        f.append(a)
        a, b = b, a + b
    return f
fibs = fib(233)

def zeckendorf(n):
    # Recursive function to return the Zeckendorf representation of n as a list
    if n in fibs:
        return [n]
    else:
        i = 0
        while n > fibs[i]:
            i += 1
        f = fibs[i - 1]
        l = [f]
        l.extend(zeckendorf(n - f))
        return l

def setup():
    size(935, 438)
    colorMode(HSB, len(fibs) - 1, 100, 100, 100)
    noLoop()
    noStroke()
    background(0, 0, 0)
    
def draw():
    # Draw graph of Zeckendorf representations for numbers 1 through 232
    for n in range(1, 233):
        for f in zeckendorf(n):
            # Calculate hue of fill
            fill((hue_phase + fibs.index(f)) % len(fibs), 100, 100, 100)
            rect(n * 4, 3, 4, f * 3)

```
