home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / software / testi / corsoasm / sorgenti_3d / fire.txt < prev    next >
Text File  |  1980-01-10  |  5KB  |  97 lines

  1.                   How to code youre own "Fire" Routines        
  2.  
  3.     Hopefully this information file will give you all the information you
  4.     need to code youre own fire routines, seen in many demo's and also to
  5.     actually take it all further and develop youre own effects..
  6.  
  7.     Ok, so lets get on....
  8.  
  9.     Setting up
  10.  
  11.  
  12.     first thing we need to do is set up two arrays, the size of the arrays
  13.     depends on the many things, screen mode, speed of computer etc, its not
  14.     really important, just that they should both be the same size... I'll
  15.     use 320x200 (64000 byte) arrays for this text, because that happens to
  16.     be the size needed for using a whole screen in vga mode 13h.
  17.  
  18.     The next thing we need to do is set a gradient palette, this can be
  19.     smoothly gradiated through ANY colours, but for the purpose of this
  20.     text lets assume the maximum value is a white/yellow and the bottom
  21.     value is black, and it grades through red in the middle.
  22.  
  23.     Ok, we have two arrays, lets call them startbuffer and screenbuffer, so
  24.     we know whats going on. Firstly, we need to setup an initial value for
  25.     the start buffer...  so what we need is a random function, that returns
  26.     a value between 0 and 199 (because our screen is 200 bytes wide) this
  27.     will give us the initial values for our random "hotspots" so we do this
  28.     as many times as we think is needed, and set all our bottom line values
  29.     of the start buffer to the maximum colour value. (so we have the last
  30.     300 bytes of the start buffer set randomly with our maximum colour,
  31.     usually if we use a full palette this would be 255 but it can be
  32.     anything that is within our palette range.)
  33.  
  34.     Ok, thats set the bottom line up.. so now we need to add the effect,
  35.     for this we need to copy the start buffer, modify it and save it to the
  36.     screenbuffer, we do this by averaging the pixels (this is in effect
  37.     what each byte in our array represents) surrounding our target....
  38.  
  39.     It helps to think of these operations in X,Y co-ordinates....
  40.  
  41.     Lets try a little diagram for a single pixel.....
  42.  
  43.     This is the startbuffer             This is our screenbuffer
  44.  
  45.     ÚÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄ¿               ÚÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄ¿
  46.     ³0,0³0,1³0,2³0,3³0,4³ etc...        ³   ³   ³   ³   ³   ³
  47.     ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄ´               ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄ´
  48.     ³1,0³1,1³1,2³1,3³1,4³ etc..         ³   ³X,Y³   ³   ³   ³
  49.     ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄ´               ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄ´
  50.     ³2,0³2,1³2,2³2,3³2,4³ etc..         ³   ³   ³   ³   ³   ³
  51.     ÀÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÙ               ÀÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÙ
  52.  
  53.     Here we're going to calulate the value for X,Y (notice I didnt start at
  54.     0,0 for calculating our new pixel values?? thats because we need to
  55.     average the 8 surrounding pixels to get out new value.. and the pixels
  56.     around the edges wouldn't have 8 pixels surrounding them), so what we
  57.     need to do to get the value for X,Y is to average the values for all
  58.     the surrounding pixels... that means adding 0,0 0,1 0,2 + 1,0 1,2 + 2,0
  59.     2,1 2,2 and then dividing the total by 8 (the number of pixels we've
  60.     takes our averages from), but there's two problems still facing us..
  61.  
  62.     1) The fire stays on the bottom line....
  63.     2) Its slow....
  64.     3) The fire colours dont fade...
  65.  
  66.     Ok, so first thing, we need to get the fire moving! :) this is really
  67.     VERY easy. All we need to do is to take our average values from the
  68.     pixel value BELOW the pixel we are calculating for, this in effect,
  69.     moves the lines of the new array up one pixel... so for example our old
  70.     X,Y value we were calculating for was 1,1 so now we just calculate for
  71.     2,1 and put the calculated value in the pixel at 1,1 instead.. easy..
  72.  
  73.     The second problem can be approached in a few ways.. first and easiest
  74.     is to actually calculate less pixels in our averaging.. so instead of
  75.     the 8 surrounding pixels we calculate for example, 2 pixels, the one
  76.     above and the one below our target pixel (and divide by 2 instead of 8)
  77.     this saves a lot of time, another approach is to use a screen mode,
  78.     where you can set 4 pixels at a time, or set up the screen so that you
  79.     can use smaller arrays (jare's original used something like 80X50 mode)
  80.     which in effect reduces to 1/4 the number of pixels needed to be
  81.     calculated.
  82.  
  83.     The third problem is just a matter of decrementing the calculated value
  84.     that we get after averaging by 1 (or whatever) and storing that value.
  85.  
  86.     Last but not least, we need to think about what else can be done...
  87.     well, you can try setting a different palette, you can also try setting
  88.     the pixel value we calculated from to another place, so say, instead of
  89.     calculating from one pixel below our target pixel, you use one pixel
  90.     below and 3 to the right of our target... FUN! :))
  91.  
  92.     Well, I hope I didnt confuse you all too much, if you need anything
  93.     clearing up about this, then email me at pc@espr.demon.co.uk ok?
  94.  
  95.     Written by  Phil Carlisle (aka Zoombapup // CodeX) 1994.
  96.  
  97. EOF