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
40
votes
15 answers

Code golf: the Mandelbrot set

Usual rules for the code golf. Here is an implementation in python as an example from PIL import Image im = Image.new("RGB", (300,300)) for i in xrange(300): print "i = ",i for j in xrange(300): x0 = float( 4.0*float(i-150)/300.0…
Stefano Borini
  • 138,652
  • 96
  • 297
  • 431
37
votes
7 answers

Smooth spectrum for Mandelbrot Set rendering

I'm currently writing a program to generate really enormous (65536x65536 pixels and above) Mandelbrot images, and I'd like to devise a spectrum and coloring scheme that does them justice. The wikipedia featured mandelbrot image seems like an…
Nick Johnson
  • 100,655
  • 16
  • 128
  • 198
29
votes
4 answers

Which color gradient is used to color mandelbrot in wikipedia?

At Wikipedia's Mandelbrot set page there are really beautiful generated images of the Mandelbrot set. I also just implemented my own Mandelbrot algorithm. Given n is the number of iterations used to calculate each pixel, I color them pretty simple…
q9f
  • 11,293
  • 8
  • 57
  • 96
11
votes
2 answers

Mandelbrot Set implementation in Common Lisp

I've been working on an implementation of the Mandelbrot Set in several different languages. I have a working implementation in C++, C#, Java, and Python, but the Common Lisp implementation has some bugs that I just can't figure out. It generates…
Robert Mason
  • 3,949
  • 3
  • 31
  • 44
10
votes
9 answers

Lua Challenge: Can you improve the mandelbrot implementation’s performance?

Status: So far the best answer's program executes in 33% of the time of the original program! But there is probably still other ways to optimize it. Lua is currently the fastest scripting language out there, however Lua scores really bad in a few…
Robert Gould
  • 68,773
  • 61
  • 187
  • 272
9
votes
1 answer

Why does my program keep getting stuck while running the mandelbrot brainf*** program?

I wanted to improve my C skills, so I search some program's ideas. Someone propose to create a simple Brainf*** interpreter and then a compiler. So here I am. I created the interpreter and it works as expected, except with the Mandelbrot program: A…
tteixeira
  • 321
  • 2
  • 8
9
votes
3 answers

Making C# mandelbrot drawing more efficient

First of all, I am aware that this question really sounds as if I didn't search, but I did, a lot. I wrote a small Mandelbrot drawing code for C#, it's basically a windows form with a PictureBox on which I draw the Mandelbrot set. My problem is, is…
Omer Tuchfeld
  • 2,886
  • 1
  • 17
  • 24
8
votes
2 answers

Multithreaded & SIMD vectorized Mandelbrot in R using Rcpp & OpenMP

As an OpenMP & Rcpp performance test I wanted to check how fast I could calculate the Mandelbrot set in R using the most straightforward and simple Rcpp+OpenMP implementation. Currently what I did was: #include #include //…
Tom Wenseleers
  • 7,535
  • 7
  • 63
  • 103
7
votes
2 answers

Why is turtle lightening pixels?

My program for creating a Mandelbrot set has a bug: whenever the pen changes colors, and every 42nd pixel after that, is lighter. This is, rather coincidentally, a mandelbug (yes, I just learned that term), as it is inconsistent for many pixels near…
IronBeard
  • 229
  • 2
  • 4
  • 12
7
votes
5 answers

For all the creative people out there: coloring mandelbrot set... need ideas

Given max amount of iterations = 1000 give me some ideas on how to color (red, green, blue) it. All I can come up right now are lame 2 color gradients :( Is it actually possible to come up with something as beautiful as this?
Carpe Diem
  • 107
  • 2
  • 8
7
votes
1 answer

Can't find a way to color the Mandelbrot-set the way i'm aiming for

I've been successful in coloring the Mandelbrot-set although I can't zoom in very far until it becomes "blurry" and the pattern stops. I fix this by increasing the max_iteration, this works but I get very few colors at *1 magnification and lot's of…
MorganS42
  • 656
  • 4
  • 21
7
votes
1 answer

Implementing smooth colouring in mandelbrot set

I am trying to colour MandelBrot using HSV values and the PIL Library. Even after multiple tries fiddling with HSV values, I could not achieve the desired effect. here is what I currently have Here is the desired effect This is the code that I am…
darkermuffin
  • 919
  • 1
  • 7
  • 16
7
votes
2 answers

Why would an image (the Mandelbrot) be skewed and wrap around?

So I just wrote a little snippet to generate the Mandelbrot fractal and imagine my surprise when it came out all ugly and skewed (as you can see at the bottom). I'd appreciate a point in the direction of why this would even happen. It's a learning…
user328062
7
votes
1 answer

Improvement to my Mandelbrot set code

I have the following Mandelbrot set code in C. I am doing the calculation and creating a .ppm file for the final fractal image. The point is that my fractal image is upside down, meaning it is rotated by 90 degrees. You can check it by executing my…
user1726549
6
votes
3 answers

What's wrong with my Mandelbrot set code?

I'm trying to implement the Mandelbrot set in C, but I'm having a weird problem. My code is as follows: #include #include #include int iterate_pt(complex c); int main() { FILE *fp; fp = fopen("mand.ppm",…
Nathan Jones
  • 4,904
  • 9
  • 44
  • 70
1
2 3
24 25