You can find an explanation on the logic behin Markov chains on this website.
This implementation uses an image to compute the probability of transition between each pair of colors contained in the image.
It then create a new image with this informations, by gradually adding colors according to the Markov chain.