[Rod Stephens Books]
Index Books Python Examples About Rod Contact
[Mastodon] [Bluesky]
[Build Your Own Ray Tracer With Python]

[Beginning Database Design Solutions, Second Edition]

[Beginning Software Engineering, Second Edition]

[Essential Algorithms, Second Edition]

[The Modern C# Challenge]

[WPF 3d, Three-Dimensional Graphics with WPF and C#]

[The C# Helper Top 100]

[Interview Puzzles Dissected]

Title: Draw the burning ship fractal in Python and tkinter

[The burning ship fractal drawn in tkinter and Python]

This program is very similar to the Mandelbrot set program described in the post Draw the Mandelbrot set and zoom in on areas in Python and tkinter. See that post for most of the details.

The big difference is that this program uses the absolute values of each point's real and imaginary parts when it iterates. Here's the equation that this program iterates.

Zn+1 = (|Re(Zn)| + |Im(Zn)| × i)2 + C

Where C = 0 and Z0 is the point.

Here's the Python code that calculates the pixels' colors. The change, which takes the absolute values of Zs real and imaginary parts, is hilighted in blue.

# Loop over the pixels. for x in range(image_wid): for y in range(image_hgt): # Calculate this point's color. re, im = self.d_to_w(x, y) c = re + im * 1j z = z0 iteration = 0 while ((iteration < max_iterations) and (abs(z) < escape_radius)): # Calculate Z(clr). z = abs(z.real) + abs(z.imag) * 1j z = z * z + c iteration += 1 # Set the pixel's color. if (iteration >= max_iterations): color = black else: color = colors[iteration % len(colors)] self.pixels[x, y] = color

Download the example to experiment with it and to see additional details.

[The burning ship fractal drawn in tkinter and Python] [The burning ship fractal drawn in tkinter and Python] [The burning ship fractal drawn in tkinter and Python] [The burning ship fractal drawn in tkinter and Python]
© 2025 Rocky Mountain Computer Consulting, Inc. All rights reserved.