-- | Mecha Examples
module Language.Mecha.Examples
( example
) where

import Language.Mecha.Assembly
import Language.Mecha.Solid
import Language.Mecha.Types

-- | A simple design example.
example :: IO ()
example = do
view    "example" 400 600 \$ scaleAll 0.4 \$ design
animate "example" 300 400 24 \$ map f [0, 1 / 24 .. 5]
where
f t = (Perspective, moveY d3 \$ rotateX (atan2 cz d2) \$ rotateZ a design)
where
a = 1 * pi / 2 * t - pi / 2
m = t
cx = m * cos a
cy = m * sin a
cz = m
d2 = sqrt \$ cx ** 2 + cy ** 2
d3 = sqrt \$ cx ** 2 + cy ** 2 + cz ** 2

design :: Asm
design = assemble
[ move ( 0, 0, 0) \$ color (0.2, 0.2, 1, 0) \$ part \$ difference sphereCube cyl3
, move (-4, 0, 0) \$ color (0.8, 0, 0, 0) \$ part \$ sphereCube
, move (-8, 0, 0) \$ color (0.8, 0, 0, 0) \$ part \$ sphere'
, move (-4, 4, 0) \$ color (0.8, 0, 0, 0) \$ part \$ cube'
, move ( 0, 4, 0) \$ color (0, 0.8, 0, 0) \$ part \$ cyl3
, move ( 0, 8, 0) \$ color (0, 0.8, 0, 0) \$ part \$ cyl
, move ( 0,12, 0) \$ color (0, 0.8, 0, 0) \$ part \$ rotateX (pi/2) cyl
, move ( 0,16, 0) \$ color (0, 0.8, 0, 0) \$ part \$ rotateY (pi/2) cyl
]

sphere' = sphere 2
cube' = cube \$ 2 * 0.75
sphereCube = intersection sphere' cube'
cyl = moveZ (-1) \$ cylinder 1 2
cyl3 = unions [cyl, rotateX (pi / 2) cyl, rotateY (pi / 2) cyl]