Questions tagged [mandelbrot]

The Mandelbrot set is a fractal in the complex plane.

Many programmers write their own Mandelbrot generators as a way of sharpening their coding (and, to a lesser extent, maths) skills; there are interesting programming challenges to be solved, and a beautiful visual journey as you explore the depths of the set.

The algorithm

At its heart, plotting the Mandelbrot set is a question of complex maths:

  1. Map a grid of pixels to a region of the complex plane
  2. For each complex point, apply the formula Zn+1 = Zn + C, where:
    • C is the point's complex co-ordinates
    • Z0 = 0
  3. Iterate each point until the point is distance greater than 2 from the origin, or until you get bored (often a fixed iteration limit).
  4. If a pixel did not escape, it is part of the Mandelbrot set and traditionally represented by a black pixel; otherwise, apply your choice of colouring algorithm to decide what colour to paint the pixel.

Challenges

In the process of writing a non-naive Mandelbrot set plotter there are a number of algorithmic and architectural challenges to be solved.

On deep zooms it is possible to reach the limit of precision of the double type, leading to the question of how one might go further; arbitrary-precision arithmetic is one answer, while some brave souls implement their own fixed-point types.

Creating a plot is a very CPU-intensive process, so optimisation rapidly becomes important in order to be able to generate a plot in a reasonable time. As individual points do not depend on each other (with most plotting algorithms), it is possible to parallelise the work - which is itself a further challenge.

There is also the question of whether and how the user interacts with the plotter.

Further reading

  • Wikipedia has a detailed description of the fractal, its history, pseudo-code for the basic algorithm and descriptions of a number of extensions.
  • Wolfram has a purely mathematical description of the fractal and many links to related work.
361 questions
0
votes
0 answers

Mandelbrot set using normalized iteration count

I have the following Python program that endeavours to use the normalized iteration count algorithm to colour the Mandelbrot set: from PIL import Image import numpy as np from matplotlib.colors import hsv_to_rgb steps = 256 # maximum…
0
votes
1 answer

Ordering Mandelbrot edge points at some level of detail

Is there known way of assigning natural numbers (ordering) of Mandelbrot fractal edge points? Obviously there is an infinite number of such points, but at certain level of detail we can count them and order them. I'd like to order them in such way…
bartek
  • 2,921
  • 5
  • 26
  • 30
0
votes
0 answers

Make pre existing matplotlib graphs into a 2x2 subplot

I have made 4 blocks of code resulting in 4 different colourmesh graphs, each defined in this same way. I want to print these 4 graphs together in a 2x2 subplot. Is there a way I can retroactively apply these graphs like that in matplotlib?
Declan
  • 15
  • 1
  • 4
0
votes
0 answers

Graphing the Mandelbrot set using the C curses library

I am having trouble drawing the Mandelbrot set with Curses. I am looking mainly at this tutorial: https://www.codingame.com/playgrounds/2358/how-to-plot-the-mandelbrot-set/mandelbrot-set. My screen ends up just outputting rows of the same character…
Caspian Ahlberg
  • 934
  • 10
  • 19
0
votes
1 answer

Best way to render pixels to the screen in python?

I'm writing an interactive (zoom/pan) mandelbrot set viewer in python, and I'm having some performance issues. I'm currently using pyglet and PyOpenGL to render the pixels since I like how it handles mouse events. I generate the pixel values using…
0
votes
2 answers

Mandelbrot's algorithm not giving the desired result without using complex numbers

when i use the following algorithm for using the mandelbrot algorithm i get the a image similar to the image i want but it looks more like an outline of the final image and when i use the algorithm with complex numbers it gives a proper sharp…
Amit kh
  • 59
  • 1
  • 9
0
votes
1 answer

I don't know why the same code works for Julia but not work for Mandelbrot?

I have the following code that generates a Mandelbrot image. The white spaces around the image, which has to be gotten rid. import numpy as np import matplotlib.pyplot as plt from pylab import * from numpy import NaN def mandelbrot(C): z = 0 …
Daniel L
  • 31
  • 6
0
votes
1 answer

How to declare a variable in python without assigning a value?

I'm trying to create graphs of the Mandelbrot set. I have managed to do this by iterating over a lot of points but this takes a lot of processing power, so I'm now trying to generate a polynomial by iterating f(z) = z**2 + c many times and then…
olibpool
  • 33
  • 5
0
votes
0 answers

How can I convert a boolean matrix into a greyscale map?

I am trying to visualize the Mandelbrot Set so it can be like the image like this(https://mathworld.wolfram.com/SeaHorseValley.html). I have the function that returns a boolean array with True indicating It is a part of the Mandelbrot set and False…
Lonnie Kim
  • 11
  • 4
0
votes
0 answers

Mandelbrot set in Python

I have a problem. I'm doing a task for my lessons and I'm doing my best, but the teachers clues does not seem to help and I need to look for the problem myself facing the problem. To begin with, I had to translate that task from my native language…
Snorku
  • 13
  • 2
0
votes
1 answer

Draw interactive mandelbrot with pyglet

I have a function that calculates the Mandelbrot set in an numpy array of size (500,500). I can draw it in matplotlib. Now i want to zoom into the image via mouse click. I want to use pyglet for that but struggle with rendering. I know this (not…
Moanos
  • 314
  • 3
  • 11
0
votes
1 answer

Mandelbrot in python

I am trying to code a Mandelbrot set in python. But my code shows a black image instead of the Mandelbrot image. This is my full code. import numpy as np from PIL import Image def mandelbrot_count(c,n): z = 0j for i in range(n): z =…
Eka
  • 14,170
  • 38
  • 128
  • 212
0
votes
1 answer

My Mandelbrot set doesn't generate. What's wrong with my equation?

//Generator class public class Generator { double jump; double sizeModifier; int iterationRate,range; ComplexNumber c; public Generator(double jump) { this.jump=jump; this.sizeModifier=40; this.iterationRate=10; this.range=100; …
jamie
  • 176
  • 1
  • 12
0
votes
1 answer

Why does this Mandelbrot Calculation return a circle?

I try to calculate and display a Mandelbrot set with the following code but it always returns a circle. I think I understood the calculation but I can't find the error. Any help is very welcome. I know there are one or two other similiar questions…
0
votes
1 answer

What do these lines do when computing Mandelbrot set?

Not sure if this should go into Math Stack Exchange or here, but I can move it if needed. I have this piece of code that generates two matrices from which the Mandelbrot set is plottable and I am trying to understand it. def mandelbrot_set(xmin,…
whatwhatwhat
  • 1,991
  • 4
  • 31
  • 50