Tutorial: Generalized de Jong Coloring
Text and Images © 2011
Kerry Mitchell
Introduction
This coloring is based on an
attractor developed by Peter de Jong. His attractor is based on iterating
sinusoidal functions:
xn+1 = sin(a × yn) - cos(b × xn),
yn+1 = sin(c × xn) - cos(d × yn).
My generalization expands the type of function and their inputs.
Background
De Jong simply used the previous x and y values (scaled by frequencies a, b, c, and d) as inputs. I've extended that notion to
also allow a general linear or quadratic function of x and y as the stuff inside the parentheses:
- linear: slopex × xn
+ slopey × yn +
constant, or
- quadratic: slopexx × xn
2 + slopexy × xn×
yn + slopeyy × yn
2 + slopex × xn
+ slopey × yn + constant.
For the stuff outside of the parentheses, de Jong used the standard (circular) sine and cosine functions. The bane of many a trigonometry student, these functions turn out to be horribly useful for a variety of reasons. Professionals often refer to these as the circular trigonometric functions, in reference to their relationship to the coordinates of points on a circle. For a circle of radius 1 whose center is at the origin (point (0, 0)), the x- and y-coordinates of a point are given by: x = cos(θ) and y = sin(θ), where θ is the angle from the +x axis (measured counter-clockwise positive). Unwrapping these relationships and plotting both functions against the angle θ, you can easily see that both are periodic (that is, they repeat infinitely) with a period of 2π radians, and they are both bounded between -1 and 1. These characteristics make them ideal for this algorithm.

Unit circle and circular cosine & sine functions
When I first learned of these functions and their relationships to the circle, it seemed to me that their graphs should be circular. That is, if you plotted a full period of either, you should get four quarter-circles. That clearly isn't the case (and for good reasons), but that thought does invite investigation into other (probably less useful) functions. I call the first variation available in this formula the "superellipse" version. That's because plotting it gives four quarter superellipses--ellipses whose power is not necessarily 2. The graph below shows the superellipse version of the sine function for powers of 0.5, 1, and 2. In the coloring, you can choose any value from 0 on up.

Superellipse sine functions
The circular sine and cosine functions give the x- and y-coordinates of points on a circle (respectively). With a bit of effort, one can generate formulas for the coordinates of points on other shapes. My second variation, "polygonal," does that for regular polygons. As the number of sides increases, a regular polygon increasingly approaches a circle. In a similar fashion, the polygonal sine and cosine functions become indistinguishable from their circular counterparts as the number of sides increases. Conversely, the greatest differences between the two functions occur when the number of sides is the least, 3. The graph below shows the polygonal sine function for 3, 5, and 8 sides. In the coloring, you can specify at least 3 sides.

Polygonal sine functions
Parameters
The parameters are in three groups: general parameters, those for the functions (x-cosine, x-sine, y-cosine, and y-sine), and drawing parameters.
General parameters
- mode: the type of inputs: de Jong (default), linear, or quadratic
- trig mode: the type of trigonometric functions: standard (circular, default),
superellipse, or polygonal
- power: for the superellipse trig mode, the superellipse power (any value can
be used, but positive values will probably work better)
- sides: for the polygonal trig mode, the number of sides (integer, at least 3)
- initial value: the initial x- and y-values. The real part of
the parameter is the initial x-value and the imaginary part is the
initial y-value.
x-cosine function
These parameters are repeated for the x-sine, y-cosine, and y-sine functions. Which specific parameters are shown depends on the modes chosen.
- frequency: for the de Jong mode, the a (or b, c, or
d) frequency value.
- amplitude: for the linear and quadratic modes, scales the output of the
function
- x^2 coefficient: for the quadratic mode, multiplies x2 in
the input; slopexx above
- x*y coefficient: for the quadratic mode, multiplies x ×
y in the input; slopexy above
- y^2 coefficient: for the quadratic mode, multiplies y2 in
the input; slopeyy above
- x slope: for the linear and quadratic modes, multiplies x in
the input; slopex above
- y slope: for the linear and quadratic modes, multiplies y in
the input; slopey above
- constant: for the linear and quadratic modes, added to the x
and y terms in the input
Drawing parameters
- sampling factor: determines how many points are used to draw the image.
Set to a positive number; larger numbers use more memory and time.
- transients: how many times to iterate before drawing, to let the transients
die out and just display the attractor
- frequency scaling: how the pixel hit counts are converted to colors.
Choose from linear, logarithmic, and hyperbolic tangent.
- density: like the Color Density at the top of the Outside tab, but before
the Outside Color Density is applied
- solid background?: check to use the Solid Color as the background color,
instead of color 0 from the palette
Hints
You are, of course, free to use this coloring however you’d like. However, these hints may help your explorations be more productive.
- This is one of those coloring formulas that does all the work. It was
designed to be used as an outside coloring with the “Pixel” formula in
lkm.ucl.
- It works by storing a count of how many times each pixel is visited while
the functions are iterated. Consequently, it can use a LOT of memory for big
images and it doesn't work well with rendering-to-disk.
- Start small and simple until you get the hang of things. Use the de Jong
mode and standard trig to start, with a sampling factor of 10 or less. Then
venture into the funky stuff and increase the sampling factor as you develop
some confidence.
- The hyperbolic tangent frequency scaling works best with the Repeat Gradient
box cleared. Leave it checked when using the linear and logarithmic scaling
modes.
- The Explore mode (crosshairs associated with each parameter's input) is a
great way to get a sense of how to set the function parameters, particularly
with the linear and quadratic modes.
- Not all function parameter settings will result in attractors. If you get
a blank screen, Undo and make a smaller change.
Sample Images
Click the image to see its parameters.

Sample 1. This image uses the de Jong mode and the standard trig functions.

Sample 2. This image uses the linear mode and the superellipse trig functions.

Sample 3. This image uses the quadratic mode and the polygonal trig functions.
Enjoy!
Back
to Tutorials page
Up
to my home page