Tamás Deák

Tamás Deák

Web Developer

Fire effect in terminal


Fire effect in terminal

  • Platform: Linux
  • Language: Perl

Long time ago

... in a galaxy far, far away... I had a colleague who didn't believe the possibilities of the simple character based linux terminal. I interpreted this as a challenge, because I grew up in the '90s, in the world of Commodore, MS Dos and Norton Commander.

So I know everything is possible with simple characters. I mean: everything ...

The magic

Every computer generated visual effect is a lie. This small script doesn't simulate flames or do hard calculations about the heat and wind. It's just an optical illusion for your eyes. And finally your brain starts to compare the image with similar images, what you have already seen.

And to be honest, it absolutely looks like a campfire ;) Especially when it's moving.

The magic behind it is:

  • The bottom line, which is filled with random characters
  • In every frame we must calculate the average of every char and its neighbours, then move them up by one line
  • We put some random "flashing dots" into the scene to have more randomly waving flames
  • Rinse, repeat :)

Of course I wasn't able to stop here, so I created a more colorful second edition... :D

If you are interested in coding some char effect, chek out the source at my Github repo