The Julia set is a fractal defined by the following equation:
where
The Julia set is usually visualized by coloring the complex plane. Each pixel in
the image corresponds to a complex number
The Julia set is a fractal because it is self-similar. If you zoom in on any part of the image, you will see the same pattern repeating itself.
The calcJulia
function calculates the number of iterations it takes for the
sequence
calcJulia :: Complex Double -> Int
calcJulia z0 = iterateJulia z0 0
where
iterateJulia z n
| n == maxIterations || magnitude z > 2.0 = n
| otherwise = iterateJulia (z * z + c) (n + 1)
The steps of the calculation are as follows:
- Start with a complex number
$z_0$ . - Calculate the next value of the sequence
$z_n$ using the$f$ function. - Repeat step 2 until the sequence diverges to infinity or the maximum number of iterations is reached.
The iterateJulia
function uses the f function to calculate the next value of the
sequence
The
The
- Install Haskell.
- Install the dependencies:
cabal install --only-dependencies
. - Compile the program:
cabal build
. - Run the program:
cabal run
. - Open the
julia_set.png
file to see the result.