Pixel Rain

A small c++ program to create images like the one below. The core algorithm was written in about 2 hours.

The source code is on Github: https://github.com/shamanDevel/PixelRain

(Actually, this is a collage of four output images, representing the four elements fire, water, air, earth)

This is how the algorithm works:

  1. Define a random distribution that generates colors. Different distributions produced the different results above.
  2. Define a similarity function that computes how similar two colors are. Here it is important which color space is used. I usually use the HCL color space because it results in color gradients that look more natural to a human than a simple RGB-distance.
  3. Pick a seed pixel and fill it with a random color according to the distribution.
  4. Until all pixels are filled:
    1. Sample a new color from the distribution
    2. From all already filled pixels that have neighbors without a color assigned, search the one with the lowest distance according to the similarity function
    3. Place the new pixel at one of the neighbors of the pixel found in step 4.2.
    4. Repeat
  5. Done