1// This reproduces a sample image from http://mercury.sexy/hg_sdf
2// Credit: @gsohler
3
4let
5    include lib.blend;
6    show_grid pitch shape =
7        make_shape {
8            dist p = shape.dist p;
9            colour p =
10                if (
11                    mod[abs(p.[X])+(0.001+pitch)/2,pitch] < 0.01 ||
12                    mod[abs(p.[Y])+(0.001+pitch)/2,pitch] < 0.01 ||
13                    mod[abs(p.[Z])+(0.001+pitch)/2,pitch] < 0.01
14                )
15                    black
16                else
17                    white;
18            bbox = shape.bbox;
19            is_2d = shape.is_2d;
20            is_3d = shape.is_3d;
21        };
22in
23columns [0.5, 3] .union [sphere, cube >> move[1,1,1]]
24  >> lipschitz 2
25  >> show_grid 0.3
26