Integer Apollonian Packings

The slider below allows you to choose from a collection of pre-generated Apollonian packings. You can also click on the figure to zoom in by the factor two. The code often craps out after five or six clicks, however.

The initial packings are chosen so that all four initial circles are integers. This includes the exterior circle, whose oriented curvature is negative. As it turns out, this implies that all subsequent circles in the packing have integer curvatures yielding a configuration sometimes called a Bowl of Integers.

We can see why this works using the Descartes Circle Theorem: Given three, mutually tangent circles with curvatures $\kappa_1$, $\kappa_2$, and $\kappa_3$, there are two more circles mutually tangent to the original three. Furthermore, if the curvatures of such a circle is $\kappa_4$, then these curvatures all satisfy $$(\kappa_1+\kappa_2+\kappa_3+\kappa_4)^2 = 2(\kappa_1^2+\kappa_2^2+\kappa_3^2+\kappa_4^2).$$ For example, in the first labelled packing shown above, there are three gray circles labelled 2, 2, and 3. There is a circle with curvature 15 that is tangent to all three and $$(2+2+3+15)^2 = 2(2^2+2^2+3^2+15^2).$$ There's also an exterior circle with curvature 1 that is tangent to all three. If we apply the convention that an exterior circle has negative curvature, then the formula works again, as you can check.

Note that Descarte's theorem relates the curvatures using a quadratic equation. If we solve for $\kappa_4$ in terms of the others, we get $$\kappa_4 = \kappa_1 + \kappa_2 + \kappa_3 \pm \sqrt{\kappa_1 \kappa_2 + \kappa_1 \kappa_3 + \kappa_2 \kappa_3},$$ corresponding to the two solutions that Descartes' theorem refers to. If we call these two solutions $\kappa_4$ and $\kappa_4'$ and add them together, then the square root terms cancel so that we are left with $$\kappa_4 + \kappa_4' = 2(\kappa_1 + \kappa_2 + \kappa_3).$$ In particular, $\kappa_4'$ must be an integer when the others are.