I will like to animate a list of parametric spirals over a list of packed spheres. The effect I am after is illustrated in this gif by Étienne Jacob :



1 Answer 1


By looking at the gif above, we will divide our implementation into two parts:

  • Sphere Packing, where we try to find a list of locations and radii for the sphere such that they are non intersecting and look packed.
  • Generating Spirals, this part is relatively easy, all we have to do is find a parametric equation for the spiral over the spheres and replicate it over the list of locations and radii we have got.

Sphere Packing

There are multiple algorithms we can use to generate point locations and radii. Some are iterative, others are generative (but expensive), and others are "approximative." We don't really care about execution time because the output is readily cached. Perfect packing is not needed either since smaller circles will usually go unnoticed.

Our algorithms will be as follows:

  • Initialize an empty vector and float lists for locations and radii.
  • Define a function that generates a random location, preferably uniform in density.
  • For some arbitrary number:
    • Generate a random point $p$.
    • Loop over the point and radii lists and compute the smallest signed distance between the point $p$ and the nearest sphere surface point.
    • If the signed distance is positive (meaning the point is outside all of the existing spheres), append that point $p$ and radii (which is defined as any scalar that is smaller that or equal the positive distance).

The smallest signed distance between the point $p$ and the nearest surface point is equal to the distance between $p$ and the nearest sphere minus its radius.

Signed Distance

If the distance is smaller than the radius, then the signed distance will be negative, telling us that the point $p$ is inside of the spheres, and that's why we don't append it. Moreover, the radius of the sphere at point $p$ has to be smaller than the positive distance so as not to intersect the other circle.

To find the smallest signed distance, we loop over the point and radii lists and reassign an initially infinity float parameter if the current signed distance is smaller than the value of the parameter. This is is the equivalent to a KD Tree search except we are subtracting some value defined as the radius.

Smallest Signed Distance

Next, we create a loop that has an arbitrary number of iterations controlling the maximum number of spheres. However, it does not strictly define the number of spheres itself! The loop has two main parameters: (1) a vector list that will include the spheres locations and (2) a float list that will contain the radii locations. Both inputs are undefined, meaning that they are initially empty lists that we will append to later. In this loop, we generate a random point (we will talk about that algorithm later on), compute the smallest signed distance using the loop we created before and append the sphere location if it is positive. The append condition is implemented as a form of reassign condition for both lists. It is important that we copy the lists at each iteration, ensuring the append doesn't overwrite the original list rendering our reassign condition useless. I chose to define the radius as the positive distance bounded by some arbitrary constant called the Max Radius, though any other positive value less than the distance will work.


Again, the random point generation is a choice and it may vary based on our needs. I can see that in the reference gif, the random points are uniformly distributed inside a circle, so our random generator can be created as define in the document about Disk Point Picking, that is, the random point is defined by the parametric equation:

$$ \begin{aligned} x &= \sqrt{r} \cos t\\ y &= \sqrt{r} \sin t \end{aligned} $$

Where $r$ and $t$ are uniform random variables, $t$ ranging from zero to two $\pi$ and $r$ ranging from zero to some max radius. Th result would be something like this:

Colored Balls

Had I used a normalized random vector, it would have been like this:

Colored Balls On A Ball


All we have to do now is generate a spiral on those spheres. A possible parametric equation would be the ones described in this question and answers, that is:

$$ \begin{aligned} x &= \sqrt{1-t^2}\cos (a \pi t)\\ y &= \sqrt{1-t^2}\sin (a \pi t)\\ z &= t \end{aligned} $$

Where $t$ ranges between negative one and one and $a$ controls the number of revolutions. Which results:


But since sin and cos and periodic, we can animate them by adding a phase shift:

Spiral Phase Shift

We can now transform this by some transformation matrix defined by the sphere locations and radii. Create a spline from it. And we are going to put that in a group to be able to use it easily.

Final Implementation

By looping over spheres, randomizing some of the parameters and transforming, as follows:


We get:


You can now render this as you wish. Maybe through in some random colors or make it particles like the reference gif.

Blend File:

  • 2
    $\begingroup$ So do you sit at home twirling your villain mustache thinking "Hum... What convoluted question shall I answer myself today?" Once again great post! $\endgroup$ Apr 12, 2018 at 21:32
  • 3
    $\begingroup$ @DuarteFarrajotaRamos Most if not all of these self answers are created as an answer to some challenge on twitter. And man do I love challenges ! This is only one of five challenges they gave me, so expect some more posts in the following days :D. $\endgroup$
    – Omar Emara
    Apr 13, 2018 at 17:47
  • $\begingroup$ Great keep it up, these are all pretty interesting. I've been planning to look into Animation Nodes myself, it is a pretty powerful tool, and these posts really motivate me. $\endgroup$ Apr 13, 2018 at 17:50
  • $\begingroup$ Hmmmm, sphere packing will make great bubbles for a coffee render :D $\endgroup$
    – 3pointedit
    Apr 14, 2018 at 13:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .