Dissipating heat: pseudocode for a Game

Heat convection pseudocode:

  • the ‘Q’ heat quantity (an integer) is split into as many numbers as there are free directions
  • Q dissipates to round-robin direction
  • there are 8 possible free slots of advancing for our player ‘x’
  • scan # of free slots for ‘x’
  • swirl-preference is the initial direction (one of 8)
  • swirl-preference has also flag for counterclockwise or clockwise direction of swirl-next
  • the algorithm dissipates the Q until there’s no Q left (to zero)
  • try it out! You’ll see what happens. Only by trying.
  • add wind gusts: a gust just changes convection-locks
  • try what happens if you change the initial setting of “swirl-preference”

Convection simulation in a nutshell

In 1990s PC demos world, there used to be coupel of pretty cool effects: Plasma and Fire.

Photo by СергейКатышкин on Pexels.com

But you know what was the most jaw dropping thing for a geek?

To find out that the driving algorithm for both fire and plasma are super easy: it’s just summing and averaging numbers.

You need 2 buffers: original grid, and the result. For each pixel in result, average the neighboring 8 pixels. (Wikipedia: multiple buffering)

When you’ve done calculating the value of all result pixels, show that on screen.

For the next round, this new result buffer will be the original grid

Plasma and fire can both be done by just averaging pixel values around a square!

(There’s also a “cheap” version of the plasma effect, which is done by just cycling through a color palette, so apparent motion appears on display, see Wiki https://en.wikipedia.org/wiki/Plasma_effect )

Convection of heat is a little bit similar.

In real physics, convection is one the 3 main forms of heat movement. Heat can:

  • radiate as heat radiation, through matter: when you feel warm at campfire, it’s mostly radiation you feel on skin
  • be convected (‘drifting’ usually via air or liquid)
  • conducted directly between two objects who touch each other

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: