I found several animations of the Central Limit Theorem on the web. Most of them are implementations of Galton box that show how the binomial distribution get closer and closer to the normal distribution.

While sketching out the flow chart for a different kind of program, I realized that the same concept can be illustrated in another way, focusing on the analytical aspect of the approximation process (charting the exact probability distribution) instead of the empirical one (sampling from the exact probability distribution) as in the Galton box.

To describe it, consider the classic example of a fair coin to flip repeatedly. In all the tosses the coin has probability 50% of landing heads and probability 50% of landing tails. Now let reason about the number of heads after each toss.

Suppose to have already flipped the coin a certain number of times: with the next flip the number of heads can increase by one or remain the same with equal probability.

So, it happens that the probability to have exactly x heads after n tosses can be calculated as the sum of the probability to have the previous number of heads (x over n-1 tosses) multiplied by 50% and the probability to have one heads less (x-1 over n-1 tosses) multiplied by 50% (yes, it’s a simple Markov Chain, if you know the subject).

My applet implements this computation iteratively, visualizing the transition between the probability distributions at two successive steps like an osmotic exchange between a couple of bar charts, as described by the following pseudo-code:

put 100% on a blue bar

repeat {

blue bars transfer 50% of their total to same column red bars

red bars shift one place to the right

red bars give back 100% of their total to same column blue bars

}

The live applet is available here. It is also possible to change the probability of success (the probability of heads in the coin example). The x-axis is not explicitely labelled for simplicity; each new iteration (the toss in the coin example) is generically represented by a traslation to the right.

Here are some screenshots, showing that the convergence to the normal distribution is very fast.