• LinkedIn

Julia Set Visualisation

About

The Julia set is a chaotic set of fractals defined by iterating on a function fc(z)f_c(z), where:

fc(z)=z2+cf_c(z) = z^2 + c

zz and cc are complex parameters.

The colour of a given pixel is defined by how many recursive iterations of fc(z)f_c(z) it takes, until the magnitude of the returned value is greater than some RR.

Pseudo-code

def julia(z):
    i = 0

    while len(z) < R && i < LIMIT:
        z = (z * z) + c
        i = i + 1

    return i

for (x, y) in pixels:
    zx = map(x, 0, width, -R, R)
    zy = map(y, 0, height, -R, R)

    z = complex(zx, zy)

    value = julia(z)

    pixels[x, y] = grey(value)

Parameters For The Above Sketch

By default the demonstration above uses a cc value where:

c=0.7885eiac = 0.7885e^{ia}

aa is animated over the range a[0,2pi]a \in [0, 2pi] with a period of 4pi4pi seconds.

In-case you haven’t worked with complex numbers for a while, the above definition of cc is in the form:

c=Aeiθc = Ae^{i \theta}

This, in practice, is a representation of a polar coordinate, where AA is magnitude and θ\theta is the angle (radians).

To represent this in code, you can do the following (pseudo-code):

cx = A * cos(theta)
cy = A * sin(theta)

c = complex(cx, cy)