Skip to main content
added 13 characters in body
Source Link

There are a few tricks you can use to make a Mandelbrot renderer really fly.

Detect cycles

If a point lies inside the Mandelbrot set, successive iterations will cause it to decay into a cycle. The most economical way to detect this, I have found, is to do x iterations, test to see if it is the same as before, then increment x and repeat.

Draw a half resolution version first

That's a 1000x1500 image in your case. Calculate it such that each pixel represents a pixel in the real image. Then if a pixel is entirely surrounded by other pixels with the same iteration count, you can assume that it is it'salso has that iteration count and skip calculating it.

This technique can miss fine strands, but it saves an enormous amount of time. You should also use a flood fill style algorithm whenever you calculate an unskippable pixel to find other pixels that may previously have been considered skippable but aren't. This should fix most of the problems.

Also note that this is recursive. Before calculating the 1000x1500 version you should calculate a 500x750 version, before that a 250x375 version etc.

The SuperFractalThing trick If

If you want to calculate deep fractals, you need to use high precision, which can be a huge drain on calculation time. However, strictly speaking you only need to use high precision for one pixel.

We start from position \$p_0\$, and we follow the usual iterative formula:

\$p_{x+1}={p_x}^2+p_0\$

We record all the values of \$p_x\$ as regular, double precision complex numbers. Now we calculate \$q\$, but we do it by calculating \$d\$, where \$d_x=q_x-p_x\$:

\$d_{x+1} = 2d_xp_x + {d_x}^2 + (q_0-p_0)\$

This is a bit more complicated, but we only need to use double precision numbers, so it is much, much faster when deep zooming.

One issue is that the \$p\$ sequence has to be at least as long as the \$q\$ sequence, and we cannot tell the best \$p\$ sequence in advance. In practice we often have to calculate new \$p\$ sequences using high precision arithmetic as we discover pixels with a longer escape time.

Faster languages

There is no getting around it, Python is slow. NumPy can do the heavy lifting, which can speed it up dramatically, but it's pretty awkward compared to the same code written in C. I suggest learning to use Ctypes and writing a small C library to follow the iterative formula.

There are a few tricks you can use to make a Mandelbrot renderer really fly.

Detect cycles

If a point lies inside the Mandelbrot set, successive iterations will cause it to decay into a cycle. The most economical way to detect this, I have found, is to do x iterations, test to see if it is the same as before, then increment x and repeat.

Draw a half resolution version first

That's a 1000x1500 image in your case. Calculate it such that each pixel represents a pixel in the real image. Then if a pixel is entirely surrounded by other pixels with the same iteration count, you can assume that it is it's iteration count skip calculating.

This technique can miss fine strands, but it saves an enormous amount of time. You should also use a flood fill style algorithm whenever you calculate an unskippable pixel to find other pixels that may previously have been considered skippable but aren't. This should fix most of the problems.

Also note that this is recursive. Before calculating the 1000x1500 version you should calculate a 500x750 version, before that a 250x375 version etc.

The SuperFractalThing trick If you want to calculate deep fractals, you need to use high precision, which can be a huge drain on calculation time. However, strictly speaking you only need to use high precision for one pixel.

We start from position \$p_0\$, and we follow the usual iterative formula:

\$p_{x+1}={p_x}^2+p_0\$

We record all the values of \$p_x\$ as regular, double precision complex numbers. Now we calculate \$q\$, but we do it by calculating \$d\$, where \$d_x=q_x-p_x\$:

\$d_{x+1} = 2d_xp_x + {d_x}^2 + (q_0-p_0)\$

This is a bit more complicated, but we only need to use double precision numbers, so it is much, much faster when deep zooming.

One issue is that the \$p\$ sequence has to be at least as long as the \$q\$ sequence, and we cannot tell the best \$p\$ sequence in advance. In practice we often have to calculate new \$p\$ sequences using high precision arithmetic as we discover pixels with a longer escape time.

Faster languages

There is no getting around it, Python is slow. NumPy can do the heavy lifting, which can speed it up dramatically, but it's pretty awkward compared to the same code written in C. I suggest learning to use Ctypes and writing a small C library to follow the iterative formula.

There are a few tricks you can use to make a Mandelbrot renderer really fly.

Detect cycles

If a point lies inside the Mandelbrot set, successive iterations will cause it to decay into a cycle. The most economical way to detect this, I have found, is to do x iterations, test to see if it is the same as before, then increment x and repeat.

Draw a half resolution version first

That's a 1000x1500 image in your case. Calculate it such that each pixel represents a pixel in the real image. Then if a pixel is entirely surrounded by other pixels with the same iteration count, you can assume that it also has that iteration count and skip calculating it.

This technique can miss fine strands, but it saves an enormous amount of time. You should also use a flood fill style algorithm whenever you calculate an unskippable pixel to find other pixels that may previously have been considered skippable but aren't. This should fix most of the problems.

Also note that this is recursive. Before calculating the 1000x1500 version you should calculate a 500x750 version, before that a 250x375 version etc.

The SuperFractalThing trick

If you want to calculate deep fractals, you need to use high precision, which can be a huge drain on calculation time. However, strictly speaking you only need to use high precision for one pixel.

We start from position \$p_0\$, and we follow the usual iterative formula:

\$p_{x+1}={p_x}^2+p_0\$

We record all the values of \$p_x\$ as regular, double precision complex numbers. Now we calculate \$q\$, but we do it by calculating \$d\$, where \$d_x=q_x-p_x\$:

\$d_{x+1} = 2d_xp_x + {d_x}^2 + (q_0-p_0)\$

This is a bit more complicated, but we only need to use double precision numbers, so it is much, much faster when deep zooming.

One issue is that the \$p\$ sequence has to be at least as long as the \$q\$ sequence, and we cannot tell the best \$p\$ sequence in advance. In practice we often have to calculate new \$p\$ sequences using high precision arithmetic as we discover pixels with a longer escape time.

Faster languages

There is no getting around it, Python is slow. NumPy can do the heavy lifting, which can speed it up dramatically, but it's pretty awkward compared to the same code written in C. I suggest learning to use Ctypes and writing a small C library to follow the iterative formula.

Source Link

There are a few tricks you can use to make a Mandelbrot renderer really fly.

Detect cycles

If a point lies inside the Mandelbrot set, successive iterations will cause it to decay into a cycle. The most economical way to detect this, I have found, is to do x iterations, test to see if it is the same as before, then increment x and repeat.

Draw a half resolution version first

That's a 1000x1500 image in your case. Calculate it such that each pixel represents a pixel in the real image. Then if a pixel is entirely surrounded by other pixels with the same iteration count, you can assume that it is it's iteration count skip calculating.

This technique can miss fine strands, but it saves an enormous amount of time. You should also use a flood fill style algorithm whenever you calculate an unskippable pixel to find other pixels that may previously have been considered skippable but aren't. This should fix most of the problems.

Also note that this is recursive. Before calculating the 1000x1500 version you should calculate a 500x750 version, before that a 250x375 version etc.

The SuperFractalThing trick If you want to calculate deep fractals, you need to use high precision, which can be a huge drain on calculation time. However, strictly speaking you only need to use high precision for one pixel.

We start from position \$p_0\$, and we follow the usual iterative formula:

\$p_{x+1}={p_x}^2+p_0\$

We record all the values of \$p_x\$ as regular, double precision complex numbers. Now we calculate \$q\$, but we do it by calculating \$d\$, where \$d_x=q_x-p_x\$:

\$d_{x+1} = 2d_xp_x + {d_x}^2 + (q_0-p_0)\$

This is a bit more complicated, but we only need to use double precision numbers, so it is much, much faster when deep zooming.

One issue is that the \$p\$ sequence has to be at least as long as the \$q\$ sequence, and we cannot tell the best \$p\$ sequence in advance. In practice we often have to calculate new \$p\$ sequences using high precision arithmetic as we discover pixels with a longer escape time.

Faster languages

There is no getting around it, Python is slow. NumPy can do the heavy lifting, which can speed it up dramatically, but it's pretty awkward compared to the same code written in C. I suggest learning to use Ctypes and writing a small C library to follow the iterative formula.