Last updated: 2026-11-26
11. Animals: a bird, a rabbit and a fox
For new readers
The rabbit of the film is the hardest thing in it. This page builds animals: a bird feather by feather, fur as thousands of tufts over a body of blended ellipsoids, and a skeleton posed by placing the feet, whose legs are then solved. The rabbit and the fox use the fur and the skeleton, written in the scene language.
A Bird, Feather by Feather
A bird is a better test of the scene language than a tree, because nobody mistakes a bad one for a good one. This page builds a robin with the tools of Surfaces of any function and A language for scenes and models and nothing new in the renderer.
Two layers
A body under a coat. The body is one implicit function (Surfaces of any function): three ellipsoids, for the body, the head and the neck, joined with a smooth minimum (Surfaces of any function) so that there is no crease where the head meets the body. Over it goes a coat of feathers, each a flattened ball laid like a roof tile: long along the body, thin across it, tilted so that its rear end lifts off the surface.
func ell(cx, cy, cz, ra, rb, rc) = "(sqrt(((x - cx) / ra)^2 + ((y - cy) / rb)^2 + ((z - cz) / rc)^2) - 1) * 0.45"
func sm(p, q, k) = "min(p, q) - max(k - abs(p - q), 0)^2 / (4 k)"
The 0.45 brings the ellipsoid's function close to a distance (its smallest axis is about 0.45), so that the
blend sm has the same width in every direction.
Rings of feathers. The coat goes on in rings round the body's long axis, from the front to the back. Ring i
stands at x = s, where its radius is the ellipsoid's cross-section there; feathers in a ring are 360 / n
degrees apart and every second ring is turned half a step, so that each feather covers the gap between two in
the ring before. The same definition, plumage, covers the head with smaller feathers. A feather's colour comes
from where it is: orange on the underside and front, buff on the underside behind, brown on top, and one of two or
three shades by a seeded random number, so that the coat is not flat.
The rest. A tail of five long feathers in a fan, a wing on each side (seven flight feathers of falling
length and three rows of coverts, one wing mirrored with scale 1 1 -1), a glossy black eye (a sphere with a
very high shininess and a little reflection), a cone for a beak, and legs with three toes each.
# Animals, to be included. The body is one smooth function (ellipsoids blended with a smooth minimum) under a coat of
# overlapping flat feathers, each a flattened ball laid like a roof tile.
# include "parts/animals.scene"
# use robin(1) a robin sitting, facing +x, its feet on the origin's y = -1 (the perch is at y = -1)
# Lengths are in the bird's own units: the body is about 2 long.
material core_dark
color 0.45 0.33 0.2
ambient 0.15 diffuse 0.8 specular 0 shininess 5
end
material brown_a
color 0.42 0.3 0.18
ambient 0.18 diffuse 0.8 specular 0.03 shininess 12
end
material brown_b
color 0.5 0.36 0.21
ambient 0.18 diffuse 0.8 specular 0.03 shininess 12
end
material brown_c
color 0.34 0.24 0.14
ambient 0.18 diffuse 0.8 specular 0.03 shininess 12
end
material red_a
color 0.86 0.36 0.1
ambient 0.2 diffuse 0.8 specular 0.05 shininess 15
end
material red_b
color 0.92 0.45 0.14
ambient 0.2 diffuse 0.8 specular 0.05 shininess 15
end
material buff_a
color 0.82 0.74 0.6
ambient 0.2 diffuse 0.8 specular 0.03 shininess 12
end
material buff_b
color 0.72 0.64 0.5
ambient 0.2 diffuse 0.8 specular 0.03 shininess 12
end
material eye
color 0.02 0.02 0.02
ambient 0.02 diffuse 0.3 specular 1 shininess 400 reflective 0.15
end
material beak
color 0.18 0.14 0.1
ambient 0.15 diffuse 0.7 specular 0.3 shininess 40
end
material leg
color 0.62 0.5 0.45
ambient 0.2 diffuse 0.8 specular 0.1 shininess 20
end
material perch_bark
color 0.28 0.2 0.13
ambient 0.12 diffuse 0.8 specular 0 shininess 5
end
# one feather: a flattened ball, long along x, thin along y; v turns its thin axis to point out from the x axis,
# tilt lifts its rear end off the body; kind picks the colour
define feather(len, wid, tilt, v, px, py, pz, kind)
if kind == 0
sphere scale len 0.03 wid rotate z tilt rotate x v at px py pz material brown_a
else
if kind == 1
sphere scale len 0.03 wid rotate z tilt rotate x v at px py pz material brown_b
else
if kind == 2
sphere scale len 0.03 wid rotate z tilt rotate x v at px py pz material brown_c
else
if kind == 3
sphere scale len 0.03 wid rotate z tilt rotate x v at px py pz material red_a
else
if kind == 4
sphere scale len 0.03 wid rotate z tilt rotate x v at px py pz material red_b
else
if kind == 5
sphere scale len 0.03 wid rotate z tilt rotate x v at px py pz material buff_a
else
sphere scale len 0.03 wid rotate z tilt rotate x v at px py pz material buff_b
end
end
end
end
end
end
end
# a coat over an ellipsoid with its axes along x, y, z: rings of feathers from the front to the back, alternate rings
# turned half a step; underneath (cos v below ucut) the feathers are red in front of x = sred and buff behind it, on top brown
define plumage(cx, cy, cz, a, b, c, rings, around, flen, fwid, sred, ucut, seed)
for i in 0 to (rings - 1)
let s = (a * 0.94 * (1 - 2 * (i + 0.5) / rings))
let sq = (sqrt(1 - (s / a) ^ 2))
for j in 0 to (around - 1)
let v = (360 * (j + 0.5 * mod(i, 2)) / around)
let cv = (cosd(v))
let rr = (rand(seed + 17 * i + j))
let px = (cx + s)
let py = (cy + b * sq * cv)
let pz = (cz + c * sq * sind(v))
if cv < ucut
if px > sred
use feather(flen, fwid, -9, v, px, py, pz, (3 + floor(2 * rr)))
else
use feather(flen, fwid, -9, v, px, py, pz, (5 + floor(2 * rr)))
end
else
use feather(flen, fwid, -9, v, px, py, pz, (floor(3 * rr)))
end
end
end
end
func ell(cx, cy, cz, ra, rb, rc) = "(sqrt(((x - cx) / ra)^2 + ((y - cy) / rb)^2 + ((z - cz) / rc)^2) - 1) * 0.45"
func sm(p, q, k) = "min(p, q) - max(k - abs(p - q), 0)^2 / (4 k)"
# a folded wing in the plane z = 0 pointing back along -x, one side: long flight feathers in a stack, then rows of coverts
define wing()
for k in 0 to 6
let ln = (0.66 - 0.035 * k)
if mod(k, 2) == 0
sphere scale ln 0.06 0.015 at (-ln) 0 0 rotate z (2 + 1.5 * k) at 0.3 (0.12 - 0.045 * k) 0 material brown_c
else
sphere scale ln 0.06 0.015 at (-ln) 0 0 rotate z (2 + 1.5 * k) at 0.3 (0.12 - 0.045 * k) 0 material brown_a
end
end
for r in 0 to 2
for i in 0 to 4
sphere scale 0.2 0.08 0.02 at -0.2 0 0 rotate z 6 at (0.35 - 0.2 * i - 0.05 * r) (0.2 - 0.08 * r) (0.01 * r) material brown_b
end
end
end
define robin(seed)
surface "a = ell(0, 0, 0, 0.9, 0.52, 0.44); b = ell(1.0, 0.5, 0, 0.3, 0.3, 0.28); n = ell(0.68, 0.28, 0, 0.4, 0.36, 0.34); shape = sm(sm(a, b, 0.3), n, 0.3)" bounds -1.2 -0.8 -0.7 1.5 1.1 0.7 material core_dark
use plumage(0, 0, 0, 1.0, 0.56, 0.48, 20, 26, 0.15, 0.085, 0.3, 0.1, seed)
use plumage(1.0, 0.5, 0, 0.34, 0.34, 0.31, 10, 16, 0.1, 0.065, 0.72, 0.5, seed + 100)
# tail
for k in 0 to 4
sphere scale 0.8 0.016 0.12 at -0.75 0 0 rotate y (-16 + 8 * k) rotate z 16 at -0.8 0.08 0 material brown_c
end
# wings
use wing() at 0 0.1 0.5
use wing() scale 1 1 -1 at 0 0.1 -0.5
# eyes, beak
sphere scale 0.07 at 1.14 0.56 0.28 material eye
sphere scale 0.07 at 1.14 0.56 -0.28 material eye
cone -1 0 closed scale 0.07 0.3 0.07 rotate z -90 at 1.62 0.46 0 material beak
# legs and feet
for side in -1 to 1 step 2
cylinder 0 0.5 closed scale 0.04 1 0.04 at 0.15 -0.95 (0.2 * side) material leg
for t in 0 to 2
cylinder 0 0.22 closed scale 0.02 1 0.02 rotate z -90 rotate y (-25 + 25 * t) at 0.15 -0.97 (0.2 * side) material leg
end
end
end
Scenarios and oracles
There is no second tracer here, since the renderer is the one the the pages it builds on checked. What can be checked is what the definition builds:
- 20 ร 26 body feathers, 10 ร 16 head feathers, 5 in the tail, 22 in each wing and 2 eyes: 731 spheres; one smooth body, a beak, 8 cylinders for the legs and toes.
- Every orange feather is on the front: 189 of them, none behind
x = 0.3. - A different seed shades the feathers differently and keeps the count.
The picture
param w = 400
param h = 300
size w h
camera from 0.5 1.0 -5.4 to 0.5 0.0 0 fov 38
light point at -6 8 -8
include "parts/animals.scene"
material grass
color 0.4 0.62 0.3
ambient 0.3 diffuse 0.8 specular 0
end
material sky
color 0.6 0.78 0.95
ambient 0.95 diffuse 0 specular 0
end
plane at 0 -1.45 0 material grass
plane rotate x 90 at 0 0 30 material sky
cylinder -2.5 2.5 closed scale 0.1 1 0.1 rotate z 90 at 0 -1 0 material perch_bark
use robin(1) rotate y 40
What it is, and what it is not
It reads as a robin, because of the proportions, the orange breast and the overlapping feathers. It is not a photograph: the feathers are smooth ellipsoids, with no barbs, no fine detail at the edge of the wing, and no soft down between the layers; the legs are plain cylinders. The cost of 700 shapes is the render time: this picture took about four minutes on 20 cores, with no antialiasing.render time grows with shape count
Fur: a Rabbit and a Fox
Animals: a bird, a rabbit and a fox's bird was built from separate feathers. Fur cannot be: a rabbit has a few hundred thousand hairs, and a hair is far thinner than a pixel. Here the hairs are a picture: the picture gives the colour of each hair and, from the same strands, a height map, so that the light catches the tip of each hair and leaves the skin between in shadow. The shapes underneath are the blended bodies of Animals: a bird, a rabbit and a fox, built from ellipsoids and a smooth minimum; a few cones break the outline where fur would stick out (the cotton tail, the whiskers).
The fur pictures
tools/make_fur.patlang draws 105 000 strands into a picture of 1024 ร 1024 pixels that wraps at its edges, in three
layers: an undercoat of 60 000 short, dense, dark hairs (12 to 32 pixels), the coat of 40 000 (22 to 56), and 5 000 long guard
hairs (50 pixels) that stand above the rest and are a little lighter. A strand is a line along v, leaning a little and
waving a little, with a start and a length from a hash of its number. Where two strands cross, the higher point wins. Each pixel remembers which strand it came from and how far along
it (0 at the root, 1 at the tip), and two things are made from that:
- the height map: 0.1 for bare skin, then a height that rises along the hair, from 0.2 in the undercoat and 0.3 in the coat to 0.4 for a guard hair, so the tip is the highest point of a hair and a guard hair stands above the coat;
- a colour picture for each coat, with three colours along the hair (root, middle, tip) mixed smoothly, and a tone for each hair that makes it a little lighter or darker than its neighbours. The rabbit's brown is the agouti of a wild rabbit: grey at the root, brown in the middle and dark at the tip. The fox is dark at the root, orange in the middle and lighter at the tip. The white and black coats are for the fox's stockings and the brush's tip.
Colour and bump come from the same strands, so the colour of a hair is where its bump is.
The pictures are drawn each time they are needed, not kept in the repository (they are about 3 MB each); the build of this page draws them first.
# Writes the fur pictures for the animals of Chapter 36 into textures/: fur_height.ppm (a height map, root dark and tip
# bright) and one colour picture per coat, all 512 x 512 and drawn from the same strands, so that the colour of a hair is
# where its bump is. A strand is a slightly leaning, slightly wavy line of 14 to 40 pixels along v, drawn into a picture that
# wraps at its edges; where strands cross, the one with the higher point wins. Mapped spherically with the poles along the
# animal's length, or cylindrically on a leg, the strands run along the body.
# (cd tools && v2_interp.exe make_fur.patlang)
include "../lib/spec.patlang"
include "../lib/canvas.patlang"
make a function called hash2 takes a, b returns h
let v = sin(a * 12.9898 + b * 78.233) * 43758.5453
return v - floor(v)
end
# the colour of a coat at p along a hair (0 at the root, 1 at the tip), scaled by this hair's tone
make a function called mix3 takes a, b, t returns c
return [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t]
end
# the colour of a coat at p along a hair (0 at the root, 1 at the tip), scaled by this hair's tone: three colours, root, middle and tip,
# mixed smoothly along the hair
make a function called coat_color takes coat, p, tone returns rgb
let k = 0.88 + 0.24 * tone
let roots = [[0.5, 0.45, 0.4], [0.8, 0.78, 0.74], [0.45, 0.22, 0.1], [0.84, 0.8, 0.72], [0.06, 0.05, 0.05]]
let mids = [[0.56, 0.44, 0.31], [0.86, 0.84, 0.8], [0.8, 0.38, 0.1], [0.92, 0.9, 0.84], [0.1, 0.09, 0.08]]
let tips = [[0.3, 0.23, 0.17], [0.95, 0.94, 0.92], [0.9, 0.52, 0.2], [0.98, 0.97, 0.94], [0.2, 0.17, 0.15]]
let c = mix3(roots[coat], mids[coat], min(p / 0.4, 1))
if p > 0.7 then
let c = mix3(mids[coat], tips[coat], (p - 0.7) / 0.3)
end
return [c[0] * k, c[1] * k, c[2] * k]
end
let w = 1024
let h = 1024
let names = ["rabbit_brown", "rabbit_white", "fox_red", "fox_white", "fox_black"]
let height = vec_new()
let owner = vec_new()
let ptip = vec_new()
let layer = vec_new()
let i = 0
while i < w * h do
vec_push(height, 0.1)
vec_push(owner, 0 - 1)
vec_push(ptip, 0)
vec_push(layer, 0)
let i = i + 1
end
# one coat of hairs: count of them, their lengths, how high a tip stands, and which layer (0 under, 1 main, 2 guard)
make a function called draw_hairs takes w, h, height, owner, ptip, layer, count, minlen, rangelen, base, rise, lay, seed returns done
let s = 0
while s < count do
let id = seed + s
let x0 = hash2(id, 1) * w
let y0 = hash2(id, 2) * h
let len = minlen + hash2(id, 3) * rangelen
let lean = (hash2(id, 4) - 0.5) * 0.3
let wob = hash2(id, 5) * 6
let k = 0
while k < len do
let p = k / len
let fx = to_int(floor(x0 + lean * k + 0.8 * sin(wob + k * 0.22)))
let fy = to_int(floor(y0 + k))
let px = fx - w * floor(fx / w)
let py = fy - h * floor(fy / h)
let at = py * w + px
let ht = base + rise * p
if ht > vec_get(height, at) then
vec_set(height, at, ht)
vec_set(owner, at, id)
vec_set(ptip, at, p)
vec_set(layer, at, lay)
end
let k = k + 1
end
let s = s + 1
end
return true
end
# the undercoat: short, dense and dark; the coat; and a few long guard hairs that stand above it
draw_hairs(w, h, height, owner, ptip, layer, 60000, 12, 20, 0.2, 0.35, 0, 100000)
draw_hairs(w, h, height, owner, ptip, layer, 40000, 22, 34, 0.3, 0.55, 1, 200000)
draw_hairs(w, h, height, owner, ptip, layer, 5000, 50, 50, 0.4, 0.6, 2, 300000)
make a function called put_ppm takes path, coat, w, h, height, owner, ptip, layer returns done
let bytes = []
let header = "P6" + chr(10) + w + " " + h + chr(10) + "255" + chr(10)
let k = 0
while k < header.length do
let bytes = list_push(bytes, char_code(header, k))
let k = k + 1
end
let at = 0
while at < w * h do
let who = vec_get(owner, at)
let c = [0, 0, 0]
if coat < 0 then
let v = vec_get(height, at)
let c = [v, v, v]
else
if who < 0 then
let c = coat_color(coat, 0, 0.3)
else
let c = coat_color(coat, vec_get(ptip, at), hash2(who, 9))
let lf = [0.6, 1, 1.12]
let lv = lf[vec_get(layer, at)]
let c = [c[0] * lv, c[1] * lv, c[2] * lv]
end
end
let bytes = list_push(bytes, to_byte(c[0]))
let bytes = list_push(bytes, to_byte(c[1]))
let bytes = list_push(bytes, to_byte(c[2]))
let at = at + 1
end
write_file_bytes(path, bytes)
return true
end
put_ppm("../textures/fur_height.ppm", 0 - 1, w, h, height, owner, ptip, layer)
let c = 0
while c < names.length do
put_ppm("../textures/fur_" + names[c] + ".ppm", c, w, h, height, owner, ptip, layer)
print("wrote textures/fur_" + names[c] + ".ppm")
let c = c + 1
end
Putting fur on a body
The picture is mapped spherically (Bump and normal maps) about a point inside the body, with its poles turned from up to along the
body (rotate z 90), so that the hairs run from the head toward the tail. The mapping depends only on the direction from
that point, not the distance: so the picture is centred on the middle of the body (the fox has one for the head and one for the
brush as well), where the hairs are about the same size all over, and a leg that is a separate sphere has its own, centred on it.
# Furred animals, to be included. A body is one smooth function (ellipsoids joined by a smooth minimum); its fur is a picture of
# hairs that sets both the colour and the bump (textures/fur_*.ppm, made by tools/make_fur.patlang), plus cones for the tufts
# that break the outline.
# include "parts/mammals.scene"
# use rabbit(1) a sitting rabbit facing +x, its feet on y = 0, about 1.8 high
# Textures are named from the scene file's folder, so scenes in scenes/ read ../../textures/.
func ell(cx, cy, cz, ra, rb, rc) = "(sqrt(((x - cx) / ra)^2 + ((y - cy) / rb)^2 + ((z - cz) / rc)^2) - 1) * 0.3"
func sm(p, q, k) = "min(p, q) - max(k - abs(p - q), 0)^2 / (4 k)"
material rabbit_fur
color 1 1 1
ambient 0.25 diffuse 0.8 specular 0.02 shininess 8
texture ../../textures/fur_rabbit_brown.ppm spherical rotate z 90 at 0.45 0.85 0
bump height ../../textures/fur_height.ppm spherical strength 3 rotate z 90 at 0.45 0.85 0
end
material rabbit_white_fur
color 1 1 1
ambient 0.28 diffuse 0.8 specular 0.02 shininess 8
texture ../../textures/fur_rabbit_white.ppm spherical rotate z 90
bump height ../../textures/fur_height.ppm spherical strength 3 rotate z 90
end
material pink_skin
color 0.88 0.58 0.58
ambient 0.25 diffuse 0.8 specular 0.15 shininess 30
end
material dark_eye
color 0.02 0.015 0.015
ambient 0.02 diffuse 0.3 specular 1 shininess 500 reflective 0.2
end
material tuft_rabbit_a
color 0.5 0.4 0.28
ambient 0.25 diffuse 0.8 specular 0.02 shininess 8
end
material tuft_rabbit_b
color 0.42 0.33 0.23
ambient 0.25 diffuse 0.8 specular 0.02 shininess 8
end
material tuft_rabbit_c
color 0.55 0.43 0.3
ambient 0.25 diffuse 0.8 specular 0.02 shininess 8
end
material tuft_fox_a
color 0.82 0.4 0.1
ambient 0.25 diffuse 0.8 specular 0.02 shininess 8
end
material tuft_fox_b
color 0.66 0.3 0.08
ambient 0.25 diffuse 0.8 specular 0.02 shininess 8
end
material tuft_fox_c
color 0.92 0.55 0.18
ambient 0.25 diffuse 0.8 specular 0.02 shininess 8
end
# one tuft of hair: a thin cone with its base on the surface, laid back along -x and lifted by `lift` degrees off it;
# v turns the lift to the outward direction; kind 0-2 are the rabbit's three shades, 3-5 the fox's
define tuft(len, thick, lift, v, px, py, pz, kind)
if kind > 5
cone -1 0 closed scale thick len thick at 0 len 0 rotate z (90 - lift) rotate x v at px py pz material tuft_white
else
if kind == 0
cone -1 0 closed scale thick len thick at 0 len 0 rotate z (90 - lift) rotate x v at px py pz material tuft_rabbit_a
else
if kind == 1
cone -1 0 closed scale thick len thick at 0 len 0 rotate z (90 - lift) rotate x v at px py pz material tuft_rabbit_b
else
if kind == 2
cone -1 0 closed scale thick len thick at 0 len 0 rotate z (90 - lift) rotate x v at px py pz material tuft_rabbit_c
else
if kind == 3
cone -1 0 closed scale thick len thick at 0 len 0 rotate z (90 - lift) rotate x v at px py pz material tuft_fox_a
else
if kind == 4
cone -1 0 closed scale thick len thick at 0 len 0 rotate z (90 - lift) rotate x v at px py pz material tuft_fox_b
else
cone -1 0 closed scale thick len thick at 0 len 0 rotate z (90 - lift) rotate x v at px py pz material tuft_fox_c
end
end
end
end
end
end
end
# a coat of tufts over an ellipsoid with its axes along x, y and z, in rings from front to back (as plumage in Chapter 35);
# `base` is 0 for the rabbit's shades, 3 for the fox's and 6 for white
define fuzz(cx, cy, cz, a, b, c, rings, around, len, thick, base, seed)
for i in 0 to (rings - 1)
let s = (a * 0.96 * (1 - 2 * (i + 0.5) / rings))
let sq = (sqrt(1 - (s / a) ^ 2))
for j in 0 to (around - 1)
let v = (360 * (j + 0.5 * mod(i, 2)) / around)
let rr = (rand(seed + 31 * i + j))
use tuft((len * (0.7 + 0.6 * rand(seed + 5 * i + 7 * j + 1))), thick, (3 + 12 * rand(seed + 3 * i + 11 * j + 2)), v, (cx + s), (cy + b * sq * cosd(v)), (cz + c * sq * sind(v)), (base + floor(3 * rr)))
end
end
end
define rabbit(seed)
surface "h = ell(-0.45, 0.62, 0, 0.62, 0.6, 0.5); c = ell(0.3, 0.7, 0, 0.72, 0.52, 0.42); n = ell(0.85, 0.95, 0, 0.35, 0.4, 0.3); hd = ell(1.2, 1.1, 0, 0.42, 0.34, 0.3); m = ell(1.52, 1.0, 0, 0.2, 0.17, 0.17); k1 = ell(1.25, 0.95, 0.17, 0.25, 0.22, 0.15); k2 = ell(1.25, 0.95, -0.17, 0.25, 0.22, 0.15); l1 = ell(0.85, 0.28, 0.17, 0.12, 0.3, 0.1); l2 = ell(0.85, 0.28, -0.17, 0.12, 0.3, 0.1); f1 = ell(-0.1, 0.1, 0.4, 0.42, 0.1, 0.14); f2 = ell(-0.1, 0.1, -0.4, 0.42, 0.1, 0.14); shape = sm(sm(sm(sm(sm(sm(sm(sm(sm(sm(h, c, 0.25), n, 0.2), hd, 0.15), m, 0.1), k1, 0.1), k2, 0.1), l1, 0.1), l2, 0.1), f1, 0.1), f2, 0.1)" bounds -1.3 -0.1 -0.8 1.8 1.5 0.8 material rabbit_fur
use fuzz(-0.45, 0.62, 0, 0.62, 0.6, 0.5, 34, 52, 0.08, 0.009, 0, seed)
use fuzz(0.3, 0.7, 0, 0.72, 0.52, 0.42, 34, 52, 0.08, 0.009, 0, seed + 5000)
use fuzz(1.2, 1.1, 0, 0.42, 0.34, 0.3, 20, 34, 0.06, 0.007, 0, seed + 9000)
# ears: long, flattened, leaning back and a little apart
sphere scale 0.13 0.52 0.035 at 0 0.5 0 rotate z 16 rotate x 14 at 1.08 1.35 0.12 material rabbit_fur
sphere scale 0.13 0.52 0.035 at 0 0.5 0 rotate z 16 rotate x -14 at 1.08 1.35 -0.12 material rabbit_fur
sphere scale 0.07 0.4 0.036 at 0 0.5 0 rotate z 16 rotate x 14 at 1.08 1.355 0.125 material pink_skin
sphere scale 0.07 0.4 0.036 at 0 0.5 0 rotate z 16 rotate x -14 at 1.08 1.355 -0.125 material pink_skin
sphere scale 0.07 at 1.4 1.19 0.2 material dark_eye
sphere scale 0.07 at 1.4 1.19 -0.2 material dark_eye
sphere scale 0.045 at 1.72 1.03 0 material pink_skin
sphere scale 0.22 at -1.12 0.78 0 material rabbit_white_fur
use pom(0.16, 140, seed) at -1.12 0.78 0
use whiskers(1)
use whiskers(-1)
end
# ---- rabbit's whiskers, tail tuft ----
define whiskers(side)
for k in 0 to 2
cone -1 0 closed scale 0.006 0.55 0.006 at 0 0.55 0 rotate z (-98 - 6 * k) rotate y (0 - side * (65 + 15 * k)) at 1.72 (1.03 - 0.02 * k) (0.06 * side) material whisker
end
end
material whisker
color 0.95 0.95 0.92
ambient 0.3 diffuse 0.7 specular 0.4 shininess 60
end
# a pom of cones all round a centre: the cotton tail
define pom(r, n, seed)
for i in 0 to (n - 1)
let a = 360 * rand(seed + i)
let b = (60 * (rand(seed + 7 * i + 3) - 0.5) * 3)
let len = (r * (0.8 + 0.4 * rand(seed + 11 * i)))
cone -1 0 closed scale 0.05 len 0.05 at 0 len 0 rotate z (90 + b) rotate x a at 0 0 0 material rabbit_white_fur
end
end
# ---- the fox: slender, a long snout, black stockings, a brush with a white tip ----
# one material per part, each with its picture centred where that part is, so that the hairs have the same size everywhere
material fox_body_fur
color 1 1 1
ambient 0.25 diffuse 0.8 specular 0.02 shininess 8
texture ../../textures/fur_fox_red.ppm spherical rotate z 90 at 0.4 1.0 0
bump height ../../textures/fur_height.ppm spherical strength 3 rotate z 90 at 0.4 1.0 0
end
material fox_head_fur
color 1 1 1
ambient 0.25 diffuse 0.8 specular 0.02 shininess 8
texture ../../textures/fur_fox_red.ppm spherical rotate z 90 at 1.4 1.35 0
bump height ../../textures/fur_height.ppm spherical strength 3 rotate z 90 at 1.4 1.35 0
end
material fox_tail_fur
color 1 1 1
ambient 0.25 diffuse 0.8 specular 0.02 shininess 8
texture ../../textures/fur_fox_red.ppm spherical rotate z 90 at -1.7 0.85 0
bump height ../../textures/fur_height.ppm spherical strength 3 rotate z 90 at -1.7 0.85 0
end
material tuft_white
color 0.95 0.93 0.88
ambient 0.3 diffuse 0.8 specular 0.02 shininess 8
end
material fox_white_fur
color 1 1 1
ambient 0.3 diffuse 0.8 specular 0.02 shininess 8
texture ../../textures/fur_fox_white.ppm spherical rotate z 90
bump height ../../textures/fur_height.ppm spherical strength 3 rotate z 90
end
material fox_black_fur
color 1 1 1
ambient 0.2 diffuse 0.8 specular 0.05 shininess 12
texture ../../textures/fur_fox_black.ppm spherical
bump height ../../textures/fur_height.ppm spherical strength 3
end
material fox_red_leg_fur
color 1 1 1
ambient 0.25 diffuse 0.8 specular 0.02 shininess 8
texture ../../textures/fur_fox_red.ppm spherical
bump height ../../textures/fur_height.ppm spherical strength 3
end
material amber_eye
color 0.75 0.5 0.1
ambient 0.1 diffuse 0.5 specular 1 shininess 400 reflective 0.15
end
define fox(seed)
group at 0 0.2 0
# body, haunch, neck, thighs and the upper front legs: one smooth form
surface "c = ell(0.3, 0.95, 0, 0.55, 0.42, 0.32); h = ell(-0.4, 0.95, 0, 0.5, 0.4, 0.3); n = ell(0.85, 1.22, 0, 0.33, 0.3, 0.23); t1 = ell(-0.55, 0.62, 0.15, 0.14, 0.36, 0.12); t2 = ell(-0.55, 0.62, -0.15, 0.14, 0.36, 0.12); e1 = ell(0.5, 0.66, 0.14, 0.1, 0.34, 0.09); e2 = ell(0.5, 0.66, -0.14, 0.1, 0.34, 0.09); shape = sm(sm(sm(sm(sm(sm(h, c, 0.3), n, 0.25), t1, 0.12), t2, 0.12), e1, 0.1), e2, 0.1)" bounds -1.1 0.2 -0.5 1.3 1.6 0.5 material fox_body_fur
use fuzz(0.3, 0.95, 0, 0.55, 0.42, 0.32, 34, 52, 0.09, 0.009, 3, seed)
use fuzz(-0.4, 0.95, 0, 0.5, 0.4, 0.3, 34, 52, 0.09, 0.009, 3, seed + 5000)
use fuzz(0.85, 1.22, 0, 0.33, 0.3, 0.23, 18, 34, 0.08, 0.008, 3, seed + 9000)
# head: skull, long snout, cheeks
surface "s = ell(1.35, 1.4, 0, 0.3, 0.26, 0.22); m = ell(1.75, 1.3, 0, 0.3, 0.1, 0.09); k1 = ell(1.3, 1.28, 0.13, 0.22, 0.16, 0.1); k2 = ell(1.3, 1.28, -0.13, 0.22, 0.16, 0.1); shape = sm(sm(sm(s, m, 0.12), k1, 0.1), k2, 0.1)" bounds 0.9 1.0 -0.45 2.2 1.8 0.45 material fox_head_fur
use fuzz(1.35, 1.4, 0, 0.3, 0.26, 0.22, 20, 34, 0.06, 0.007, 3, seed + 13000)
use fuzz(1.3, 1.22, 0.13, 0.2, 0.14, 0.09, 14, 24, 0.12, 0.009, 6, seed + 15000)
use fuzz(1.3, 1.22, -0.13, 0.2, 0.14, 0.09, 14, 24, 0.12, 0.009, 6, seed + 17000)
sphere scale 0.28 0.07 0.08 at 1.74 1.235 0 material fox_white_fur
sphere scale 0.1 0.2 0.16 at 1.15 1.05 0 material fox_white_fur
use fuzz(1.15, 1.05, 0, 0.1, 0.2, 0.16, 14, 24, 0.07, 0.007, 6, seed + 19000)
sphere scale 0.045 at 2.04 1.31 0 material dark_eye
sphere scale 0.045 at 1.58 1.46 0.15 material amber_eye
sphere scale 0.045 at 1.58 1.46 -0.15 material amber_eye
# ears, with a pale lining
cone -1 0 closed scale 0.12 0.4 0.04 at 0 0.4 0 rotate z 10 rotate x 8 at 1.3 1.58 0.1 material fox_black_fur
cone -1 0 closed scale 0.12 0.4 0.04 at 0 0.4 0 rotate z 10 rotate x -8 at 1.3 1.58 -0.1 material fox_black_fur
cone -1 0 closed scale 0.07 0.3 0.03 at 0 0.3 0 rotate z 10 rotate x 8 at 1.32 1.58 0.128 material fox_white_fur
cone -1 0 closed scale 0.07 0.3 0.03 at 0 0.3 0 rotate z 10 rotate x -8 at 1.32 1.58 -0.128 material fox_white_fur
# the brush
surface "a = ell(-1.2, 1.0, 0, 0.35, 0.2, 0.2); b = ell(-1.65, 0.88, 0, 0.4, 0.27, 0.27); c = ell(-2.1, 0.75, 0, 0.35, 0.22, 0.22); shape = sm(sm(a, b, 0.2), c, 0.2)" bounds -2.6 0.3 -0.6 -0.8 1.3 0.6 material fox_tail_fur
use fuzz(-1.2, 1.0, 0, 0.35, 0.2, 0.2, 18, 30, 0.12, 0.011, 3, seed + 21000)
use fuzz(-1.65, 0.88, 0, 0.4, 0.27, 0.27, 24, 36, 0.14, 0.012, 3, seed + 23000)
use fuzz(-2.1, 0.75, 0, 0.35, 0.22, 0.22, 20, 32, 0.12, 0.011, 3, seed + 25000)
sphere scale 0.3 0.21 0.21 at -2.45 0.7 0 material fox_white_fur
use fuzz(-2.45, 0.7, 0, 0.3, 0.21, 0.21, 18, 30, 0.13, 0.011, 6, seed + 27000)
end
# legs: black stockings below the red
for side in -1 to 1 step 2
sphere scale 0.07 0.4 0.07 at 0.5 0.4 (0.14 * side) material fox_black_fur
sphere scale 0.11 0.045 0.08 at 0.55 0.04 (0.14 * side) material fox_black_fur
sphere scale 0.07 0.4 0.07 at -0.7 0.4 (0.15 * side) material fox_black_fur
sphere scale 0.11 0.045 0.08 at -0.65 0.04 (0.15 * side) material fox_black_fur
end
end
Scenarios and oracles
There is no second renderer here; the renderer and the bump and texture mappings are those that Pictures on surfaces: texture and cube maps and Bump and normal maps checked. What can be checked is what the pictures and the definitions make:
- The six pictures are 1024 ร 1024; the height map runs from 0.1 (skin) to about 1 (a tip).
- The fox's colour is where its bump is: the pixels at the tips of hairs are redder, on average, than the bare skin.
- The black coat is dark and the white coat light.
- A rabbit is one smooth body, 8 spheres and 4 362 cones (4 216 tufts of fur, 140 of the tail pom and 6 whiskers); a fox is three smooth bodies (body, head, brush), 14 spheres and 8 424 cones; the rabbit's fur material has a picture and a height map.
- A binary PPM read a row at a time is the same canvas as the whole file parsed at once.
The pictures
A rabbit, sitting, turned a little away:
param w = 480
param h = 380
size w h
camera from 0.4 1.3 -5.0 to 0.4 0.85 0 fov 36
light point at -5 8 -7
include "parts/mammals.scene"
material grass
color 0.4 0.62 0.3
ambient 0.3 diffuse 0.8 specular 0
end
material sky
color 0.6 0.78 0.95
ambient 0.95 diffuse 0 specular 0
end
plane material grass
plane rotate x 90 at 0 0 30 material sky
use rabbit(1) rotate y 35
and a fox, standing:
param w = 480
param h = 360
size w h
camera from 0.3 1.8 -7.2 to 0.3 0.9 0 fov 40
light point at -5 8 -7
include "parts/mammals.scene"
material grass
color 0.4 0.62 0.3
ambient 0.3 diffuse 0.8 specular 0
end
material sky
color 0.6 0.78 0.95
ambient 0.95 diffuse 0 specular 0
end
plane material grass
plane rotate x 90 at 0 0 30 material sky
use fox(1) rotate y 28 at 0.2 0 0
What it is, and what it is not
Both are recognisably what they are, and the fur reads as fur in a picture of this size: the light catches the hair tips and the colours vary hair to hair. Close up it would not hold: the hairs are the picture's pixels, so they get blocky and blurred when magnified; the fur does not move, parts, or fall over itself, and a hair never casts a shadow on another (the bump changes the shading, not the shape). What breaks the outline are the tufts: thin cones laid over each ellipsoid of the body in rings from front to back, as the feathers of Animals: a bird, a rabbit and a fox were, each lying back along the body and lifted a few degrees off it, in three shades near the coat's own. There are about 4 200 on the rabbit and 8 400 on the fox, and they are what makes the edge a haze and not a line; the cheeks, the chest and the brush of the fox have longer ones, and the white parts have white ones.
The animals take a long time to render: the scene is built again by each of the 20 processes that share a picture, and the smooth body is solved by the interval method of Surfaces of any function for every ray that reaches it. They were allowed to cost what they cost. The chapter did, though, make the library faster in two places that mattered: a PPM is now read a row at a time straight into the canvas (a 1024 ร 1024 picture took 6 s and 200 MB as one list of bytes, and 20 processes asked for it at once; it takes under 2 s now), and a picture named by several materials of a scene is read once.interval method finds roots of f(x):0
A Skeleton, and Posing by the Feet
Until now an animal has been built in one pose. To make it sit, or stretch, or step, someone had to move the numbers of every leg by hand and keep the bones the same length while doing it. A better way to pose a limb is the way a person does it: say where the foot goes, and let the leg follow. That is inverse kinematics: from the place of the foot, find the joints.
Two bones
A leg of two bones, a thigh from the hip to the knee and a shin from the knee to the foot, is a triangle: the hip, the knee and the foot are its
corners, and its sides are the length l1 of the thigh, the length l2 of the shin, and d, the distance from the hip to the foot. Its angles
follow from its sides by the law of cosines. The angle at the hip, between the line to the foot and the thigh, is
cos A = (l1^2 + d^2 - l2^2) / (2 l1 d)
and the knee is the hip plus l1 along the line to the foot, turned by A toward one side. There are two sides a knee could be on, the
mirror images of each other in the line from hip to foot, and a pole says which: the direction the limb bends toward (the front for a
knee, the back for an elbow). The knee is in the plane of the hip, the foot and the pole, on the pole's side of the line.
Two things can go wrong, and neither is an error:
- The foot may be too far, beyond
l1 + l2. The limb is then straight, pointing at it, and the foot as far as it will go. - The foot may be too near, closer than
|l1 - l2|. The limb is folded back on itself, the foot as near as it can come.
Either way the bones keep their lengths, and reached says whether the foot is where it was asked to be.
Three bones
An animal's leg has a third bone: the long bone of the foot, which the animal stands on or points. It is not free, it points
along a direction given with it (flat on the ground, say, or steeply down), so the ankle is the place of the foot moved back along that direction by
l3, and the thigh and the shin are the two-bone problem from the hip to the ankle. That is a rabbit's hind leg (a thigh,
a shin that goes back to the hock, a long flat foot) and a fox's.
Points and directions are the tuples of the foundation pages, conformal points and vectors, and the solver is made of what they offer (sums, scalings, dot products, normalisations). It does not need an angle for the knee; it does not need a rotation at all.conformal algebra: points and directions as tuples
# A skeleton posed by inverse kinematics: a limb of two or three bones is given the place its foot should be, and the joints are solved for.
# Points and vectors are the tuples of tuple.patlang (conformal points and directions), so moving a foot is adding a vector to a point.
#
# rig_two_bone(root, target, l1, l2, pole) -> [middle joint, tip, reached]
# rig_three_bone(root, target, l1, l2, l3, toe, pole) -> [first joint, ankle, tip, reached]
#
# TWO BONES. The root, the middle joint and the tip are the corners of a triangle with sides l1 (root to middle), l2 (middle to tip) and
# d (root to tip). The law of cosines gives the angle at the root between the line to the tip and the first bone,
# cos A = (l1^2 + d^2 - l2^2) / (2 l1 d),
# and the middle joint is the root plus l1 along the line to the tip turned by A toward the POLE, the direction the limb bends toward
# (a knee toward the front, an elbow toward the back): in the plane of root, tip and pole, on the pole's side of the line. The tip is
# where it was asked to be if the target is within reach, |l1 - l2| <= d <= l1 + l2; a target that is too far leaves the limb straight and
# pointing at it, and one that is too near folds the limb back on itself (the tip stopping at |l1 - l2|). `reached` says which.
#
# THREE BONES (a thigh, a shin and a foot). The foot is not free: it points along `toe` (a flat foot on the ground, say), so the ankle is
# the target moved back along it by l3, and the thigh and the shin are the two-bone problem from the root to the ankle.
include "tuple.patlang"
# the unit vector along the part of `pole` that is across u (at a right angle to it); when the pole is along u there is no such part
# and any direction across will do
make a function called rig_across takes u, pole returns v
let p = tuple_sub(pole, tuple_mul(u, dot(pole, u)))
if magnitude(p) > 0.000000001 then
return normalize(p)
end
let q = vector(0, 1, 0)
let r = tuple_sub(q, tuple_mul(u, dot(q, u)))
if magnitude(r) > 0.000000001 then
return normalize(r)
end
let s = vector(1, 0, 0)
return normalize(tuple_sub(s, tuple_mul(u, dot(s, u))))
end
make a function called rig_two_bone takes root, target, l1, l2, pole returns sol
let to = tuple_sub(target, root)
let d = magnitude(to)
let u = vector(0, 0 - 1, 0)
if d > 0.000000000001 then
let u = tuple_mul(to, 1 / d)
end
let lo = abs(l1 - l2)
let hi = l1 + l2
let reached = true
if d > hi then
let d = hi
let reached = false
elif d < lo then
let d = lo
let reached = false
end
let cos_a = 0
if d > 0.000000000001 then
let cos_a = (l1 * l1 + d * d - l2 * l2) / (2 * l1 * d)
if cos_a > 1 then
let cos_a = 1
end
if cos_a < 0 - 1 then
let cos_a = 0 - 1
end
end
let sin_a = sqrt(1 - cos_a * cos_a)
let v = rig_across(u, pole)
let mid = tuple_add(root, tuple_add(tuple_mul(u, l1 * cos_a), tuple_mul(v, l1 * sin_a)))
let tip = tuple_add(root, tuple_mul(u, d))
return [mid, tip, reached]
end
make a function called rig_three_bone takes root, target, l1, l2, l3, toe, pole returns sol
let f = normalize(toe)
let ankle_wanted = tuple_sub(target, tuple_mul(f, l3))
let r = rig_two_bone(root, ankle_wanted, l1, l2, pole)
let ankle = r[1]
return [r[0], ankle, tuple_add(ankle, tuple_mul(f, l3)), r[2]]
end
In the scene language
The solver is a statement of the language:
ik hl hip -0.4 0.62 0.4 foot 0.08 0.06 0.4 bones 0.45 0.42 0.45 toe 1 0 0 pole 1 0.1 0.3
solves the limb called hl and gives names to what it found, for the statements that follow: hl_kx hl_ky hl_kz (the knee), hl_ax hl_ay hl_az (the ankle),
hl_tx hl_ty hl_tz (the tip of the foot) and hl_reach (1 if the foot is where it was put). A limb is then drawn between its joints. For that, the shape
of a bone is a piece of function: capsule(ax, ay, az, bx, by, bz, r0, r1) is the distance from the point (x, y, z) to the segment from a to b, less a radius that
goes from r0 to r1 along it, a tapered capsule that needs no rotation to put between two points, and that blends smoothly (the smooth minimum of Surfaces of any function)
with the next bone and with the body.
The language also has the functions to work out angles when they are needed: acos, asin, atan2 and, in degrees, acosd, asind, atan2d, of numbers.
# Parts for posed limbs, to be included (Chapter 39).
# include "parts/rig.scene"
# The ik statement (see the scene language) solves a limb from the hip to a foot and names the joints (leg_kx, leg_ky, leg_kz, ...); a limb is then drawn
# between them with `capsule`, a function of the shape: the distance to a tapered capsule, the segment from a to b with the radius going from r0 to r1,
# which is a piece to be used in a `surface`, and blends smoothly (smooth minimum) with the body it is part of.
# func capsule(ax, ay, az, bx, by, bz, r0, r1)
# func sm(p, q, k)
func capt(ax, ay, az, bx, by, bz) = "max(0, min(1, ((x - ax) * (bx - ax) + (y - ay) * (by - ay) + (z - az) * (bz - az)) / ((bx - ax)^2 + (by - ay)^2 + (bz - az)^2)))"
func capsule(ax, ay, az, bx, by, bz, r0, r1) = "sqrt((x - ax - capt(ax, ay, az, bx, by, bz) * (bx - ax))^2 + (y - ay - capt(ax, ay, az, bx, by, bz) * (by - ay))^2 + (z - az - capt(ax, ay, az, bx, by, bz) * (bz - az))^2) - (r0 + capt(ax, ay, az, bx, by, bz) * (r1 - r0))"
func sm(p, q, k) = "min(p, q) - max(k - abs(p - q), 0)^2 / (4 k)"
Posed animals
The rabbit and the fox are as they were in Animals: a bird, a rabbit and a fox, but each leg is a limb that is solved from its hip to the foot that is put on the ground, or in the air:
rabbit_rig(seed, skel, hind left foot, hind right foot, front left foot, front right foot), each foot an x, y and z, and three poses of it,
rabbit_sit, rabbit_stretch and rabbit_hop; for the fox, fox_rig, fox_stand and fox_step. With skel set to 1 the animal is drawn as the skeleton that was
solved, bones as capsules and joints as balls, to see what the solver did.
# Animals that are posed by their feet (Chapter 39), to be included.
# include "parts/rigged.scene"
# use rabbit_rig(seed, hl..., hr..., fl..., fr...) the feet of a rabbit, each as x y z: hind left, hind right, front left, front right
# use rabbit_sit(seed) use rabbit_stretch(seed) use rabbit_hop(seed) three poses of it
# use fox_rig(seed, ...) use fox_stand(seed) use fox_step(seed)
# The body is as in mammals.scene. Each leg is solved from its hip to the place its foot is put (the ik statement: the law of cosines, so the bones keep
# their lengths), and drawn as three tapered capsules, smoothly joined, between the joints. Left is +z, right is -z; the animal faces +x.
include "mammals.scene"
include "rig.scene"
define rabbit_rig(seed, skel, hlx, hly, hlz, hrx, hry, hrz, flx, fly, flz, frx, fry, frz)
ik hl hip (-0.4) 0.62 0.4 foot hlx hly hlz bones 0.45 0.42 0.45 toe 1 0 0 pole 1 0.1 0.3
ik hr hip (-0.4) 0.62 (-0.4) foot hrx hry hrz bones 0.45 0.42 0.45 toe 1 0 0 pole 1 0.1 (-0.3)
ik fl hip 0.8 0.58 0.17 foot flx fly flz bones 0.33 0.33 0.14 toe 1 0 0 pole (-1) 0.3 0
ik fr hip 0.8 0.58 (-0.17) foot frx fry frz bones 0.33 0.33 0.14 toe 1 0 0 pole (-1) 0.3 0
if skel > 0
use rabbit_bones()
else
# the body: haunch, chest, neck, head, muzzle and cheeks, with its tufts of fur
surface "h = ell(-0.45, 0.62, 0, 0.62, 0.6, 0.5); c = ell(0.3, 0.7, 0, 0.72, 0.52, 0.42); n = ell(0.85, 0.95, 0, 0.35, 0.4, 0.3); hd = ell(1.2, 1.1, 0, 0.42, 0.34, 0.3); m = ell(1.52, 1.0, 0, 0.2, 0.17, 0.17); k1 = ell(1.25, 0.95, 0.17, 0.25, 0.22, 0.15); k2 = ell(1.25, 0.95, -0.17, 0.25, 0.22, 0.15); shape = sm(sm(sm(sm(sm(sm(h, c, 0.25), n, 0.2), hd, 0.15), m, 0.1), k1, 0.1), k2, 0.1)" bounds -1.3 -0.1 -0.8 1.8 1.5 0.8 material rabbit_fur
use fuzz(-0.45, 0.62, 0, 0.62, 0.6, 0.5, 34, 52, 0.08, 0.009, 0, seed)
use fuzz(0.3, 0.7, 0, 0.72, 0.52, 0.42, 34, 52, 0.08, 0.009, 0, seed + 5000)
use fuzz(1.2, 1.1, 0, 0.42, 0.34, 0.3, 20, 34, 0.06, 0.007, 0, seed + 9000)
# the legs, each a smooth chain of three capsules from the hip, through the joints the ik statement found, to the foot
surface "a = capsule(-0.4, 0.62, 0.4, hl_kx, hl_ky, hl_kz, 0.22, 0.12); b = capsule(hl_kx, hl_ky, hl_kz, hl_ax, hl_ay, hl_az, 0.12, 0.07); c = capsule(hl_ax, hl_ay, hl_az, hl_tx, hl_ty, hl_tz, 0.07, 0.06); shape = sm(sm(a, b, 0.06), c, 0.04)" bounds -1.4 -0.1 -0.8 1.8 1.5 0.8 material rabbit_fur
surface "a = capsule(-0.4, 0.62, -0.4, hr_kx, hr_ky, hr_kz, 0.22, 0.12); b = capsule(hr_kx, hr_ky, hr_kz, hr_ax, hr_ay, hr_az, 0.12, 0.07); c = capsule(hr_ax, hr_ay, hr_az, hr_tx, hr_ty, hr_tz, 0.07, 0.06); shape = sm(sm(a, b, 0.06), c, 0.04)" bounds -1.4 -0.1 -0.8 1.8 1.5 0.8 material rabbit_fur
surface "a = capsule(0.8, 0.58, 0.17, fl_kx, fl_ky, fl_kz, 0.13, 0.09); b = capsule(fl_kx, fl_ky, fl_kz, fl_ax, fl_ay, fl_az, 0.09, 0.07); c = capsule(fl_ax, fl_ay, fl_az, fl_tx, fl_ty, fl_tz, 0.07, 0.06); shape = sm(sm(a, b, 0.05), c, 0.04)" bounds -0.5 -0.1 -0.8 2 1.5 0.8 material rabbit_fur
surface "a = capsule(0.8, 0.58, -0.17, fr_kx, fr_ky, fr_kz, 0.13, 0.09); b = capsule(fr_kx, fr_ky, fr_kz, fr_ax, fr_ay, fr_az, 0.09, 0.07); c = capsule(fr_ax, fr_ay, fr_az, fr_tx, fr_ty, fr_tz, 0.07, 0.06); shape = sm(sm(a, b, 0.05), c, 0.04)" bounds -0.5 -0.1 -0.8 2 1.5 0.8 material rabbit_fur
# ears, eyes, nose, tail and whiskers
sphere scale 0.13 0.52 0.035 at 0 0.5 0 rotate z 16 rotate x 14 at 1.08 1.35 0.12 material rabbit_fur
sphere scale 0.13 0.52 0.035 at 0 0.5 0 rotate z 16 rotate x -14 at 1.08 1.35 -0.12 material rabbit_fur
sphere scale 0.07 0.4 0.036 at 0 0.5 0 rotate z 16 rotate x 14 at 1.08 1.355 0.125 material pink_skin
sphere scale 0.07 0.4 0.036 at 0 0.5 0 rotate z 16 rotate x -14 at 1.08 1.355 -0.125 material pink_skin
sphere scale 0.07 at 1.4 1.19 0.2 material dark_eye
sphere scale 0.07 at 1.4 1.19 -0.2 material dark_eye
sphere scale 0.045 at 1.72 1.03 0 material pink_skin
sphere scale 0.22 at -1.12 0.78 0 material rabbit_white_fur
use pom(0.16, 140, seed) at -1.12 0.78 0
use whiskers(1)
use whiskers(-1)
end
end
# sitting: the hind feet flat under the haunch, the front paws just forward of the chest
define rabbit_sit(seed, skel)
use rabbit_rig(seed, skel, 0.08, 0.06, 0.4, 0.08, 0.06, (-0.4), 1.0, 0.06, 0.17, 1.0, 0.06, (-0.17))
end
# stretched: the hind feet pushed back and the front paws reaching out ahead
define rabbit_stretch(seed, skel)
use rabbit_rig(seed, skel, (-0.55), 0.06, 0.4, (-0.55), 0.06, (-0.4), 1.25, 0.06, 0.2, 1.25, 0.06, (-0.2))
end
# a hop: the hind feet lifted and swung forward, the front paws reaching
define rabbit_hop(seed, skel)
use rabbit_rig(seed, skel, 0.35, 0.3, 0.4, 0.35, 0.3, (-0.4), 1.2, 0.2, 0.17, 1.2, 0.2, (-0.17))
end
# sitting up on its haunches: the body turned up by `pitch` degrees about the middle of the haunch, the hind feet flat on the ground in front of it, the
# front paws held against its belly. The hips go with the body, so the hind legs are solved from the turned hips to feet that stay on the ground; the front legs are
# solved in the body's own frame and turn with it.
define rabbit_upright(seed, pitch)
ik hl hip (-0.45 + 0.05 * cosd(pitch)) (0.62 + 0.05 * sind(pitch)) 0.4 foot 0.12 0.06 0.4 bones 0.45 0.42 0.45 toe 1 0 0 pole 1 0.1 0.3
ik hr hip (-0.45 + 0.05 * cosd(pitch)) (0.62 + 0.05 * sind(pitch)) (-0.4) foot 0.12 0.06 (-0.4) bones 0.45 0.42 0.45 toe 1 0 0 pole 1 0.1 (-0.3)
ik fl hip 0.8 0.58 0.17 foot 0.66 0.16 0.16 bones 0.33 0.33 0.14 toe 1 0 0 pole (-1) 0.3 0
ik fr hip 0.8 0.58 (-0.17) foot 0.66 0.16 (-0.16) bones 0.33 0.33 0.14 toe 1 0 0 pole (-1) 0.3 0
# the hind legs, in the room's frame
surface "a = capsule(-0.45 + 0.05 * cosd(pitch), 0.62 + 0.05 * sind(pitch), 0.4, hl_kx, hl_ky, hl_kz, 0.22, 0.12); b = capsule(hl_kx, hl_ky, hl_kz, hl_ax, hl_ay, hl_az, 0.12, 0.07); c = capsule(hl_ax, hl_ay, hl_az, hl_tx, hl_ty, hl_tz, 0.07, 0.06); shape = sm(sm(a, b, 0.06), c, 0.04)" bounds -1.6 -0.1 -0.8 1.8 2.6 0.8 material rabbit_fur
surface "a = capsule(-0.45 + 0.05 * cosd(pitch), 0.62 + 0.05 * sind(pitch), -0.4, hr_kx, hr_ky, hr_kz, 0.22, 0.12); b = capsule(hr_kx, hr_ky, hr_kz, hr_ax, hr_ay, hr_az, 0.12, 0.07); c = capsule(hr_ax, hr_ay, hr_az, hr_tx, hr_ty, hr_tz, 0.07, 0.06); shape = sm(sm(a, b, 0.06), c, 0.04)" bounds -1.6 -0.1 -0.8 1.8 2.6 0.8 material rabbit_fur
# the body and everything on it, turned about the middle of the haunch
group at 0.45 (-0.62) 0 rotate z pitch at (-0.45) 0.62 0
surface "h = ell(-0.45, 0.62, 0, 0.62, 0.6, 0.5); c = ell(0.3, 0.7, 0, 0.72, 0.52, 0.42); n = ell(0.85, 0.95, 0, 0.35, 0.4, 0.3); hd = ell(1.2, 1.1, 0, 0.42, 0.34, 0.3); m = ell(1.52, 1.0, 0, 0.2, 0.17, 0.17); k1 = ell(1.25, 0.95, 0.17, 0.25, 0.22, 0.15); k2 = ell(1.25, 0.95, -0.17, 0.25, 0.22, 0.15); shape = sm(sm(sm(sm(sm(sm(h, c, 0.25), n, 0.2), hd, 0.15), m, 0.1), k1, 0.1), k2, 0.1)" bounds -1.3 -0.1 -0.8 1.8 1.5 0.8 material rabbit_fur
use fuzz(-0.45, 0.62, 0, 0.62, 0.6, 0.5, 34, 52, 0.08, 0.009, 0, seed)
use fuzz(0.3, 0.7, 0, 0.72, 0.52, 0.42, 34, 52, 0.08, 0.009, 0, seed + 5000)
use fuzz(1.2, 1.1, 0, 0.42, 0.34, 0.3, 20, 34, 0.06, 0.007, 0, seed + 9000)
surface "a = capsule(0.8, 0.58, 0.17, fl_kx, fl_ky, fl_kz, 0.13, 0.09); b = capsule(fl_kx, fl_ky, fl_kz, fl_ax, fl_ay, fl_az, 0.09, 0.07); c = capsule(fl_ax, fl_ay, fl_az, fl_tx, fl_ty, fl_tz, 0.07, 0.06); shape = sm(sm(a, b, 0.05), c, 0.04)" bounds -0.5 -0.1 -0.8 2 1.5 0.8 material rabbit_fur
surface "a = capsule(0.8, 0.58, -0.17, fr_kx, fr_ky, fr_kz, 0.13, 0.09); b = capsule(fr_kx, fr_ky, fr_kz, fr_ax, fr_ay, fr_az, 0.09, 0.07); c = capsule(fr_ax, fr_ay, fr_az, fr_tx, fr_ty, fr_tz, 0.07, 0.06); shape = sm(sm(a, b, 0.05), c, 0.04)" bounds -0.5 -0.1 -0.8 2 1.5 0.8 material rabbit_fur
sphere scale 0.13 0.52 0.035 at 0 0.5 0 rotate z 16 rotate x 14 at 1.08 1.35 0.12 material rabbit_fur
sphere scale 0.13 0.52 0.035 at 0 0.5 0 rotate z 16 rotate x -14 at 1.08 1.35 -0.12 material rabbit_fur
sphere scale 0.07 0.4 0.036 at 0 0.5 0 rotate z 16 rotate x 14 at 1.08 1.355 0.125 material pink_skin
sphere scale 0.07 0.4 0.036 at 0 0.5 0 rotate z 16 rotate x -14 at 1.08 1.355 -0.125 material pink_skin
sphere scale 0.07 at 1.4 1.19 0.2 material dark_eye
sphere scale 0.07 at 1.4 1.19 -0.2 material dark_eye
sphere scale 0.045 at 1.72 1.03 0 material pink_skin
sphere scale 0.22 at -1.12 0.78 0 material rabbit_white_fur
use pom(0.16, 140, seed) at -1.12 0.78 0
use whiskers(1)
use whiskers(-1)
end
end
# the rabbit for an animation: sitting up and moving. The body is turned by `pitch` about the middle of the haunch and the head by `hyaw` (to the side) and
# `hpitch` (nodding, negative is nose down) about the neck, which is a separate surface that overlaps the body's. The hind feet stay on the ground in the room's frame;
# the front paws are put at (flx, fly, flz) and (frx, fry, frz) in the body's own frame, wherever the caller wants them (against the belly, or on the ground).
define rabbit_anim(seed, pitch, hyaw, hpitch, flx, fly, flz, frx, fry, frz)
ik hl hip (-0.45 + 0.05 * cosd(pitch)) (0.62 + 0.05 * sind(pitch)) 0.4 foot 0.12 0.06 0.4 bones 0.45 0.42 0.45 toe 1 0 0 pole 1 0.1 0.3
ik hr hip (-0.45 + 0.05 * cosd(pitch)) (0.62 + 0.05 * sind(pitch)) (-0.4) foot 0.12 0.06 (-0.4) bones 0.45 0.42 0.45 toe 1 0 0 pole 1 0.1 (-0.3)
ik fl hip 0.8 0.58 0.17 foot flx fly flz bones 0.33 0.33 0.14 toe 1 0 0 pole (-1) 0.3 0
ik fr hip 0.8 0.58 (-0.17) foot frx fry frz bones 0.33 0.33 0.14 toe 1 0 0 pole (-1) 0.3 0
surface "a = capsule(-0.45 + 0.05 * cosd(pitch), 0.62 + 0.05 * sind(pitch), 0.4, hl_kx, hl_ky, hl_kz, 0.22, 0.12); b = capsule(hl_kx, hl_ky, hl_kz, hl_ax, hl_ay, hl_az, 0.12, 0.07); c = capsule(hl_ax, hl_ay, hl_az, hl_tx, hl_ty, hl_tz, 0.07, 0.06); shape = sm(sm(a, b, 0.06), c, 0.04)" bounds -1.6 -0.1 -0.8 1.8 2.6 0.8 material rabbit_fur
surface "a = capsule(-0.45 + 0.05 * cosd(pitch), 0.62 + 0.05 * sind(pitch), -0.4, hr_kx, hr_ky, hr_kz, 0.22, 0.12); b = capsule(hr_kx, hr_ky, hr_kz, hr_ax, hr_ay, hr_az, 0.12, 0.07); c = capsule(hr_ax, hr_ay, hr_az, hr_tx, hr_ty, hr_tz, 0.07, 0.06); shape = sm(sm(a, b, 0.06), c, 0.04)" bounds -1.6 -0.1 -0.8 1.8 2.6 0.8 material rabbit_fur
group at 0.45 (-0.62) 0 rotate z pitch at (-0.45) 0.62 0
# the body without its head: haunch, chest and the shoulders' neck
surface "h = ell(-0.45, 0.62, 0, 0.62, 0.6, 0.5); c = ell(0.3, 0.7, 0, 0.72, 0.52, 0.42); n = ell(0.85, 0.95, 0, 0.35, 0.4, 0.3); shape = sm(sm(h, c, 0.25), n, 0.2)" bounds -1.3 -0.1 -0.8 1.4 1.5 0.8 material rabbit_fur
use fuzz(-0.45, 0.62, 0, 0.62, 0.6, 0.5, 34, 52, 0.08, 0.009, 0, seed)
use fuzz(0.3, 0.7, 0, 0.72, 0.52, 0.42, 34, 52, 0.08, 0.009, 0, seed + 5000)
surface "a = capsule(0.8, 0.58, 0.17, fl_kx, fl_ky, fl_kz, 0.13, 0.09); b = capsule(fl_kx, fl_ky, fl_kz, fl_ax, fl_ay, fl_az, 0.09, 0.07); c = capsule(fl_ax, fl_ay, fl_az, fl_tx, fl_ty, fl_tz, 0.07, 0.06); shape = sm(sm(a, b, 0.05), c, 0.04)" bounds -0.5 -0.1 -0.8 2 1.5 0.8 material rabbit_fur
surface "a = capsule(0.8, 0.58, -0.17, fr_kx, fr_ky, fr_kz, 0.13, 0.09); b = capsule(fr_kx, fr_ky, fr_kz, fr_ax, fr_ay, fr_az, 0.09, 0.07); c = capsule(fr_ax, fr_ay, fr_az, fr_tx, fr_ty, fr_tz, 0.07, 0.06); shape = sm(sm(a, b, 0.05), c, 0.04)" bounds -0.5 -0.1 -0.8 2 1.5 0.8 material rabbit_fur
sphere scale 0.22 at -1.12 0.78 0 material rabbit_white_fur
use pom(0.16, 140, seed) at -1.12 0.78 0
# the head, turned about the neck
group at (-0.95) (-0.92) 0 rotate z hpitch rotate y hyaw at 0.95 0.92 0
surface "nk = ell(0.95, 0.98, 0, 0.3, 0.32, 0.28); hd = ell(1.2, 1.1, 0, 0.42, 0.34, 0.3); m = ell(1.52, 1.0, 0, 0.2, 0.17, 0.17); k1 = ell(1.25, 0.95, 0.17, 0.25, 0.22, 0.15); k2 = ell(1.25, 0.95, -0.17, 0.25, 0.22, 0.15); shape = sm(sm(sm(sm(nk, hd, 0.15), m, 0.1), k1, 0.1), k2, 0.1)" bounds 0.5 0.3 -0.6 1.9 1.7 0.6 material rabbit_fur
use fuzz(1.2, 1.1, 0, 0.42, 0.34, 0.3, 20, 34, 0.06, 0.007, 0, seed + 9000)
sphere scale 0.13 0.52 0.035 at 0 0.5 0 rotate z 16 rotate x 14 at 1.08 1.35 0.12 material rabbit_fur
sphere scale 0.13 0.52 0.035 at 0 0.5 0 rotate z 16 rotate x -14 at 1.08 1.35 -0.12 material rabbit_fur
sphere scale 0.07 0.4 0.036 at 0 0.5 0 rotate z 16 rotate x 14 at 1.08 1.355 0.125 material pink_skin
sphere scale 0.07 0.4 0.036 at 0 0.5 0 rotate z 16 rotate x -14 at 1.08 1.355 -0.125 material pink_skin
sphere scale 0.07 at 1.4 1.19 0.2 material dark_eye
sphere scale 0.07 at 1.4 1.19 -0.2 material dark_eye
sphere scale 0.045 at 1.72 1.03 0 material pink_skin
use whiskers(1)
use whiskers(-1)
end
end
end
# ---- the fox ----
# Four legs, each three bones from the shoulder or the hip to the foot: for a front leg an upper arm, a forearm and a paw, for a hind leg a thigh, a shin
# and the long bone of the foot (the hock is where the shin ends, and bends backward). The red of the upper leg is the body's; the stocking, from the elbow
# or the knee down, is black. The body is raised 0.2, the feet are put in the room's own coordinates.
define fox_rig(seed, skel, hlx, hly, hlz, hrx, hry, hrz, flx, fly, flz, frx, fry, frz)
ik hl hip (-0.55) 1.0 0.15 foot hlx hly hlz bones 0.42 0.5 0.3 toe 0.3 (-1) 0 pole 1 0 0.1
ik hr hip (-0.55) 1.0 (-0.15) foot hrx hry hrz bones 0.42 0.5 0.3 toe 0.3 (-1) 0 pole 1 0 (-0.1)
ik fl hip 0.5 1.05 0.15 foot flx fly flz bones 0.38 0.58 0.17 toe 1 0 0 pole (-1) 0.2 0
ik fr hip 0.5 1.05 (-0.15) foot frx fry frz bones 0.38 0.58 0.17 toe 1 0 0 pole (-1) 0.2 0
if skel > 0
use fox_bones()
else
group at 0 0.2 0
# the body, haunch and neck
surface "c = ell(0.3, 0.95, 0, 0.55, 0.42, 0.32); h = ell(-0.4, 0.95, 0, 0.5, 0.4, 0.3); n = ell(0.85, 1.22, 0, 0.33, 0.3, 0.23); shape = sm(sm(h, c, 0.3), n, 0.25)" bounds -1.2 0.2 -0.5 1.4 1.6 0.5 material fox_body_fur
use fuzz(0.3, 0.95, 0, 0.55, 0.42, 0.32, 34, 52, 0.09, 0.009, 3, seed)
use fuzz(-0.4, 0.95, 0, 0.5, 0.4, 0.3, 34, 52, 0.09, 0.009, 3, seed + 5000)
use fuzz(0.85, 1.22, 0, 0.33, 0.3, 0.23, 18, 34, 0.08, 0.008, 3, seed + 9000)
# the head
surface "s = ell(1.35, 1.4, 0, 0.3, 0.26, 0.22); m = ell(1.75, 1.3, 0, 0.3, 0.1, 0.09); k1 = ell(1.3, 1.28, 0.13, 0.22, 0.16, 0.1); k2 = ell(1.3, 1.28, -0.13, 0.22, 0.16, 0.1); shape = sm(sm(sm(s, m, 0.12), k1, 0.1), k2, 0.1)" bounds 0.9 1.0 -0.45 2.2 1.8 0.45 material fox_head_fur
use fuzz(1.35, 1.4, 0, 0.3, 0.26, 0.22, 20, 34, 0.06, 0.007, 3, seed + 13000)
use fuzz(1.3, 1.22, 0.13, 0.2, 0.14, 0.09, 14, 24, 0.12, 0.009, 6, seed + 15000)
use fuzz(1.3, 1.22, -0.13, 0.2, 0.14, 0.09, 14, 24, 0.12, 0.009, 6, seed + 17000)
sphere scale 0.28 0.07 0.08 at 1.74 1.235 0 material fox_white_fur
sphere scale 0.1 0.2 0.16 at 1.15 1.05 0 material fox_white_fur
use fuzz(1.15, 1.05, 0, 0.1, 0.2, 0.16, 14, 24, 0.07, 0.007, 6, seed + 19000)
sphere scale 0.045 at 2.04 1.31 0 material dark_eye
sphere scale 0.045 at 1.58 1.46 0.15 material amber_eye
sphere scale 0.045 at 1.58 1.46 -0.15 material amber_eye
cone -1 0 closed scale 0.12 0.4 0.04 at 0 0.4 0 rotate z 10 rotate x 8 at 1.3 1.58 0.1 material fox_black_fur
cone -1 0 closed scale 0.12 0.4 0.04 at 0 0.4 0 rotate z 10 rotate x -8 at 1.3 1.58 -0.1 material fox_black_fur
cone -1 0 closed scale 0.07 0.3 0.03 at 0 0.3 0 rotate z 10 rotate x 8 at 1.32 1.58 0.128 material fox_white_fur
cone -1 0 closed scale 0.07 0.3 0.03 at 0 0.3 0 rotate z 10 rotate x -8 at 1.32 1.58 -0.128 material fox_white_fur
# the brush
surface "a = ell(-1.2, 1.0, 0, 0.35, 0.2, 0.2); b = ell(-1.65, 0.88, 0, 0.4, 0.27, 0.27); c = ell(-2.1, 0.75, 0, 0.35, 0.22, 0.22); shape = sm(sm(a, b, 0.2), c, 0.2)" bounds -2.6 0.3 -0.6 -0.8 1.3 0.6 material fox_tail_fur
use fuzz(-1.2, 1.0, 0, 0.35, 0.2, 0.2, 18, 30, 0.12, 0.011, 3, seed + 21000)
use fuzz(-1.65, 0.88, 0, 0.4, 0.27, 0.27, 24, 36, 0.14, 0.012, 3, seed + 23000)
use fuzz(-2.1, 0.75, 0, 0.35, 0.22, 0.22, 20, 32, 0.12, 0.011, 3, seed + 25000)
sphere scale 0.3 0.21 0.21 at -2.45 0.7 0 material fox_white_fur
use fuzz(-2.45, 0.7, 0, 0.3, 0.21, 0.21, 18, 30, 0.13, 0.011, 6, seed + 27000)
end
# the upper legs, red, and the stockings, black: a thigh or an upper arm, then from the knee or elbow down
surface "a = capsule(-0.55, 1.0, 0.15, hl_kx, hl_ky, hl_kz, 0.17, 0.1); b = capsule(hl_kx, hl_ky, hl_kz, hl_ax, hl_ay, hl_az, 0.1, 0.06); shape = sm(a, b, 0.05)" bounds -1.4 -0.1 -0.8 1.8 1.6 0.8 material fox_red_leg_fur
surface "a = capsule(hl_ax, hl_ay, hl_az, hl_tx, hl_ty, hl_tz, 0.06, 0.055)" bounds -1.4 -0.1 -0.8 1.8 1.6 0.8 material fox_black_fur
surface "a = capsule(-0.55, 1.0, -0.15, hr_kx, hr_ky, hr_kz, 0.17, 0.1); b = capsule(hr_kx, hr_ky, hr_kz, hr_ax, hr_ay, hr_az, 0.1, 0.06); shape = sm(a, b, 0.05)" bounds -1.4 -0.1 -0.8 1.8 1.6 0.8 material fox_red_leg_fur
surface "a = capsule(hr_ax, hr_ay, hr_az, hr_tx, hr_ty, hr_tz, 0.06, 0.055)" bounds -1.4 -0.1 -0.8 1.8 1.6 0.8 material fox_black_fur
surface "a = capsule(0.5, 1.05, 0.15, fl_kx, fl_ky, fl_kz, 0.13, 0.08); shape = a" bounds -0.5 -0.1 -0.8 2 1.6 0.8 material fox_red_leg_fur
surface "a = capsule(fl_kx, fl_ky, fl_kz, fl_ax, fl_ay, fl_az, 0.08, 0.055); b = capsule(fl_ax, fl_ay, fl_az, fl_tx, fl_ty, fl_tz, 0.055, 0.05); shape = sm(a, b, 0.03)" bounds -0.5 -0.1 -0.8 2 1.6 0.8 material fox_black_fur
surface "a = capsule(0.5, 1.05, -0.15, fr_kx, fr_ky, fr_kz, 0.13, 0.08); shape = a" bounds -0.5 -0.1 -0.8 2 1.6 0.8 material fox_red_leg_fur
surface "a = capsule(fr_kx, fr_ky, fr_kz, fr_ax, fr_ay, fr_az, 0.08, 0.055); b = capsule(fr_ax, fr_ay, fr_az, fr_tx, fr_ty, fr_tz, 0.055, 0.05); shape = sm(a, b, 0.03)" bounds -0.5 -0.1 -0.8 2 1.6 0.8 material fox_black_fur
end
end
# standing: four feet on the ground
define fox_stand(seed, skel)
use fox_rig(seed, skel, (-0.55), 0.04, 0.15, (-0.55), 0.04, (-0.15), 0.68, 0.04, 0.15, 0.68, 0.04, (-0.15))
end
# stepping: the near front paw lifted and reaching forward, the far hind foot lifted
define fox_step(seed, skel)
use fox_rig(seed, skel, (-0.45), 0.04, 0.15, (-0.2), 0.2, (-0.15), 0.95, 0.3, 0.15, 0.6, 0.04, (-0.15))
end
# ---- the skeletons, to see what was solved ----
# bones as capsules and joints as balls, from the same ik statements the animals use
material bone_m
color 0.93 0.9 0.8
ambient 0.3 diffuse 0.8 specular 0.15 shininess 30
end
material joint_m
color 0.85 0.15 0.15
ambient 0.3 diffuse 0.8 specular 0.4 shininess 60
end
define bone(ax, ay, az, bx, by, bz, r)
surface "shape = capsule(ax, ay, az, bx, by, bz, r, r)" bounds -3.5 -0.5 -1.5 3.5 3 1.5 material bone_m
end
define joint(jx, jy, jz)
sphere scale 0.05 at jx jy jz material joint_m
end
define rabbit_bones()
# the spine: hips, shoulders, the head
use bone(-0.4, 0.62, 0, 0.8, 0.58, 0, 0.05)
use bone(0.8, 0.58, 0, 1.2, 1.1, 0, 0.05)
use bone(-0.4, 0.62, 0.4, -0.4, 0.62, -0.4, 0.04)
use bone(0.8, 0.58, 0.17, 0.8, 0.58, -0.17, 0.04)
use joint(-0.4, 0.62, 0.4)
use joint(-0.4, 0.62, -0.4)
use joint(0.8, 0.58, 0.17)
use joint(0.8, 0.58, -0.17)
use joint(1.2, 1.1, 0)
use bone(-0.4, 0.62, 0.4, hl_kx, hl_ky, hl_kz, 0.035)
use bone(hl_kx, hl_ky, hl_kz, hl_ax, hl_ay, hl_az, 0.035)
use bone(hl_ax, hl_ay, hl_az, hl_tx, hl_ty, hl_tz, 0.035)
use joint(hl_kx, hl_ky, hl_kz)
use joint(hl_ax, hl_ay, hl_az)
use joint(hl_tx, hl_ty, hl_tz)
use bone(-0.4, 0.62, -0.4, hr_kx, hr_ky, hr_kz, 0.035)
use bone(hr_kx, hr_ky, hr_kz, hr_ax, hr_ay, hr_az, 0.035)
use bone(hr_ax, hr_ay, hr_az, hr_tx, hr_ty, hr_tz, 0.035)
use joint(hr_kx, hr_ky, hr_kz)
use joint(hr_ax, hr_ay, hr_az)
use joint(hr_tx, hr_ty, hr_tz)
use bone(0.8, 0.58, 0.17, fl_kx, fl_ky, fl_kz, 0.035)
use bone(fl_kx, fl_ky, fl_kz, fl_ax, fl_ay, fl_az, 0.035)
use bone(fl_ax, fl_ay, fl_az, fl_tx, fl_ty, fl_tz, 0.035)
use joint(fl_kx, fl_ky, fl_kz)
use joint(fl_ax, fl_ay, fl_az)
use joint(fl_tx, fl_ty, fl_tz)
use bone(0.8, 0.58, -0.17, fr_kx, fr_ky, fr_kz, 0.035)
use bone(fr_kx, fr_ky, fr_kz, fr_ax, fr_ay, fr_az, 0.035)
use bone(fr_ax, fr_ay, fr_az, fr_tx, fr_ty, fr_tz, 0.035)
use joint(fr_kx, fr_ky, fr_kz)
use joint(fr_ax, fr_ay, fr_az)
use joint(fr_tx, fr_ty, fr_tz)
end
define fox_bones()
use bone(-0.55, 1.0, 0, 0.5, 1.05, 0, 0.05)
use bone(0.5, 1.05, 0, 1.35, 1.6, 0, 0.05)
use bone(-0.55, 1.0, 0, -2.4, 0.95, 0, 0.04)
use bone(-0.55, 1.0, 0.15, -0.55, 1.0, -0.15, 0.04)
use bone(0.5, 1.05, 0.15, 0.5, 1.05, -0.15, 0.04)
use joint(-0.55, 1.0, 0.15)
use joint(-0.55, 1.0, -0.15)
use joint(0.5, 1.05, 0.15)
use joint(0.5, 1.05, -0.15)
use joint(1.35, 1.6, 0)
use bone(-0.55, 1.0, 0.15, hl_kx, hl_ky, hl_kz, 0.035)
use bone(hl_kx, hl_ky, hl_kz, hl_ax, hl_ay, hl_az, 0.035)
use bone(hl_ax, hl_ay, hl_az, hl_tx, hl_ty, hl_tz, 0.035)
use joint(hl_kx, hl_ky, hl_kz)
use joint(hl_ax, hl_ay, hl_az)
use joint(hl_tx, hl_ty, hl_tz)
use bone(-0.55, 1.0, -0.15, hr_kx, hr_ky, hr_kz, 0.035)
use bone(hr_kx, hr_ky, hr_kz, hr_ax, hr_ay, hr_az, 0.035)
use bone(hr_ax, hr_ay, hr_az, hr_tx, hr_ty, hr_tz, 0.035)
use joint(hr_kx, hr_ky, hr_kz)
use joint(hr_ax, hr_ay, hr_az)
use joint(hr_tx, hr_ty, hr_tz)
use bone(0.5, 1.05, 0.15, fl_kx, fl_ky, fl_kz, 0.035)
use bone(fl_kx, fl_ky, fl_kz, fl_ax, fl_ay, fl_az, 0.035)
use bone(fl_ax, fl_ay, fl_az, fl_tx, fl_ty, fl_tz, 0.035)
use joint(fl_kx, fl_ky, fl_kz)
use joint(fl_ax, fl_ay, fl_az)
use joint(fl_tx, fl_ty, fl_tz)
use bone(0.5, 1.05, -0.15, fr_kx, fr_ky, fr_kz, 0.035)
use bone(fr_kx, fr_ky, fr_kz, fr_ax, fr_ay, fr_az, 0.035)
use bone(fr_ax, fr_ay, fr_az, fr_tx, fr_ty, fr_tz, 0.035)
use joint(fr_kx, fr_ky, fr_kz)
use joint(fr_ax, fr_ay, fr_az)
use joint(fr_tx, fr_ty, fr_tz)
end
The pictures were made by tools/ch39_pictures.sh (about two hours); the build of this page copies them. Sitting, stretching, hopping, each as fur
and as the bones that were solved:
![]() | ![]() |
![]() | ![]() |
![]() | ![]() |
and the fox standing and stepping:
![]() | ![]() |
![]() | ![]() |
Scenarios and oracles
What any such limb must satisfy is worked out in the test, in plain arithmetic on lists that shares no code with the solver:
- The bones keep their lengths,
|knee - hip| = l1and|foot - knee| = l2, for a grid of 245 targets near and far, to 1e-12. - A foot that can be reached is reached (83 of the targets), and the knee is on the pole's side of the line and in the plane of hip, foot and pole.
- A foot too far (161 targets) leaves the limb straight and pointing at it, and a foot too near folds it: the tip stops at
|l1 - l2|. A foot at the hip itself, and a pole along the line to the foot, still give a limb. - Mirror the hip, the foot and the pole in a plane and the knee is mirrored; the same target gives the same limb; a foot that moves 0.006 moves the knee less than 0.05 all the way through the limb's range and out of it.
- The angle at the knee is the law of cosines' one, to 1e-9 over 30 reaches.
- Three bones keep their lengths, the foot bone points along the direction asked for, and the tip is the target when it can be reached.
- The language:
ikbinds the names (checked against the solver), says whether the foot was reached, and refuses a limb with no pole, one bone, a negative length, no name or an unknown word;acos,asinandatan2dtake the quadrant and refuse what is out of range. - The animals: a rigged rabbit is its body and four limbs (5 smooth surfaces); a ray along the ground meets the toe of a hind foot one radius beyond the place it was put, sitting (x = 0.08) and stretched (x = -0.55); the rabbit's skeleton is 16 bones and 17 joints; the fox is 11 smooth surfaces.
What it is not
The legs follow the feet, but the body does not follow the legs: a rabbit with its hind feet lifted does not lean forward, and nothing keeps its weight over its feet. Joints have no limits other than the reach, so a knee will bend where a knee cannot, if asked. Nothing stops a foot passing through the ground or the other leg. And a pose is one picture: there is no motion, only a place for each foot, though a run of pictures with the feet moved a little between them would be an animation, which is what a skeleton is for.
How it is checked
> v2_interp.exe tests/run.patlang --node scene/rig --depth 2
[ ok ] Skeletons and poses
[ ok ] Inverse trigonometric functions of the language
[ ok ] Acos, asin: acos(1/2) = pi/3 and asin(1/2) = pi/6
[ ok ] Two bones
[ ok ] Both bones keep their lengths for all
[ ok ] A target nearer than |l1 - l2| folds the limb back on itself: the tip is at distance 0.4
[ ok ] Mirror the hip, the target and the pole in x = 0 and the knee is mirrored (worst ...
[ ok ] A foot that moves 0.006 moves the knee less than 0.05, through the whole range of the ...
[ ok ] The angle at the knee is the law of cosines' for 30 reaches from 0.15 to 0.875 (worst ...
[ ok ] Three bones
[ ok ] Three bones (thigh, shin, foot) keep their lengths for
[ ok ] The ik statement
[ ok ] Ik binds name_kx, name_ky, name_kz to the knee the solver finds
[ ok ] The rigged animals
[ ok ] A rigged rabbit is its body and four limbs of capsules: 5 smooth surfaces, 8 spheres ...
checks: 9 passed, 0 failed, 0 blocked, 0 skipped, 0 not run
ALL PASSED
> v2_interp.exe tests/run.patlang --node scene/fur --depth 2
[ ok ] Fur
[ ok ] The fur pictures
[ ok ] The six fur pictures are all 1024 x 1024
[ ok ] Reading pictures
[ ok ] A binary PPM read a row at a time is the same canvas as the whole file parsed at once ...
[ ok ] Animals
[ ok ] A rabbit is 1 smooth body, 8 spheres (4 ear, 2 eye, nose, tail), and 4 362 cones: 4 216 ...
[ ok ] Each whisker leaves the muzzle sideways (further out than along, on its own side) and ...
checks: 4 passed, 0 failed, 0 blocked, 0 skipped, 0 not run
ALL PASSED
Graduate Attributes
Directly developed
- Digitally Fluent: Readers implement inverse kinematics to solve limb positions from foot coordinates using geometric functions.
- Subject Specialist: Readers construct complex animal models by layering implicit functions, procedural textures, and skeletal rigs.
Modelled on this page
- Critical Thinker: Limitations of the rendering technique are stated explicitly, noting that fur does not move or cast shadows on itself.
- Researcher: The solver is validated against independent arithmetic tests that share no code with the main implementation.
- Reflective: The text examines why a bird serves as a better test of the scene language than a tree due to visual recognisability.
University of Reading Graduate Attributes framework.









