1// Logarithmic spiral.
2// https://swiftcoder.wordpress.com/2010/06/21/logarithmic-spiral-distance-field/
3//
4// `s` is a scaling parameter. You could also use `scale(s)`.
5//
6// Growth rate parameter `g` controls how tightly and in which direction
7// the spiral spirals.
8// `g=0.1759` is a measured growth rate for a Nautilus shell.
9// This implementation requires 0 < g < 1 for a counterclockwise spiral,
10// or -1 < g < 0 for a clockwise spiral.
11//
12// The spiral makes a constant angle t with any radius vector.
13// You can define `g` as `cot t`.
14//
15// Distance field looks okay for g=.2, is bonkers for more extreme values.
16
17let
18    log_spiral [s, g] = make_shape {
19        dist [x,y,_,_] =
20            let r = mag[x,y];
21                t = phase[x,y];
22            in if (r == 0)
23                0
24            else
25                let n = (log(r/s)/g - t) / tau;
26                    upper_r = s * e^(g*(t+tau*ceil n));
27                    lower_r = s * e^(g*(t+tau*floor n));
28                in (min[abs(upper_r-r), abs(r-lower_r)] - r*abs g)
29                    / 1.24; /* empirical Lipschitz factor for g=.2 */
30        is_2d = true;
31    };
32
33in
34log_spiral [1, 0.2]
35