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
2
votes
1 answer

Controlling where to zoom in on the Mandelbrot set

I wrote a simple fragment shader that renders a mandelbrot set. I am doing this in c and with opengl using glsl. #version 330 core in vec2 fCoord; //position.x position.y which is -1 to 1 on both axis uniform int maxIterations; uniform sampler1D…
user1610950
  • 1,837
  • 5
  • 33
  • 49
2
votes
2 answers

mandlebrot fractal error in the plotted function

Hello guys i am trying plotting the mandlebrot fractal but the result is very far from it, can you help me to find the why? Here is the code: void Button1Click(object sender, EventArgs e) { Graphics g = pbx.CreateGraphics(); Pen p = new…
2
votes
1 answer

Hybrid openmp mpi mandelbrot code

Im facing one problem: ive done the mpi version of mandelbrot and it works perfect. Then i have to implement an hybrid version using openmp. Ive put openmp parallelization in the loop with all the calculations ( inside function calculoMandelbrot).…
2
votes
3 answers

Max resolution of .bmp file format

I have made a Mandelbrot fractal generator (who hasn't, I know) which can render directly to disk to generate huge fractals. My first test was a UHD 4k resolution which turned out great (8-bit colour for all of these examples). So I decided to go…
allanmb
  • 321
  • 3
  • 14
2
votes
3 answers

Multithreading computation of Mandelbrot set

I have created a program which creates a Mandelbrot set. Now I'm trying to make it multithreaded. // mandelbrot.cpp // compile with: g++ -std=c++11 mandelbrot.cpp -o mandelbrot // view output with: eog mandelbrot.ppm #include #include…
Sybren
  • 1,071
  • 3
  • 17
  • 51
2
votes
1 answer

C++ Mandelbrot program won't produce correct output

I am trying to make a program that generates an image of the standard Mandelbrot set by making a .PPM file. The program doesn't produce a valid PPM file and I have no clue why. Here is my code: #include #include using namespace…
maxun
  • 25
  • 6
2
votes
2 answers

Very fast pixel on screen drawing

A friend of mine had to draw a mandelbrot with opengl in c. I decided to do it in Swift. The first method I tried was by creating an array with ARGB data and convert this into a CGImage and view that one in an UIImageView. However this was not fast…
Simon
  • 2,419
  • 2
  • 18
  • 30
2
votes
3 answers

Help with rendering the Mandelbrot set in Java

I wrote an implementation of the Mandelbrot set in Java using a JComponent but I'm getting strange results when I render it. Besides that everything compiles right. I'm just not for sure what I'm doing wrong with it. Any code review also would be…
SDLFunTimes
  • 745
  • 2
  • 7
  • 13
2
votes
1 answer

How can I fix this issue with my Mandelbrot fractal generator?

I've been working on a project that renders a Mandelbrot fractal. For those of you who know, it is generated by iterating through the following function where c is the point on a complex plane: function f(c, z) return z^2 + c end Iterating through…
David
  • 693
  • 1
  • 7
  • 20
2
votes
2 answers

Improving Javascript Mandelbrot Plot Performance

I have written a javascript program which plots the Mandelbrot set with the normal pretty colours approaching the boundary. I was planning on adding a zoom function next but it is far far too slow for this to be sensible. I have posted the most…
user1977132
  • 487
  • 2
  • 18
2
votes
1 answer

Redraw Mandelbrot in Bokeh?

I am learning to use Bokeh for an interactive plotting tool. The issue I have is similar to the case in a Mandelbrot chart, when zooming into it, the new area is redraw. This requires BokehJS to send the new X and Y ranges back the Bokeh backend to…
Shiwen
  • 21
  • 2
2
votes
1 answer

Implementing a smooth color algorithm into my existing Mandelbrot generator

I am currently writing a Mandelbrot generator, and stumbled onto a smooth color algorithm that creates a, as its name suggests, a "smooth color" as opposed to the example I currently have. As you can see, the edge cases are very evident and…
theGreenCabbage
  • 5,197
  • 19
  • 79
  • 169
2
votes
1 answer

Mandelbrot Set Zooming and Panning

I have coded a Mandelbrot Set Fractal in Java and have included the ability to pan and zoom in on the fractal a certain amount. The only thing is that when I pan the image and try to zoom in, it looks as if it tries to zoom in on the center and pans…
BigBerger
  • 1,765
  • 4
  • 23
  • 43
2
votes
1 answer

Mandelbrot in OpenCL

I have this Mandelbrot Kernel written for an OpenCL program. For test I've decided to have all my complex plane on a vector. My problem is when I print the output I obtain a list of 1 (like the initialization of the results array) and not the result…
2
votes
0 answers

Problems computing the normalized iteration count with numpy

This is the code I've got so far: import numpy as np def mandelbrot(resol): R, I = np.meshgrid(np.linspace(-2,.5,resol), np.linspace(1.25j,-1.25j,resol)) Z = R + I C = np.array(Z) iterations = np.zeros(Z.shape, dtype=np.uint8) …
Broseph
  • 1,655
  • 1
  • 18
  • 38