Spiral Coloring Formula

by Kerry Mitchell, 13 May 2000

Basic information

As a fractal is being computed, the iterate (typically, the z variable) can bounce around all over the complex plane.  This formula colors the pixel according to some condition related to how close z comes to a given spiral.

A spiral is typically defined as r = f(q), where r is the distance from the center of the spiral, and q is the polar angle (counterclockwise, from the +x or +real axis).  A simple linear spiral is given by r = q; the curve spirals out from the center forever.  A curve that spirals in forever would be r = 1/q; as r goes to 0, q takes on all values, causing the curve to spin around on its way to the center.

While this works well mathematically, it doesn't work out quite so well in Ultra Fractal.  The polar angle q is obtained using the atan2() function, which returns a value from only -p to p.  Larger values of q just wrap around; for any r value, the point for q = 3p is exactly the same point as for q = p.  Howevever, there is no problem with r, since the cabs() function can return any value from 0 to the limits of Ultra Fractal's arithmetic.  Consequently, for this formula, the defintion of the spiral was inverted; q = f(r).  For any value of r, the formula determines the requisite value of q for a point to be on the spiral.  Then, the standard rectangular-polar conversions are used to determine the x- and y-coordinates of this point:  x = r * cos(q), y = r * sin(q).  This point is compared with the current iterate (z value), and the pixel is colored according to the minimum difference between them.

Parameters

Several parameters are used to adjust the size, shape, location, and orientation of the spiral, as well as how the pixel is colored.  The basic formula for the spiral is:

q = factor * [f(r)] ^ power,

where f() is one of Ultra Fractal's built-in functions.

Hints

To set up a spiral first, use the "draw spiral" option of the "color by" parameter.  Otherwise, adust the spiral's parameters "live" while working on your fractal.  You can also use the "Spiral Sample 0" image as a testbed for spiral tweaking.

If you get a lot of noise or schmutz, it is probably because q is getting too large, and there are too many thin loops in the spiral.  Try increasing the "minimum r" value or decreasing the "maximum r" value.  The outward extent of the spiral will also be affected by any "bailout value" settings in the fractal's Formula tab.

Sample images

This is a one-layer image, showing the effect of a non-zero spiral center.

SpiralSample1 { ; © 2000 Kerry Mitchell
fractal:
  title="Spiral Sample 1" width=600 height=400 author="Kerry Mitchell"
  created="May 13, 2000" numlayers=1
layer:
  method=multipass caption="New Layer 1" opacity=100 visible=yes alpha=no
  mergemode=difference
mapping:
  center=0/0 magn=1 angle=0
formula:
  filename="Standard.ufm" entry="Julia" maxiter=1000 percheck=off
  p_seed=0.28/0 p_power=2/0 p_bailout=1000000
inside:
  filename="lkm.ucl" entry="basic" transfer=linear repeat=no
  p_colorby="iteration"
outside:
  filename="lkm.ucl" entry="spiral" density=0.5 transfer=linear repeat=no
  p_spiralfactor=8 p_rpower=1 p_spiralcenter=3/2 p_rot=0 p_rmin=0
  p_rmax=3.60555127546398929 p_colorby="min. distance" f_rfunc=ident
gradient:
  smooth=yes numnodes=3 index=0 color=16777215 index=99 color=114943
  index=399 color=0
}

In this image, 2 layers are used to make the left and right sides of the heart. The exp() function provides the "tail" of the heart, and the "maximum r" setting keeps the heart from getting too long.

SpiralSample2 { ; © 2000 Kerry Mitchell
fractal:
  title="Spiral Sample 2" width=480 height=640 author="Kerry Mitchell"
  created="May 13, 2000" numlayers=2
layer:
  method=multipass caption="right side" opacity=100 visible=yes alpha=no
  mergemode=lighten
mapping:
  center=-0.0270668454763447008/-0.696203289828322948
  magn=4.81904239370472634 angle=352.806536746325266
formula:
  filename="Standard.ufm" entry="Julia" maxiter=1000 percheck=off
  p_seed=-0.779702280199264804/0.150339758937530933 p_power=2/0
  p_bailout=1000000
inside:
  transfer=none repeat=yes
outside:
  filename="lkm.ucl" entry="spiral" density=6 transfer=linear repeat=no
  p_spiralfactor=3 p_rpower=-1 p_spiralcenter=0/0 p_rot=2 p_rmin=0 p_rmax=5
  p_colorby="min. distance" f_rfunc=exp
gradient:
  smooth=no numnodes=3 index=0 color=16777215 index=99 color=255 index=399
  color=0
layer:
  method=multipass caption="left side" opacity=100 visible=yes alpha=no
  mergemode=difference
mapping:
  center=-0.0270668454763447008/-0.696203289828322948
  magn=4.81904239370472634 angle=352.806536746325266
formula:
  filename="Standard.ufm" entry="Julia" maxiter=1000 percheck=off
  p_seed=-0.779702280199264804/0.150339758937530933 p_power=2/0
  p_bailout=1000000
inside:
  transfer=none repeat=yes
outside:
  filename="lkm.ucl" entry="spiral" density=6 transfer=linear repeat=no
  p_spiralfactor=-3 p_rpower=-1 p_spiralcenter=0/0 p_rot=2 p_rmin=0
  p_rmax=5 p_colorby="min. distance" f_rfunc=exp
gradient:
  smooth=no numnodes=3 index=0 color=16777215 index=99 color=255 index=399
  color=0
}

The final example uses both the "angle @ min" and "magnitude @ min" coloring choices.

SpiralSample3 { ; © 2000 Kerry Mitchell
fractal:
  title="Spiral Sample 3" width=600 height=400 author="Kerry Mitchell"
  created="May 13, 2000" numlayers=2
layer:
  caption="angle @ min" opacity=100 visible=yes alpha=no
  mergemode=difference
mapping:
  center=0/0 magn=1.2 angle=0
formula:
  filename="Standard.ufm" entry="FastJulia" maxiter=100 percheck=normal
  p_Seed=-0.78/0.2 p_Bailout=1000000
inside:
  transfer=none repeat=yes
outside:
  filename="lkm.ucl" entry="spiral" transfer=linear repeat=yes
  p_spiralfactor=1 p_rpower=1 p_spiralcenter=0/0 p_rot=0 p_rmin=0 p_rmax=6
  p_colorby="angle @ min" f_rfunc=ident
gradient:
  smooth=yes numnodes=8 index=0 color=0 index=50 color=8392768 index=100
  color=11812992 index=150 color=14520255 index=200 color=16777215
  index=250 color=14520255 index=300 color=11812992 index=350 color=8392768
layer:
  caption="mag @ min" opacity=100 visible=yes alpha=no mergemode=softlight
mapping:
  center=0/0 magn=1.2 angle=0
formula:
  filename="Standard.ufm" entry="FastJulia" maxiter=100 percheck=normal
  p_Seed=-0.78/0.2 p_Bailout=1000000
inside:
  transfer=none repeat=yes
outside:
  filename="lkm.ucl" entry="spiral" transfer=sqrt repeat=yes
  p_spiralfactor=1 p_rpower=1 p_spiralcenter=0/0 p_rot=0 p_rmin=0 p_rmax=6
  p_colorby="magnitude @ min" f_rfunc=ident
gradient:
  smooth=yes numnodes=8 index=0 color=16777215 index=50 color=14520255
  index=100 color=11812992 index=150 color=8392768 index=200 color=0
  index=250 color=8392768 index=300 color=11812992 index=350 color=14520255
}