Julia set


The Julia set and its complex beauty.

A complex system in the Julia set can be defined as simply as:

`z = z^2 + c`

where both `z` and `c` are complex numbers.

# Algorithm

The value of `z` is updated iteratively for a predefined number of times (e.g.: 100) or while the absolute value of `z` is lower than a given constant (e.g. `\abs(z) < 2`).

The initial value of `z` is set as:

z = Complex(
    (2*x - w) / (w * zoom) + moveX,
    (2*y - h) / (h * zoom) + moveY
)

where `x` and `y` are the coordinate positions on a 2D plane, `w` and `h` are the width and height of the plane. 

The values for "zoom", "moveX" and "moveY" are optional. They control the level of zoom into the fractal and the offsets for shifting the image on the X and Y axis.

The iteration loop can be defined as:

i = 100   # maximum number of iterations
while (abs(z) < 2 && --i > 0) {
z = z*z + c }

When the absolute value of `z` reaches the value of 2, the loop breaks earlier and the value of `i` may not be 0. We can take advantage of this fact and map the value of `i` to represent a certain RGB value based on how close it is to its initial value.

A good solution would be to create an HSV tuple using the value of `i`, and then map it to RGB, using a corresponding algorithm:
rgb = hsv2rgb(i / maxIter * 360, 1, i > 0 ? 1 : 0)

# Images

A random collection of Julia sets can be found at:

# Implementations

Implementing the Julia set in the Julia language seemed like a good idea:

Perl implementations (using Inline::C for speed):

Even more implementations of the Julia set, in different languages, can be found at: https://rosettacode.org/wiki/Julia_set

# Bonus

There is also a great documentary about fractals, called The colours of Infinity, presented by Arthur C. Clarke in 1995.

Comments