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

How to define the matrix that will later contain Mandelbrot

I recently developed a simple function that does the work of defining whether a complex number is stable or not, to display the Mandelbrot set. She looks like this: def mandelbrot(x, y): c = complex(x, y) z = 0 for i in range(50): …
user19046914
0
votes
1 answer

Mutli Threaded Mandelbrot Set viewer with Java Swing

Attempting a multi-threaded Mandelbrot Set viewer in Java using Swing graphics. I've seen a few Mandelbrot Set programs and other multi threaded Swing apps that use BufferedImage and/or SwingWorker, but I'm wondering if this approach can work/be…
kanja klub
  • 121
  • 1
  • 1
  • 12
0
votes
1 answer

gpu.js with BigDecimal or float64array possible?

I am writing a mandelbrot-calculator with the help of gpu.js and till now, everything works perfectly fine. The only issue I am facing is, that the GPU only wants to compute 32-Bit floats. Or at least this is what the official docs are telling me.…
0
votes
1 answer

Progress Bar Causes Program to Halt and Lock, How Can I Fix It?

Below is the current code that I am working with. When I comment out the code to run the progress_bar function, code works perfectly as expected with the mandelbrot printed out into a seperate image file. Yet for whatever reason, when I try to…
0
votes
1 answer

Mandelbrot Set function crashes

i made a sim for the Mandelbrot Set function, zn + 1 = power(zn) + c and it work but when i get to the point were the function is unstable it crashes, now i have a boolen that when true makes a wire that connects all the circles, when its false its…
0
votes
2 answers

Problem with testing Linux cluster using the Mandelbrot set

I have a six-node cluster running Ubuntu 11.04 and MPICH2 1.4. I'm trying to test the graphics using the Mandelbrot set. The pmandel executable that is supposedly found in one of the MPICH2 subdirectories is supposed to render the Mandelbrot…
Ana
  • 1
0
votes
0 answers

zooming into mandelbrot set does not work as planned

I changed some things but i still have a similar problem. I am working on Mandelbrot zoom. I try to zoom in deeper at branches. I count the consecutive points in the set and return the branch if it reaches the defined length. Then I zoom into that…
Din
  • 33
  • 6
0
votes
1 answer

PIL ImageDraw.Draw() doesn't work when used in a function

I made a program that renders the Mandelbrot set to an image. I put the draw.point() method in a function, but it doesn't seem to actually draw on the final image, but if I put im.save() in the function it does work. The full code actually uses…
0
votes
1 answer

Color gradient for Mandelbrot Android application doesn't work

I'm trying to to program the Mandelbrot set for Android. I try to draw it on a Canvas. It works, but I want to have a color gradient. This is my code: package de.turbofractal; import android.app.AlertDialog; import android.content.Context; import…
Henry
  • 3
  • 2
0
votes
0 answers

I am attempting to plot a Mandelbrot fractal in python, but I'm not getting the desired output

I am new to coding and I'm trying to create a basic Mandelbrot, but my output is a straight line. When I check the length of the two lists I generated to plot, my function only places 9 elements outside of the Mandelbrot set. Can someone take a look…
Raj
  • 1
  • 1
0
votes
0 answers

How to generate and draw Mandelbrot sets with parallel code in R?

I would like to do parallel coding in R. So far I have found some examples like the following, which works fine: library(parallelly) library(parallel) library(future) # define function to test whether an number is prime is_prime <- function(num) { …
0
votes
2 answers

Zooming in on Mandelbrot set

I have the following code: # MANDELBROT a = np.arange(-2, 2, 0.01) b = np.arange(-2, 2, 0.01) M_new = new_matrix(a, b) plt.imshow(M_new, cmap='gray', extent=(-2, 2, -2, 2)) plt.show() ## ZOOMING a_2 = np.arange(0.1, 0.5, 0.01) b_2 =…
krolik2002
  • 53
  • 5
0
votes
1 answer

Mandelbrot set rotation JS

There is a simple JS code that renders a very basic Mandelbrot fractal. let canvas = document.getElementsByTagName("canvas")[0], canvasWidth = canvas.width, canvasHeight = canvas.height, ctx = canvas.getContext("2d"); const maxIterations =…
toowren
  • 85
  • 7
0
votes
0 answers

setRGB not working in Runnable Mandelbrot set

I need to draw the Mandelbrot set using parallel programming, the language used is Java. I employ Runnable tasks to do that. As setRGB is synchronized, I don't need locks to control concurrency and also the BufferedImage shared between all threads…
Alfonso
  • 13
  • 3
0
votes
1 answer

Can't zoom in on a mandelbrot set with matplotlib, instead it just cuts off the part I try to zoom

My code is as follows: import numpy as np import matplotlib.pyplot as plt def mandelbrot(c): z = complex(0, 0) for i in range(0, 100): z = z*z+c if abs(z) > 2: return(i) return 100 M = np.zeros([401, 401]) a…