Gingerbread man fractal with generativepy


Martin McBride, 2021-06-12
Tags gingerbread man fractal
Categories generativepy generative art
In Generative art

The gingerbread man is another fractal that works in a similar way to the tinkerbell fractal. It is worth reading the tinkerbell fractal article before tackling the gingerbread man fractal in this article.

Gingerbread man formula

The fractal equations for gingerbread man are:

xnext = 1 - y + abs(x)
ynext = x

There are no parameters, and the required initial values are:

x = -0.01  # Initial value
y = 0      # Initial value

For this fractal, we are reusing the black and white version of the tinkerbell fractal. That mean each pixel will be black if the algorithm lands there one or more times, or it will be white if the algorithm never lands there.

We could count the the number of times each pixel is visited, and give each count a different colour, like we did for the coloured tinkerball fractal. But it turns out that isn't very interesting, it just looks like random noise. The black and white image is more striking.

Here is the result:

The code

Here is the full code for the image above:

from generativepy.bitmap import Scaler
from generativepy.nparray import make_nparray

MAX_COUNT = 1000000

def paint(image, pixel_width, pixel_height, frame_no, frame_count):
    scaler = Scaler(pixel_width, pixel_height, width=12, startx=-3.5, starty=-3.5)

    x = -0.1
    y = 0.0
    for i in range(MAX_COUNT):
        x, y = 1 - y + abs(x), x
        px, py = scaler.user_to_device(x, y)
        image[py, px] = 0

make_nparray('gingerbread.png', paint, 600, 600, channels=1)
If you found this article useful, you might be interested in the book Computer Graphics in Python or other books by the same author.