# Fractals/Iterations in the complex plane/MandelbrotSetExterior

Colouring of exterior of Mandelbrot set can be :
* non-smooth = Escape Time = dwell
** Boolean/binary Escape Time Method ( bETM/M )
** discrete = Level Set Method = LSM/M = integer ETM = iETM/M
* Smooth :
** radial measures
*** Real Escape Time Method( rETM/M )
*** Distance Estimation Method( DEM/M )
*** radius of complex potential = Complex Potential Method ( CPM/M )
** angular measures
*** argument of complex potential
*** SAC = stripe average coloring
*** other
**** "triangle inequality"
**** Orbit trap
One can also draw curves :
* external rays
* equipotential lines ( closed curves - quasi circles)
Similar projects:
* Mandelbrot Notebook by Claude Heiland-Allen
** mandelbrot-book
** mandelbrot-book/book : one file c programs , images and description
** fork of the mandelbrot-book and book in pdf format
* different drawing techniques and algorithms by Arnaud Cheritat
** Mandelbrot set and example C programs ( not by A Cheritat)
* Linas Vepstas' Art Gallery:
** original site
** fork at gitlab

## Escape time or dwell

Here for given point c on parameter plane one checks how critical point $z=0.0$ behaves on dynamical plane under forward iteration. If you change initial point you will get different result
To draw given plane one needs to check/scan (all) its points. See here for more details ( optimisation) Read definitions first.

### How to find the number of iterations required to escape the mandelbrot set ?

* math.stackexchange question: is-there-an-equation-for-the-number-of-iterations-required-to-escape-the-mandelb
* math.stackexchange question: a-way-to-determine-the-ideal-number-of-maximum-iterations-for-an-arbitrary-zoom?

### Boolean escape time

This algorithm answers the question: “For which values of c will the Julia fractal, J(c), be line-like and for which dust-like?”
Here complex plane consists of 2 sets : Mandelbrot set $M\,$ and its complement $M^{c}\,$ :
$\mathbb {C} =M\cup M^{c}$

#### ASCI graphic ( on screen)

Comparison programs in various languages

#### Graphic file ( PPM )

Here are various programs for creating pbm file
* GLSL using shadertoy
* short c programs by ed Burke

##### C

This is complete code of C one file program.
* It makes a ppm file which consists an image. To see the file (image) use external application ( graphic viewer).
* Program consists of 3 loops:
** iY and iX, which are used to scan rectangle area of parameter plane
** iterations.
For each point of screen (iX,iY) it's complex value is computed c=cx+cy*i.
For each point c is computed iterations of critical point $z_{0}=z_{cr}=0\,$
It uses some speed_improvement. Instead of checking :
it checks :
It gives the same result but is faster.

### Integer escape time = LSM/M = dwell bands

* Number of details is proportional to maximal number of iterations
* Mandelbrot animation based on a static number of iterations per pixel. Here you can see why offset is sometimes used ( because - color gradient changes : for high MaxIteration disapears.
Here color is proportional to last iteration ( of final_n, final iteration).
This is also called Level Set Method ( LSM )
$L_{n}=\{c:z_{n}\in T~~{\mbox{and}}~~z_{k}\notin T~~{\mbox{where}}~~k<n\}\,$

#### C

Difference between Mandelbrot algorithm and LSM/M is in only in part instruction, which computes pixel color of exterior of Mandelbrot set. In LSM/M is :
Here is C function whithout explicit complex numbers, only doubles:
here a short code with complex numbers:

#### C++

Here is C++ function which can be used to draw LSM/M :
I think that it can't be coded simpler (it looks better than pseudocode), but it can be coded in other way which can be executed faster .
Here is faster code :
A touch more optimised :
* Rendering The Mandelbrot Set In C++: Part 1 - Saving Images , Video by Superdavo0001

#### GLSL

* shadertoy

#### Java Script

Here is JavaScript function which does not give last iteration but LastIteration modulo maxCol. It makes colour cycling ( if maxCol < maxIt ).
Above functions do not use explicit definition of complex number.

#### Khan Academy

* khan academy mandelbrot-set

#### Lisp program

Whole Lisp program making ASCII graphic based on code by Frank Buss

#### Pov-Ray

Pov-Ray has a built-in function mandel

#### Wolfram Mathematica

Here is code by Paul Nylander

### Level Curves of escape time Method = LCM/M

Lemniscates are boundaries of Level Sets of escape time ( LSM/M ). They can be drawn using :
* edge detection of Level sets.
** Algorithm described in paper by M. Romera et al. This method is fast and allows looking for high iterations.
* boundary trace
* drawing curves $L_{n}(T)=\{c:abs(z_{n})=ER\}\,$, see explanation and source code. This method is very complicated for iterations > 5.

### Decomposition of target set for Mandelbrot set drawing

Decomposition is modification of escape time algorithm.
The target set is divided into parts (2 or more). Very large escape radius is used, for example ER = 12.

#### Binary decomposition of LSM/M

Here target set $T\,$ on dynamic plane is divided into 2 parts (binary decomposition = 2-decomposition ):
* upper half ( white) $T_{u}=\{z:|z|>ER~~{\mbox{and}}~~Im(z)>0\}\,$
* lower half (black) $T_{l}=\{z:|z|>ER~~{\mbox{and}}~~Im(z)\leq 0\}\,$
Division of target set induces decomposition of level sets $L_{n}\,$ into $2^{n+1}\,$ parts ( cells, subsets):
* $L_{n,u}=\{c:|z_{n}|>ER~~{\mbox{and}}~~Im(z_{n})>0\}\,$ which is colored white,
* $L_{n,l}=\{c:|z_{n}|>ER~~{\mbox{and}}~~Im(z_{n})\leq 0\}\,$ which is colored black.
For binary decomposition use exp(pi) as escape radius, so that the boxes appear square (a tip from mrob).
External rays of angles (measured in turns):
$angle=(k/2^{n})~~{\mbox{mod }}~1\,$
can be seen as borders of subsets.
Difference between binary decomposition algorithm and Mandel or LSM/M is in only in part of instruction , which computes pixel color of exterior of Mandelbrot set. In binary decomposition is :
also GLSL code from Fragmentarium :
Point c is plotting white or black if imaginary value of last iteration ( Zy) is positive or negative.

#### nth-decomposition

This method is extension of binary decomposition.
The target set T = { z : |zn| > R } with a very large escape radius ( for example R = 12 ) is divided into more than 2 parts ( for example 8).

### Real Escape Time

Other names of this method/algorithm are :
* the fully-renormalized fractional iteration count ( by Linas Vepstas in 1997)
* smooth iteration count for generalized Mandelbrot sets ( by Inigo Quilez in 2016)
* continuous iteration count for the Mandelbrot set
* Normalized Iteration Count Algorithm
* Continuous coloring
* smooth colour gradient
* fractional iterations
* fractional escape time
Here color of exterior of Mandelbrot set is proportional not to Last Iteration ( which is integer number) but to real number :
    $\nu (z)=\lim _{i\to \infty }(i-\log _{2}\log _{2}|z_{i}|)\,$
Other methods and speedups
Colouring formula in Ultrafractal :
where :
* log(log(bailout) can be precalculated

#### theory

Description by Claude :
First description :
If R is large, the first z to escape satisfies (approximately)
so taking logs
so taking logs again
so by algebra
when $|z|$ at escape is bigger, the smooth iteration count should be smaller, so this value needs to be subtracted from the integer iteration count
Alternatively this fraction can be used for interpolation, or used with arg(z) for exterior tiling / binary decomposition.
Second description
pick a radius R > 2, then |Z| > R implies that |Z^2 + C| > |Z| and more generally that |Z| -> infinity, this gives R the name escape radius. proof is on math.stackexchange.com somewhere
now suppose R is large, and n is the first iteration where |Z_n| > R.
consider what happens when |Z_n| increases as you move the point C a bit further from the Mandelbrot set boundary.
eventually |Z_n| > R^2, but then |Z_{n-1}| > R, so the iteration count should be n - 1.
for smoothing, we want a value to add to n that is 0 when |Z_n| = R and -1 when |Z_n| = R^2.
taking logs, get log |Z| is between log(R) and 2 log(R)
taking logs again, get log log |Z| is between log log R and log log R + log 2
dividing by log 2, get log_2 log |Z| is between log_2 log R and log_2 log R + 1
subtracting log_2 log R gives (log_2 log |Z| - log_2 log R) is between 0 and 1
negating it gives a value between 0 and -1, as desired
so the smooth iteration count is
(replace 2 by P if you do Z^P + C)
see also http://linas.org/art-gallery/escape/escape.html which makes a value independent of R, but that is not so useful for some colouring algorithms (e.g. smooth part of escape count doesn't align with angle of final iterate)

#### C

To use log2 function add :
#include <math.h>
at the beginning of program.
where :
* Zx2 = Zx*Zx
* Zy2 = Zy*Zy
Here is another version by Tony Finch
based on equation
    $\nu (z)=n-\log _{2}\log(z_{n})\,$

#### Matemathica

Here is code by Paul Nylander. It uses different formula :
$cet=n+log_{2}ln(R)-log_{2}ln|z|$

#### Python

Python code using mpmath library

## Distance estimation DEM/M

* Exterior DEM/M
* simple boundary with DEM/M
* Boundary with DEM/M and Sobel filter
Variants :
* exterior DEM/M
* interior DEM/M
Description

## Complex potential

Description

# See also

* https://web.archive.org/web/20071008112609/http://rgba.scenesp.org/iq/trastero/fieldlines/
* http://fraktal.republika.pl/mset_bottcher.html

# References

* ↑ Mathematics of Divergent Fractals by
* ↑ jussi harkonen : coloring-techniques
* ↑ wikipedia : Orbit trap
* ↑ Mandelbrot Orbit Trap Rendering! Programming How-To Video by DKM101
* ↑ Java program by Dieter Röß showing result of changing initial point of Mandelbrot iterations
* ↑ Julia fractals in PostScript by Kees van der Laan, EUROTEX 2012 & 6CM PROCEEDINGS 47
* ↑ Fractal Benchmark by Erik Wrenholt
* ↑ 12-minute Mandelbrot: fractals on a 50 year old IBM 1401 mainframe
* ↑ Computer Language Benchmarks Game
* ↑ example-code-from-presentation-ways-of-seeing-julia-sets by ed Burke
* ↑ Computing the Mandelbrot set by Andrew Williams
* ↑ LIsp Program by Frank Buss
* ↑ Mandelbrot Set ASCII art at Bill Clementson's blog
* ↑ mandel function from 2.5.11.14 Fractal Patterns at Pov-Ray docs
* ↑ Drawing the Mandelbrot set by the method of escape lines. M. Romera et al.
* ↑ http://www.metabit.org/~rfigura/figura-fractal/math.html boundary trace by Robert Figura
* ↑ http://web.archive.org/20010415125044/www.geocities.com/CapeCanaveral/Launchpad/5113/fr27.htm%7C An open letter to Dr. Meech from Joyce Haslam in FRACTAL REPORT 27
* ↑ mandelbrot set n-th-decomposition
* ↑ linas.org : Renormalizing the Mandelbrot Escape
* ↑ I Quilez : mset_smooth
* ↑ fractalforums : What range/precision for fractional escape counts for Mandelbrot/Julia sets?
* ↑ fractalforums : gradient-pallet-with-two-colors
* ↑ fractalforums.org : can-anyone-help-me-understand-smooth-coloring
* ↑ Making Mandelbrot Set Movies by Tony Finch
* ↑ Linas Vepstas. Renormalizing the mandelbrot escape.
* ↑ mpmath Python library