Blog L342n
Home
Back
Information
Programs - Mandelbrot
This was a quick project because Lân was bored, and so decided to create
a Mandelbrot renderer in ASM. Firstly, Lân read the
Wikipedia page for the Mandelbrot set to start to understand how
the pattern happens, and how to write code do show the pattern. This
wasnt very helpful, so Lân watched the video by Numberphile
about the subject. This was much more helpful than Wikipedia, and now
Lân understood the pattern and how it was created. Next, Lân researched
the way that programmers test if a number is finite or not. After a
short time, Lân discovered that a common technique is to test that
fc(z) = z^2 + c for something like one thousand times, and if z didnt
go above a certain amount AND goes to the iteration limit, the number
is finite.
Then, Lân used the code on Wikipedia on the page
Plotting algorithms for the Mandelbrot set to see how this was done
without the use of complex number libraries. Lân used the code from the
segment called 'Optimized escape time algorithms', and rewrote the code
in python, so she understood the cod before writing in ASM. Here are
some pictures of the python code:
Now, it was time to write the code in ASM.
Firstly, Lân needed to create a system of showing points on the terminal
screen. To do this, she used 'ANSI escape sequences' to change the
colour of the foreground and background of the character '▄'. With this,
Lân could change the foreground to change the colour of the bottom pixel,
and the background to change the colour of the higher pixel. With this,
you can place pixels like this over the entire screen and then place
pixels of any ANSI colour anywhere on the screen. After this system
worked, Lân continued to write code to render the Mandelbrot set. This
was hard to do with the FPU, because of the fact that the FPU is similar
to the stack. But Lân finished the code in a short time, and after some
debugging, the code showed the Mandelbrot set.
As you can see, the set is shown correctly, but its in a weird place
and the colours are weird too. However this was very easy to fix, because
it was a very obvious bug with colours, and the position of the set was
easy to fix also because you only need to change the position of the
top left, and the zoom.After changing these problems, it looked like
this:
Now everything was correct. Lân needed to write code to move the image
and to zoom into the Mandelbrot set. Fortunately, this is easy because
the zoom level was defined by a number near the start of the code, and
every bit of maths uses this number. So, to change the zoom, you only
needed to change that number. After finishing this, the project was
finished. If you want, you can
download the project from GitHub to try the code for yourself.