In 1918, French scientist Gaston Julia investigated the behavior of complex functions during iteration, but it was only with the advent of computers that the world saw the beauty hidden in his equations.
The Julia set is the visual embodiment of the boundary between order and chaos. A simple equation
In this example, we will look at how to use complex numbers, iterations, and color schemes to create an animation of a Julia set shape that changes its state depending on the changing angle of the constant.
We will attach the necessary libraries.
neededLibs = ["LinearAlgebra", "Printf", "ProgressMeter", "Images", "FileIO", "ColorSchemes", "VideoIO"]
for lib in neededLibs
try
eval(Meta.parse("using $lib"))
catch ex
Pkg.add(lib)
eval(Meta.parse("using $lib"))
end
end
Define the animation parameters. Required parameters:
- Animation duration;
- frame width;
- Frame height;
- number of frames per second;
- the initial angle of the constant;
- the final angle of the constant;
- radius of the shape;
- number of iterations;
- dimensions of the complex plane (transformed proportionally to the width and height of the frame).
сек = 60 # animation duration
ш = 1920 # frame width
в = 1080 # frame height
квс = 60 # frames per second
α = 2π*0.14 # the initial angle of the constant
β = 2π*0.86 # the final angle of the constant
r = 0.78 # radius
итер = 20 # number of iterations
л = 1.5 # linear width of the complex plane
Based on the initial ones, we will calculate the number of frames in the animation and create arrays of numbers for the complex plane. Where
кадры = сек * квс # total frames
# Creating a complex plane
X = [x for y in range(-л, л, length=в), x in range(-л, л, length=ш)];
Y = [y for y in range(-л, л, length=в), x in range(-л, л, length=ш)];
Let's define a function that calculates each complex number and performs iterations of calculating the function and substituting the resulting values into the function argument.
The function is defined as follows:
where:
function Жюлиа(X, Y, a, r, итер)
Z = X .+ im .* Y
C = r .* cos(a) .+ im .* r .* sin(a)
for k in 1:итер
Z = Z .^ 2 .+ C
end
return exp.(-abs.(Z)), C
end
Let's define a function that creates subtitles in the srt format to display the current Z value corresponding to the current state of the shape.
function кадр_время(к, квс)
T = zeros(UInt32, 4)
квч = 3600 * квс # frames per hour
квм = 60 * квс # frames per minute
бч = mod(к, квч) # shots without a watch
бм = mod(бч, квм) # frames without minutes and hours
T[1] = (к - бч) ÷ квч # watch
T[2] = (бч - бм) ÷ квм # minutes
T[4] = mod(бм, квс) # frames without seconds, minutes, or hours
T[3] = (бм - T[4]) ÷ квс # seconds
мс = round(Int, 999 * T[4] / (квс - 1))
субт = string(lpad(T[1], 2, '0'), ':', lpad(T[2], 2, '0'), ':', lpad(T[3], 2, '0'), ',', lpad(мс, 3, '0'))
return субт
end
Let's create a progress bar and start the animation creation process.
кадр = 0
t = 0.0
время = 0.0
видео = []
п = Progress(кадры, 1, "Создание анимации:")
субтитры = open("Множество Жюлиа.srt", "w")
ProgressMeter.ijulia_behavior(:clear)
for a in range(α + (β - α)/кадры, stop = β, step = (β - α)/кадры)
старт = time()
время += t
кадр += 1
скорость = кадр / max(время, 0.001)
осталось = (кадры - кадр) / скорость
ProgressMeter.next!(п; showvalues = [(:Время, @sprintf "%d секунд" round(Int, время)), (:Создано, @sprintf "%d кадров" кадр), (:Скорость, @sprintf "%.4f кадров в секунду" скорость), (:Осталось, @sprintf "%d секунд" round(Int, осталось))])
J, C = Жюлиа(X, Y, a, r, итер)
J[isnan.(J)] .= 0.0
push!(видео, convert.(RGB{N0f8}, get.(Ref(ColorSchemes.magma), clamp.(J, 0.0, 1.0))))
write(субтитры, string(string(кадр), "\n", кадр_время(кадр-1, квс), " --> ", кадр_время(кадр, квс), "\n", "f(z) = z² ", real(C) >= 0 ? "+ " : "- ", @sprintf("%.5f", abs(real(C))), " ", imag(C) >= 0 ? "+ " : "- ", @sprintf("%.5fi", abs(imag(C))), "\n\n"))
t = time() - старт
end
if !isempty(видео)
@info "Сохраняем видео..."
параметры = (crf=23, preset="medium")
VideoIO.save("Множество Жюлиа.mp4", видео, framerate=квс, encoder_options=параметры)
end
close(субтитры)
println("\nАнимация создана успешно!")
println(" - Всего кадров: $кадры")
println(" - Время создания: $(round(Int, время)) секунд")
println(" - Средняя скорость создания: $(round(кадры/время, digits=4)) кадров в секунду")
After completing the animation creation process, a video file with a figure will appear in the current folder.:

If in the function that evaluates the iteration instead of the expression turbo,

If we define the expression as rainbow

The created animation of the Julia set demonstrates not only the aesthetic, but also the applied value of fractal geometry. Algorithms based on the principles of iterative transformations of the complex plane are used in various scientific and engineering fields.
- Telecommunications.
Fractal antennas with a self-similar structure provide multi-band performance with minimal dimensions, which is critical for mobile devices and satellite communications. - Computer modeling.
Fractal generation algorithms are used to synthesize natural landscapes in computer graphics, as well as to model porous materials and biological structures. - Medical diagnostics.
Fractal analysis is used in medical image processing to quantify the complexity of blood vessels, neural networks, and lung tissue. - Cryptography and data protection.
Deterministic chaos of fractal systems is used in pseudorandom number generators and steganographic methods.
Thus, from an abstract mathematical object to a practical tool, fractals represent an important bridge between theoretical mathematics and applied technologies. The presented animation technique allows not only to visualize these concepts, but also to experiment with parameters to explore the boundaries between order and chaos in dynamic systems.