Wolfram Research

Function Repository Resource:

MandelbrotSetRemap (1.0.0) current version: 1.1.0 »

Source Notebook

Apply functions to remap the Mandelbrot set

Contributed by: Mark Greenberg and Rohit Namjoshi

ResourceFunction["MandelbrotSetRemap"][cen, mag]

renders a smooth mapping of the Mandelbrot set centered on cen with a magnification of mag.

Details and Options

The center cen should be a complex number.
The magnification mag can be any positive number, though greater magnification requires a higher MaxIterations setting to see the details and therefore longer render time. If mag is omitted, a default value of 1.25 is used.
ResourceFunction["MandelbrotSetRemap"] accepts the following options:
ColorFunctionAutomaticcolor applied to each pixel's remapped value v, where 0 ≤ v ≤ 1
ColorFunctionScalingTrueif True,v will be scaled to 0 ≤ v ≤ 1
ImageSize{260,200}size of the image
"MappingFunction""Smooth"function that remaps the Mandelbrot set
MaxIterations16maximum number of iterations for a pixel; higher values give more detail and longer render times
"Parallel"Falsewhether ParallelMap should be used to speed up computation; using "Parallel" with a preset will slow down the computation
If "MappingFunction" is a custom function that outputs a list of values, ColorFunction should accept a list as its argument.
ImageSizew is equivalent to ImageSize{w,w}.
Render times can increase greatly for larger images or complicated functions.
The "MappingFunction" option has several presets:
"Decomposition"based on the final vector angle of c
"LineOrbitTrap"based on the minimum distance of c to an arbitrary line
"ModTrailings"based on the modulus of c
"Smooth"(default) gives a smooth gradient inside and outside
"ThreePointsOrbitTrap"based on the minimum distance of c to equlateral triangle vertices
The preset mapping functions are compiled when they are first used, which can take several seconds to complete. Subsequent use of the preset uses the compiled version, which is significantly faster.
When using the "MappingFunction" option to specify a custom mapping function, the input should accept four arguments and have the general form customMapping[px,center,corner,maxIt], where:
pxcomplex location of the pixel currently being remapped
centercomplex location of the image's center
cornercomplex location of the image's lower-left corner
maxItmaximum number of iterations
center and corner are useful for mappings that scale or are aware of the image dimensions.

Examples

Basic Examples (2) 

Render a smooth mapping of the whole Mandelbrot set:

In[1]:=
ResourceFunction["MandelbrotSetRemap"][-.7]
Out[1]=

Zoom into part of the Mandelbrot set:

In[2]:=
ResourceFunction["MandelbrotSetRemap"][-.8 + .173 I, 110, MaxIterations -> 96]
Out[2]=
In[3]:=
ResourceFunction["MandelbrotSetRemap"][-1.54368901269109, 20, "MappingFunction" -> "LineOrbitTrap", ColorFunction -> "Psychedelic"]
Out[3]=

Options (10) 

ColorFunction (4) 

Use one of the presets, either the default "BlueGold" or the more vibrant color functions called "Vivid" and "Psychedelic":

In[4]:=
Table[ResourceFunction["MandelbrotSetRemap"][-.7, ColorFunction -> cf], {cf, {"BlueGold", "Vivid", "Psychedelic"}}]
Out[4]=

Assign a built-in color scheme to the mapping:

In[5]:=
Table[ResourceFunction["MandelbrotSetRemap"][-.7, ColorFunction -> cf], {cf, {"Rainbow", "BoldColorFractalGradient", ColorData[{"TemperatureMap", "Reversed"}]}}]
Out[5]=

Use the value(s) returned by the option "MappingFunction" as input to RGBColor, Hue or any function that returns a color:

In[6]:=
Table[ResourceFunction["MandelbrotSetRemap"][-.7, ColorFunction -> cf], {cf, {RGBColor[.5, #, #] &, Hue[#, #, Sqrt[#]] &}}]
Out[6]=

A custom mapping function can pass a list of values to a custom color function:

In[7]:=
myMapping = Function[{c, center, corner, maxIterations}, Module[{ boil, boil2, list},
    boil = Exp[-Abs[c]];
    list = NestWhileList[
      (boil += Exp[-Abs[#]]; boil2 = VectorAngle[{4, 3}, ReIm[#]]; #^2 + c) &,
      0, Abs[#] <= 8 &, 1, maxIterations];
    {Sin[boil], boil2^1.5}
    ]];
myColoring = Function[{val}, Hue[val[[2]], val[[1]], 1]];
ResourceFunction["MandelbrotSetRemap"][-.7, 1.3, "MappingFunction" -> myMapping, ColorFunction -> myColoring] // ImageAdjust
Out[8]=

ColorFunctionScaling (1) 

Set the ColorFunctionScaling option to False to use values outside 0 ≤ v ≤ 1 in custom color functions:

In[9]:=
Table[ResourceFunction["MandelbrotSetRemap"][-.7, ColorFunction -> (Hue[.75 - #, 1, Mod[#, 1] + .25] &), ColorFunctionScaling -> cfs], {cfs, {True, False}}]
Out[9]=

ImageSize (1) 

The ImageSize may be given as a single number for a square image or {w,h}:

In[10]:=
Table[ResourceFunction["MandelbrotSetRemap"][-.7, ImageSize -> sz], {sz, {260, {260, 100}}}]
Out[10]=

MappingFunction (2) 

Use one of five preset mapping functions:

In[11]:=
Table[ResourceFunction["MandelbrotSetRemap"][-.7, "MappingFunction" -> mf], {mf, {"Smooth", "ModTrailings", "Decomposition", "ThreePointsOrbitTrap", "LineOrbitTrap"}}]
Out[11]=

Use a custom mapping function:

In[12]:=
myMapping1 =
  Function[{c, center, corner, maxIterations}, Module[{ boil, boil2, list},
    boil = Exp[-Abs[c]];
    list = NestWhileList[
      (boil += Exp[-Abs[#]]; boil2 = VectorAngle[{2, 3}, ReIm[#]]; #^2 + c) &,
      0, Abs[#] <= 4 &, 1, maxIterations];
    Sin[boil]*boil2
    ]];
ResourceFunction["MandelbrotSetRemap"][-.7, MaxIterations -> 28, "MappingFunction" -> myMapping1]
Out[13]=

MaxIterations (1) 

Higher settings for MaxIterations give more details:

In[14]:=
Table[AbsoluteTiming[
  ResourceFunction["MandelbrotSetRemap"][-.7, ColorFunction -> "Vivid", MaxIterations -> mi]], {mi, {8, 16, 48, 128}}]
Out[14]=

Parallel (1) 

Setting the "Parallel" option to True helps speed up complicated mapping functions:

In[15]:=
ellipseOrbitTrap = Function[{c, center, corner, maxIterations}, Module[{ trap, trapDist, list},
    trap = Circle[{.8, 1}, {1.3, 2.7}];
    trapDist = 1000000;
    list = NestWhileList[
      (trapDist = Min[trapDist, RegionDistance[trap, ReIm[#]]]; #^2 + c) &,
      0, Abs[#] <= 6 &, 1, maxIterations];
    -Sqrt[trapDist]
    ]];
Table[AbsoluteTiming[
  ResourceFunction["MandelbrotSetRemap"][-0.7 + .46 I, 2.8, "Parallel" -> p, "MappingFunction" -> ellipseOrbitTrap]], {p, {False, True}}]
Out[16]=

Applications (1) 

Make a cool image:

In[17]:=
ResourceFunction["MandelbrotSetRemap"][-.805 - .176 I, 140, MaxIterations -> 64, "MappingFunction" -> "ThreePointsOrbitTrap", ColorFunction -> ColorData["SunsetColors"], ImageSize -> {600, 400}]
Out[17]=

Neat Examples (2) 

Combining images made with MandelbrotSetRemap can produce some spectacular results:

In[18]:=
img1 = ResourceFunction["MandelbrotSetRemap"][.08 + 1.009 I, 10, MaxIterations -> 32, "MappingFunction" -> "ModTrailings", ColorFunction -> "SunsetColors", ImageSize -> {600, 400}];
img2 = ResourceFunction["MandelbrotSetRemap"][.08 + 1.009 I, 10, "MappingFunction" -> "Decomposition", ColorFunction -> "FuchsiaTones", ImageSize -> {600, 400}];
ImageAdjust[ImageMultiply[{img1, img2}]]
Out[19]=

Here is the same part of the Mandelbrot set rendered with MandelbrotSetPlot and MandelbrotSetRemap using the same ColorFunction:

In[20]:=
Column[{
  MandelbrotSetPlot[{.3535 - .0666 I, .361 - .062 I}, MaxIterations -> 72, ImageSize -> {600, 400}, ColorFunction -> "SunsetColors"],
  ResourceFunction["MandelbrotSetRemap"][.357 - .0644 I, 550, MaxIterations -> 72, ImageSize -> {600, 400}, ColorFunction -> "SunsetColors"],
  ResourceFunction["MandelbrotSetRemap"][.357 - .0644 I, 550, MaxIterations -> 72, ImageSize -> {600, 400}, "MappingFunction" -> "ThreePointsOrbitTrap", ColorFunction -> "SunsetColors"]
  }]
Out[20]=

Publisher

Mark Greenberg

Version History

  • 1.1.0 – 10 February 2023
  • 1.0.0 – 02 November 2021

License Information