Gingerbread man fractal in generativepy
- Categories:
- generative art
- fractal
The gingerbread man is another fractal that works similarly to the Tinkerbell fractal. It is worth reading the Tinkerbell fractal article before tackling the gingerbread man fractal in this article.
We are basing this fractal on the black and white Tinkerbell, rather than the coloured Tinkerbell, as explained below.
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 code from the black and white version of the Tinkerbell fractal. That means 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 number of times each pixel is visited, and give each count a different colour as we did for the coloured Tinkerbell 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)
This code is available on github in blog/fractals/gingerbread.py.
This code is similar to the Tinkerbell implementation, it simply changes the formula used and the Scaler
range.