# teaching machines

## Crate

There’s something magical about wooden crates. Here’s a little program that recreates that magic on a small scale by subtracting away some triangular prisms from each face of a cube:

```

-- We first create an overall box structure. Later,
-- we will chisel out triangles from each face to
-- make it look like a crate.
.rgb = {1, 0.6, 0.2}
moveto 0, 0, 0
box

-- Now let\'s extrude out a pair of triangles on the +Z
-- face. We\'ll store that one extrusion and eventually
-- subtract it away from all six faces.
gap = 0.2
inset = 0.1
side = 2 - 2 * gap - 0.2
hypotenuse = side / cos 45

-- Bottom left
moveto -1 + gap, -1 + gap, 1 - inset
moveto -1 + gap, -1 + gap + side, 1 - inset
moveto -1 + gap + side, -1 + gap, 1 - inset
holeA = extrude 0, 0, 1, 0.15

-- Top right
moveto 1 - gap, 1 - gap, 1 - inset
moveto 1 - gap - side, 1 - gap, 1 - inset
moveto 1 - gap, 1 - gap - side, 1 - inset
holeB = extrude 0, 0, 1, 0.15

cutout = holeA or holeB

-- We\'ve now got our core structure and the cutout
-- geometry. Let\'s apply the cutout to each face.

subtract

transform cutout -- +Z
rotate 0, 1, 0, 90
transform cutout -- +X
rotate 0, 1, 0, 90
transform cutout -- -Z
rotate 0, 1, 0, 90
transform cutout -- -X
rotate 0, 0, 1, 90
transform cutout -- -Y
rotate 0, 0, 1, 180
transform cutout -- +Y

var mupDiv = jQuery('#mup_crate');
mupDiv.closest('pre').replaceWith(mupDiv);
document.getElementById('mup_form_crate').submit();

```

I printed the model in wood filament, and I can almost see a miniature dock worker sitting on it and eating his lunch: