Wednesday, November 13, 2013

Water Particle Simulation

      This is a pixel-particle based dynamic water simulation I made from scratch.  The background (the black areas) is entirely customizable, and there's even a rudimentary editor built into the application as it stands now.  There aren't any real physics involved; just a short set of rules governing each pixel.
Warning: Take it easy on the lightning.



[Drag mouse to draw. Press space for lightning strike]

      The program doesn't keep track of the individual water particles; instead, it scans a bitmap image containing all the water particles, and each time it finds a blue pixel, it edits the bitmap according to the colors of the pixels around the particle.  If there is free space beneath the particle, it drops down a level.  If not, it checks for free space on its left and right, and moves into that free space if possible.  If a particle sits still long enough, it becomes "inactive" (the color changes very slightly, and the program knows to ignore that color).
      This frees up the CPU when the water starts stacking, but it starts acting really weird when the user goes crazy with the lightning, hence the warning.


test

2 comments: