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:
= ( (2*x - ) / ( * ) + , (2* - ) / ( * ) + )
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:
= 100 # maximum number of iterations while (abs() < 2 && -- > 0) {
= * + }
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:
= ( / * 360, 1, > 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:
- Orange theme: julia_sets.jl
Perl implementations (using Inline::C for speed):
- Blue theme: julia_set_complex.pl
- Red theme: julia_set_random.pl
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
Post a Comment