Fourier epicycles

Draw a closed shape, or upload a simple, high-contrast image - the server breaks the curve down into a sum of rotating circles (epicycles) using a real discrete Fourier transform (DFT), in PHP. This is the classic "Fourier drawing" technique: the more circles you allow, the more closely the tip of the chained circles traces the original curve.

The PHP code that actually runs (excerpt)
// X_k = sum_n (x_n + i*y_n) * e^(-2*pi*i*k*n/N)
for ($k = 0; $k < $n; $k++) {
    $sumRe = 0.0;
    $sumIm = 0.0;
    for ($i = 0; $i < $n; $i++) {
        $theta = -2.0 * M_PI * $k * $i / $n;
        $sumRe += $points[$i]['x'] * cos($theta) - $points[$i]['y'] * sin($theta);
        $sumIm += $points[$i]['x'] * sin($theta) + $points[$i]['y'] * cos($theta);
    }
    $amplitude = sqrt($sumRe ** 2 + $sumIm ** 2) / $n;
    $phase = atan2($sumIm, $sumRe);
}
Input

Draw a closed shape with your mouse or finger - you can use more than one stroke, then press Process.