Attractors and Repellers

August 10, 2024

The Attractor and Repeller algorithms described here are similar to Vector Fields, but instead of tracing the trajectory of single points through the field as a set of lines, many points traverse through the field individual pixels are shaded whenever a point lands in the pixel.

Strange Attractors

Attractors start with a transformation:

(x, y) ↦ f(x, y)

This just says that any (x, y) coordinate, put through the equation, results in a new (x, y) coordinate. The function moves the point. However, to make it an "attractor", the function must always pull the point in toward a central region of the plane. As a counter-example, the function f(x, y) = (x + 1, y + 1) is not an attractor, because x and y values will eventually blow up to infinity. But a function f(x, y) = (x/2, y/2) is an attractor that attracts all points to the origin. But it makes a pretty boring plot.

A "strange attractor" is an attractor system that exhibits chaotic behavior. The system f(x, y) = sin(ay) + c cos(ax), sin(bx) + d cos(by) is such a system, where a, b, c, and d are constants. Very slight changes in these constants lead to very different paths, as seen in this "Attractor Study" of 12 attractors with the same equation but different coefficients.

Strange Attractor Study

To draw a strange attractor, pick any starting (x, y) point at random. Calculate its position through the attractor equation many (millions or billions) of times, and shade in each pixel the point falls within. You can make an interesting color scheme by calculating the "speed" at which the point travels in any given iteration and use the speed to map to a color value.

Attractor Pseudocode

x0, y0 := random coordinate in window
FOR N iterations:
    x1, y1 = f(x0, y0)
    IF iteration > burn_in:
        speed := (x1-x0)^2 + (y1-y0)^2
        density[x1, y1] := density[x1, y1] + 1
        color[x1, y1] := mean(color[x1, y1], palette[speed])
    x0, y0 := x1, y1

final_image := composite(color, alpha=density^gamma)

Repellers

It can be difficult to find equations that act as attractors - many times a guess becomes a "repeller" where the coordinates do not stay constrained. These can prove very interesting as well, but because the coordinate eventually blows up to infinity, one can't iterate the same point forever.

Instead, pick a random starting point, iterate it a few (50-100) times, then start with a new point. In the below pseudocode, colors are set based on the sample window location from which the initial point was drawn.

Repeller Pseudocode

FOR window in sample windows:
    FOR N samples:
        x0, y0 := random coordinate in sample window
        FOR M iterations:
            x1, y1 = f(x0, y0)
            IF iteration > burn_in:
                speed := (x1-x0)^2 + (y1-y0)^2
                density[x, y] := density[x, y] + 1
                color[x, y] := mean(color[x, y], palette[window, speed])
            x0, y0 := x1, y1
final_image := composite(color, alpha=density^gamma)

Here is an example:

Repeller

Back