ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ Demoscene: Fire effect ³ DuSTFaeRie/DDT ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ Fire, an effect for beginning coders ? Yep, fire is very cool. And it's easy. But in this article i'll also present some stuff which could be interesting for people who think they already coded the best fire available. There's a lot to do with such an effect. So what is a fire ? A normal fire is something which looks like flames going up from the bottom of the screen with nice red color shades (and maybe yellow and blue ;). In fact it is a fire simulation. The fx is so overused that putting a "normal fire" in a demo will get u called a lamer. But the fx can be distorted, optimized (i saw one in less than 100 bytes), or also used in an ironic or new way (this sounds ugly, the whole article seems to be ugly :(. For beginners : a normal fire I'll first give u an explanation of how the fire is simulated. You noticed the flames start in some points we're gonna call heatpoints. The flame then gets smaller and smaller as it goes up, but also mixes up with other flames. The heatpoints move along the bottom line of the screen, so the flames move nicely along the screen too. I think u now have an idea of how the fx works, don't u ? Okay, i give u some pseudo code. The cooling is done in a way which can be used for smoothing or blurring: point(x, y) = (point(x-1, y-1) + point(x, y-1) + point(x+1, y-1) + point(x-1, y) + point(x+1, y) + point(x-1, y+1) + point(x, y+1) + point(x+1, y+1)) / 8 -1 The -1 is there because we want the flames to cool down quite quickly, but u can of course change this value. I prefer using 8 points around the pixel because it looks a lot smoother, but u can modify the above formula, maybe like this : point(x, y) = ((point(x-1, y) * 2 + point(x, y+1) * 4) / 6 Just try it out. The flames have to go up, so u move the whole scene up : point(x, y-1) = (point(x-1, y-1) + point(x, y-1) + point(x+1, y-1) + point(x-1, y) + point(x+1, y) + point(x-1, y+1) + point(x, y+1) + point(x+1, y+1)) / 8 -1 It is y-1 because the screen coordinates are quite strange ;). There too, u can vary if u want to simulate some wind : point(x+1, y-1) = (point(x-1, y-1) + point(x, y-1) + point(x+1, y-1) + point(x-1, y) + point(x+1, y) + point(x-1, y+1) + point(x, y+1) + point(x+1, y+1)) / 8 - 1 Just try it out again ;). The last thing u have to do is to put some heatpoints in the bottom line (or bottom lines, which looks much better). There are various ways to do this : u can either place heatpoints of value 255 (we're in mode 13h) at random offsets in the botoom line (this is the method i use, cause it requires less random function calls) or u can put heatpoints of random color value along the bottom line. By the way, the bottom lines aren't quite smoothed, and look quite rasterized. What i do is not to show them ;). For the very beginning coders, who don't know what mode 13h is : mode 13h is the easiest vga mode, and the only one i'm good in (i'm lame and lazy). In mode 13h u have a resolution of 320*200*256 colors. To get into mode 13h, use the function 0 (set mode) with al=13h of int 10h. The video mem is organized in a linear way at segment a000h (in real mode of course) : if u want to plot a pixel at x, y of color c, just put byte c at a000:(x+320*y). Did u understand that ? I made some examples in the version of this article, but unfortunately i wrote it on mac, and i'm too lazy to write the whole stuff again, so fuck u if u haven't understood. Just search a bit on the web, u'll find lots of stuff ;). A step further : new ways of using fire I found a marvellous page on the web, the homepage of hugo elias (don't remember the url, i'm on an atari 1040 ST, but this time the floppies can be read on a pc, so again search around a bit). As u may have noticed, i ripped quite a bit of ideas from him (i'm really lame ;). There i found the idea of cooling the flames in a uneven way (i don't remember well the way he did it, but mine must be the same). The idea behind uneven cooling is that the flames aren't cooled down (remember the -1) the same way in dif- ferent parts of the screen. In fact, the cooling factor (the -1) varies : point(x, y-1) = (point(x-1, y-1) + point(x, y-1) + point(x+1, y-1) + point(x-1, y) + point(x+1, y) + point(x-1, y+1) + point(x, y+1) + point(x+1, y+1)) / 8 - cooling_factor The cooling factor is going to vary all over the screen, so we'll define a cooling map which will give the cooling factor in each point. U can either put up a cooling map in the beginning of the code or use a predefined cooling map. To set up a cooling map (which allows to include some cool gfx that will appear on the screen), u can draw something with a paint program and blur it some times. The higher the color value, the more the flame will cool in that point. This is one new way of making fire. But fire can also be simulated in other ways (with particles it is so easy and it looks so cool ! =), or used in many different ways (for example by simply adding some particles to a normal fire). I also used to make firy particles (i love particles, did i tell u ?) which looked like comets, but fire can also be used to smooth the image, and achieve some feedback effect by blurring the image recursively. Another way of achieving some funny effects is distributing the heatpoints in some fancy way : u can draw characters with them. U can also apply some deformations to the flames, but i'll talk about deformations in a further issue of ddt (i have to finish all my articles within 1 week, so i don't have time ;). DustFaerie / DDT