# Gingerbread man fractal with generativepy

Categories: generativepy generative art

This article has been moved to my blog. Please refer to that article as it might be more up to date.

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)
```

## See also

## Join the PythonInformer Newsletter

Sign up using this form to receive an email when new content is added:

## Popular tags

2d arrays abstract data type alignment and angle animation arc array arrays bar chart bar style behavioural pattern bezier curve built-in function callable object chain circle classes clipping close closure cmyk colour combinations comparison operator comprehension context context manager conversion count creational pattern data science data types decorator design pattern device space dictionary drawing duck typing efficiency ellipse else encryption enumerate fill filter font font style for loop formula function function composition function plot functools game development generativepy tutorial generator geometry gif global variable gradient greyscale higher order function hsl html image image processing imagesurface immutable object in operator index inner function input installing iter iterable iterator itertools join l system lambda function latex len lerp line line plot line style linear gradient linspace list list comprehension logical operator lru_cache magic method mandelbrot mandelbrot set map marker style matplotlib monad mutability named parameter numeric python numpy object open operator optimisation optional parameter or pandas partial application path pattern permutations pie chart pil pillow polygon pong positional parameter print product programming paradigms programming techniques pure function python standard library radial gradient range recipes rectangle recursion reduce regular polygon repeat rgb rotation roundrect scaling scatter plot scipy sector segment sequence setup shape singleton slice slicing sound spirograph sprite square str stream string stroke structural pattern subpath symmetric encryption template tex text text metrics tinkerbell fractal transform translation transparency triangle truthy value tuple turtle unpacking user space vectorisation webserver website while loop zip zip_longest