Friday, April 26, 2024 | Toby Opferman
 

Snow Algorithm

Toby Opferman
http://www.opferman.net
programming@opferman.net





                             SNOW

   This is the offical release of my snow algorithm.  This algorithm is
totally unstructured and if you were making a real snow for something
(And wanting it to be fast!) you should use structures and keep track
of each snow flake to DOWN the processing.

   As this algorithm was based on the FIRE algorithm, it may be helpful to
be familar with the fire algortihm.  What you do is randomly plant XX snow
flakes at the top of the buffer (7 is a good number). SnowFlake Color
should be white of course (R = 63, G = 63, B = 63) or Default color
pallete number 15.

  Once you randomly plot those snow flakes, start from the bottom of the
(buffer - 1) and go to every pixel (Up to the first location in the buffer).
If the pixel is a snow flake do the following:


      Randomly choose Left Or Right.
        Plot the Snow flake Left or Right Down 1 row.
          Erase the current location.
              Move to the next location.

  This will just make a snowfall.  If you want to see snow lay, then
you use this algorithm:

     Randomly Choose Left Or Right.
       Check Location.
         If Location has a snowflake in it(Or any Color that it cannot
                                           occupy the same space such
                                           as color of a hard object)
         Then check Opposite left/right location.
            If the same as above, then check striaght down.
              If the same as above, then the pixel goes nowhere, it stays
              there.  Move onto next pixel.

  If Location you check is not occupied, then plot snowflake there
and erase current snowflake.  Then move onto next location.

 
About Toby Opferman

Professional software engineer with over 15 years...

Learn more »
Codeproject Articles

Programming related articles...

Articles »
Resume

Resume »
Contact

Email: codeproject(at)opferman(dot)com