Skip to content

Instantly share code, notes, and snippets.

@ianthehenry
Last active July 12, 2023 07:00
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ianthehenry/612c980f0db04ea3c2ccab2741475870 to your computer and use it in GitHub Desktop.
Bauble: animated turtle
(def eye-target [100 20 40])
(def eye-shapes
(sphere 5
| move [8 10 10]
| mirror :z))
(def eyes
(eye-shapes
| color (c + 0.5)
| color (c - (dot normal (normalize eye-target) - 0.72 | clamp -1 0 | step 0))
| color [c.b c.g c.r]))
(def foot
(box [17 5 5] :r 5
| twist :x 0.05
| bend :y :z -0.052
| bend :z :y -0.012
| rotate :x 3.30 :y 1.63 :x -0.89))
(defn skin [s] (color s (+ c [-0.4 0.2 -0.3])))
(def head
(box :r 10 20
| scale :z (ss p.x 0 20 1 0.25)
| morph 0.5 (sphere 20)
| subtract :r 5 (box [45 7 63] | rotate :z (- pi/4) | move :x 25)
| subtract :r 1 (box [10.6 0 63] | rotate :z (1.28 - pi/4) | move [24 -1.1 0])
| subtract :r 4 eye-shapes
| subtract :r 1 (sphere 1 | move [17 8.3 2.4] | mirror :z)
| skin
| union eyes
| scale 0.9
))
(def shell (ellipsoid [50 50 45] | morph -0.2 (box 50)))
(def head-rotation (sin+ (t / 1.7) * sin+ (t / 9 + 9) * sin+ (+ t 10) | ss 0 1 0 0.3 + 0.1))
(def head-tilt (sin t * 0.02))
(def foot-offset [42 -17 18])
(def foot-pivot [-6 0 -5])
(intersect :r 10
shell
(half-space :y -18)
| subtract :r 5 (sphere 41 | move :y 95)
| subtract :r 5 (sphere 23 | move [40 -18 0])
| rotate :x (sin (t * 2) * 0.01)
| color (pow c 2)
| color [c.b c.g c.r]
| union (box :r 10 [54 10 15] | bend :z :y 0.01 | rotate :y (ss p.x 0 56 0 head-rotation) | skin
| move [30 -10 0]
| union :r 10 (head | move [77 10 0] | rotate :pivot [30 0 0] :y head-rotation :z head-tilt)
| union :r 10
(foot
| fork
(rotate :pivot foot-pivot :y (sin+ (t * 3) * -0.75) | move foot-offset)
(rotate :pivot foot-pivot :y (sin+ (t * 3 + (1 * pi/2)) * -0.75) | move foot-offset | reflect :z)
| spoon (move :x -57 | reflect :z)
| skin)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment