First love never dies
Plasma
Fire

Algorithms I fell in love with

An interactive journey through my algorithmic memories

First love never dies

Once upon a time…

As a teen in the late ’80s and early ’90s, I was deeply fascinated by computers. My buddies Toni and Dano were lucky owners of the iconic C64. You hooked it up to a television and suddenly you were in control. You could paint and animate anything on the screen, as opposed to just passively enduring the TV stream.
It was magical.

Unfortunately I couldn’t convince my parents to get me a C64 because “Video games are a waste of time!”. To be fair, they eventually gave me a 486DX-33, with 4Mb of RAM and a powerful Cirrus Logic graphics card! This happened after I took a computer class in my school at the end of which we showcased a project to our parents: a robotic toycar that could follow (mostly…) a white line on the floor, hooked up to a PC via a parallel cable and programmed in QBASIC. My buddies did most of the work, having developed their coding superpowers on the C64. Nevertheless that did the trick and my parents were finally convinced that there was more to computers than video games and wasting time (Back in the day, when ‘home computers’ first made their way into our households, they were predominantly used for gaming. It took a little while for them to be recognized as valuable work tools).

While I was eagerly waiting for my PC, Toni lent me his C64 (thank you, Toni!) so I practiced a bit of Basic reading through the rich manual that came with it. Dano also moved on from his C64 and got his 486DX-33 earlier than me (dammit!), so I spent some afternoons at his place amazed by what this powerhouse could do. But it was when he showed me a particular image on his 486 that I felt like struck by lightning. It was the first 3D graphics rendered image that I had ever seen: a shiny sphere and a checkerboard plane reflecting each other in glorious 256 colors! He explained he used Povray to generate it, a program that could render photorealistic images, starting from a text written in a special scene description language, with an algorithm called raytracing.
The first algorithm I fell in love with.

3D rendered image of a red shiny, reflective ball, floating over a green/blue checkboard plane.
The image that Dano showed me was very similar to this one
(although this one is rendered with 3D Studio for DOS).

I was flabbergasted and wanted to use my computer to generate such images. A couple of months later, with my 486 finally up and running, Dano brought me a copy of 3D Studio for DOS. It was a more sophisticated program to create 3D renderings with a powerful user interface, no need to learn a weird “scene description language” (although 3D Studio utilized a different algorithm to render 3D photorealistic images).

I ran to the bookstore and bought a big 3D Studio book. My long journey through the amazing world of computers and algorithms had begun.


Plasma

But plasma is, by far, the most fun!

The Plasma effect was one of the first demos I remember running on my 486 ‘DOS box’. The speed and fluidity were astonishing, not at all a given on such hardware. The secret behind this performance was the use of a technique known as color palette cycling, achieved through direct manipulation of the VGA registers. This was a sort of ‘primitive GPU acceleration’ trick, exploiting the hardware’s capabilities for faster graphical performance.
The following is the Plasma effect implemented in JavaScript and p5.js. However, there’s no palette cycling used in this case; instead, all the pixels are updated every frame.


Fire

Burn baby burn!

The fire effect was another DOS demo I remember vividly. In this case, too, the speed was extraordinary. How could my 33 MHz machine possibly run such a complex simulation! Well, it turns out the algorithm to simulate fire was relatively simple: each pixel’s value is calculated based on the values of its neighboring pixels below it. The idea is to decrease (or “cool”) the intensity as you move upwards, simulating the effect of a flame flickering and dying out as it rises. It can be thought of as a kind of convolution due to its local neighborhood computations, although not in the strict mathematical sense.