Last updated: 2026-11-26
10. Trees, plants and a garden
For new readers
The meadow of the film is ground, grass, flowers and trees. This page builds them: a tree from a recursive branching rule, a garden with a pond, then plants and species of tree, all written in the scene language and made of the shapes of part IV and the surfaces of part V.
A Tree
A tree is a rule used on itself: a branch is a limb, and at the tip of the limb are smaller
branches; at the last of them are leaves. The scene language of A language for scenes and models can say that, because a
definition may use itself, and if stops it.cf. scene language: recursion with guards
define branch(len, r, n, s)
use limb(len, r, r * 0.72)
if n > 0
for k in 0 to 2
let t = s * 7 + k * 3 + 1
use branch(len * (0.62 + 0.18 * rand(t)), r * 0.72, n - 1, t) rotate z (18 + 30 * rand(t + 1)) rotate y (120 * k + 70 * rand(t + 2)) at 0 (len * (0.82 + 0.18 * rand(t + 3))) 0
end
else
use leaves(0.5 + 0.1 * rand(s), s) at 0 len 0
end
end
Three branches leave the tip of each limb. Each is shorter than its parent by a factor between 0.62 and 0.8 and thinner by
0.72; each is turned about the limb by 120 degrees apart from its two sisters, with some more, and tilted
away from the limb by 18 to 48 degrees. The some is rand: the number rand(n) is in [0, 1), is the same every time for the
same n, and varies as if it were random from one n to the next, so each branch gets its own t, built from its parent's, and a tree is
different from another by its seed alone and the same as itself every time it is made.
The pieces
A limb is a frustum of a cone, wide at the bottom and narrow at the top. A cone has radius |y|, so the part of it between
y = r1 and y = r0 has radius r1 at one end and r0 at the other. Turned upside down (a scale by a negative number in y),
stretched so that it is len long, and moved so that its wide end is on the origin, that is a limb:
define limb(len, r0, r1)
cone r1 r0 closed scale 1 (-len / (r0 - r1)) 1 at 0 (r0 * len / (r0 - r1)) 0 material bark
end
With s = len / (r0 โ r1), the point at height y in the cone ends at r0 s โ s y: the end at y = r0 is at 0, and the end at y = r1 is at s (r0 โ r1) = len.
Leaves are three balls of one of three greens round a point, their sizes and places from rand again; the choice of green is an
if on a rand, with a second if inside its else.
The place of a branch is a modifier list, applied in the order written: rotate z tilts it, rotate y turns it about the limb it grows from,
at 0 len 0 puts its foot on the tip of that limb. A branch's own space is its own limb standing on the origin, and everything below it
(its branches, its leaves) is in that space, so each level's turn and tilt multiply down from the trunk. Nothing here is a transformation of a tree: it is a
list of transformations, one for each branch.
What was added to the language
if a < b โฆ else โฆ end (the six comparisons), rand(n), param name = value, and two guards. A definition that uses itself without stopping is
caught when 64 uses are open at once, and a scene that makes more than 100 000 shapes is refused, each with a message that names the definition.
param is let with a value that can come from outside, so that depth and seed of the tree can be changed on the command line without touching the
file: tools/render_scene.sh scenes/tree.scene out/tree.png 60 --set seed=11 --set depth=4.
Scenarios and oracles
The tests are those of A language for scenes and models (they belong to the language, which is where these were added):
- A definition that uses itself, stopped by an
if:chain(4)is a sphere andchain(3)and so on, 4 deep; one that never stops is reported. - A tree by such a definition has 40 branches at depth 3, and each is where the same tree built by library calls puts it: the 40 matrices of the two are compared, each the product of the turns, tilts and moves from the trunk down to it.
randis what the table says, is the same twice, is in [0, 1) on 400 values and has a mean near a half.paramis its default, takes a value from outside, and is not affected by values for other names.
The picture
scenes/tree.scene, depth 5 with seed 3: 364 branches and 243 clusters of leaves, about 1 100 shapes. It takes about 22 seconds to read, which
every one of the processes that render the bands does, and about 8 minutes to draw on 20 cores at 400 ร 300 with adaptive antialiasing.
The scene file includes the tree's parts (its materials and the definitions of the limb, the leaves and the branch), which are in a file of their own,
scenes/parts/tree_parts.scene, so that another scene can use the same tree (Trees, plants and a garden's garden does):
# The parts of a tree, to be included: its materials and the definitions that make one.
# include "parts/tree_parts.scene"
# use branch(3.2, 0.3, 5, 3) at 0 0 0
# branch(len, r, n, s): a limb len long and r wide, and, if n > 0, three branches at its tip, or leaves if n = 0.
# n is the depth; s is a seed that makes one tree unlike another.
material bark
color 0.42 0.3 0.2
ambient 0.12 diffuse 0.8 specular 0.05 shininess 10
end
material leaf_a
color 0.25 0.6 0.18
ambient 0.15 diffuse 0.75 specular 0.1 shininess 20
end
material leaf_b
color 0.38 0.7 0.2
ambient 0.15 diffuse 0.75 specular 0.1 shininess 20
end
material leaf_c
color 0.55 0.72 0.22
ambient 0.15 diffuse 0.75 specular 0.1 shininess 20
end
# a limb: a frustum standing on the origin, len long, r0 wide at the bottom and r1 at the top.
# (A cone has radius |y|; this is the part of one between y = r1 and y = r0, turned upside down and stretched.)
define limb(len, r0, r1)
cone r1 r0 closed scale 1 (-len / (r0 - r1)) 1 at 0 (r0 * len / (r0 - r1)) 0 material bark
end
# a few leaves round a point, three balls of three greens
define leaves(size, s)
for j in 0 to 2
if rand(s + j) < 0.34
sphere scale (size * (0.55 + 0.4 * rand(s + j + 10))) at ((rand(s + j + 20) - 0.5) * size) ((rand(s + j + 30) - 0.3) * size) ((rand(s + j + 40) - 0.5) * size) material leaf_a
else
if rand(s + j) < 0.67
sphere scale (size * (0.55 + 0.4 * rand(s + j + 10))) at ((rand(s + j + 20) - 0.5) * size) ((rand(s + j + 30) - 0.3) * size) ((rand(s + j + 40) - 0.5) * size) material leaf_b
else
sphere scale (size * (0.55 + 0.4 * rand(s + j + 10))) at ((rand(s + j + 20) - 0.5) * size) ((rand(s + j + 30) - 0.3) * size) ((rand(s + j + 40) - 0.5) * size) material leaf_c
end
end
end
end
# a branch: its limb, and three branches at its tip (or, at the end, leaves)
define branch(len, r, n, s)
use limb(len, r, r * 0.72)
if n > 0
for k in 0 to 2
let t = s * 7 + k * 3 + 1
use branch(len * (0.62 + 0.18 * rand(t)), r * 0.72, n - 1, t) rotate z (18 + 30 * rand(t + 1)) rotate y (120 * k + 70 * rand(t + 2)) at 0 (len * (0.82 + 0.18 * rand(t + 3))) 0
end
else
use leaves(0.5 + 0.1 * rand(s), s) at 0 len 0
end
if n == 1
use leaves(0.45, s + 5) at 0 (len * 0.6) 0
end
end
and the scene itself:
# A tree, made by a definition that uses itself (see parts/tree_parts.scene). Each branch is a limb, and
# at its tip three smaller branches, turned about the limb and tilted away from it, by amounts that vary
# from branch to branch by rand (the same every time, so the tree is the same every time); the last
# branches carry leaves. Change depth or seed, here or with --set, and it is another tree.
param w = 400
param h = 300
size w h
camera from 0 5.5 -17 to 0 4.6 0 fov 55
light point at -12 18 -14
param aa = 1
if aa > 0
antialias adaptive 1 0.15
end
param depth = 5
param seed = 3
include "parts/tree_parts.scene"
material grass
color 1 1 1
ambient 0.2 diffuse 0.85 specular 0
pattern checkers 0.45 0.65 0.35 0.38 0.58 0.3 scale 1.5
end
material sky
color 0.6 0.78 0.95
ambient 0.95 diffuse 0 specular 0
end
plane material grass
# the sky: a wall a long way behind
plane rotate x 90 at 0 0 60 material sky
use branch(3.2, 0.3, depth, seed)
> tools/render_scene.sh scenes/tree.scene out/tree.png 60
progress: the port is written to D:/Projects_Organized/raytrace/out/tree.png.progress; ask with v2_interp.exe tools/render_status.patlang --file D:/Projects_Organized/raytrace/out/tree.png.progress
rendered 400x300 in 60 bands by threads in 3352155 ms
rendered by 18 threads in 3472 s wall clock
Another seed and a smaller depth, from the same file:
> tools/render_scene.sh scenes/tree.scene out/tree_b.png 60 --set seed=11 --set depth=4
progress: the port is written to D:/Projects_Organized/raytrace/out/tree_b.png.progress; ask with v2_interp.exe tools/render_status.patlang --file D:/Projects_Organized/raytrace/out/tree_b.png.progress
rendered 400x300 in 60 bands by threads in 1513571 ms
rendered by 18 threads in 1562 s wall clock
Checking it independently
As in A language for scenes and models, what the independent tracer can check is the picture: the exporter sends the world the interpreter built, a thousand shapes of cones and spheres with their transformations, and the checker renders it with its own code.
The first run, on the full picture with its adaptive antialiasing, found 13 of 475 pixels different, all at the trunk and the lowest limbs. The cause was in the
exporter and the checker, not the tree: the exporter wrote the limits of a cylinder (its lowest and highest y, and whether it is closed) and not those of a cone,
so the checker drew every limb as a double cone of unlimited length. Both now handle cones. The check is made on a small picture without antialiasing
(--set w=200 --set h=150 --set aa=0, one ray a pixel, so no choice of the adaptive sampler can differ between the two renderers) with the same scene file:
> tools/render_scene.sh scenes/tree.scene out/tree_check.png 30 --set w=200 --set h=150 --set aa=0
progress: the port is written to D:/Projects_Organized/raytrace/out/tree_check.png.progress; ask with v2_interp.exe tools/render_status.patlang --file D:/Projects_Organized/raytrace/out/tree_check.png.progress
rendered 200x150 in 30 bands by threads in 338139 ms
rendered by 18 threads in 441 s wall clock
> v2_interp.exe tools/export_scene.patlang --scene file --file scenes/tree.scene --set w=200 --set h=150 --set aa=0 --out out/tree_check.txt
wrote out/tree_check.txt (1338 shapes)
> powershell.exe -NoProfile -File tools/verify_recursive.ps1 out/tree_check.png -SceneFile out/tree_check.txt -Stride 4
decoded by .NET: 200x150; pixels differing from the independent recursive tracer by more than 1 level: 0 (max difference 0); stride 4 in each direction, 1900 pixels checked
Negative control: the same picture against the garden of A language for scenes and models.
> powershell.exe -NoProfile -File tools/verify_recursive.ps1 out/tree_check.png -SceneFile out/garden_scene.txt -Stride 4
decoded by .NET: 200x150; pixels differing from the independent recursive tracer by more than 1 level: 1900 (max difference 230); stride 4 in each direction, 1900 pixels checked
A Garden with a Pond
The scene language of A language for scenes and models and Trees, plants and a garden can make shapes, loops, definitions and trees. A garden wants three things more: pictures on its surfaces (the grass), water, and a way to keep the parts of a scene in files of their own. This page adds those to the language and uses them.
Pictures on materials
A material block takes a texture line and a bump line, each naming a PPM picture (relative to the scene file that names it) and
a mapping, the machinery of Pictures on surfaces: texture and cube maps and Bump and normal maps:
material grass
color 1 1 1
ambient 0.34 diffuse 0.85 specular 0
texture ../textures/grass.ppm planar scale 0.03
bump normal ../textures/grass_normal.ppm planar strength 1.2 scale 0.03
end
texture picture mapping [modifiers] makes the picture the colour, with spherical, planar or cylindrical mapping; bump normal|height picture mapping [strength s] [modifiers] tilts the surface normal by it. The modifiers (at, scale, rotate) move the picture on the surface, in the
order written, as they move a pattern. scale 0.03 on the ground below makes one tile of the picture 1.5 across on a slab 200 wide, because the pattern lives in the
slab's own coordinates, where the slab is 2 across.
Files that include files
include "parts/tree_parts.scene" runs another scene file here: its materials and definitions are in scope after it, and anything it makes
is in the scene. The name is relative to the file that names it, so a file that includes another can be anywhere. A file that includes itself is caught at 16
deep; an error inside an included file says which file, outermost first. This is how the tree of Trees, plants and a garden, its materials and its definitions, is shared by two scenes.
Water
Water is a surface of a function, a solid of one function and not a CSG of simpler solids. A pond of water is a cylinder of radius 2.9 under a rippled surface a little below the rim of the pit, with a bed at the bottom:
surface "max(max(sqrt(x^2 + z^2) - 2.9, y + 0.06 - 0.025 * sin(7x + 3 * sin(2z)) * sin(6z + 1.5)), -1.08 - y)" bounds -3.1 -1.2 -3.1 3.1 0.2 3.1 material water
The max of three is the intersection: inside the cylinder, below the ripples, above the bed. The water material is transparent (0.7), reflective (0.45), with the index of
refraction of water, 1.33, and Mirrors and glass's rays do the rest: the sky and the tree reflected in the ripples, the bed and the stones seen through it, bent.
Why one function and not intersection of a cylinder and a half-space? A function surface is found by its roots, and a half-space cut off by a box
has no root where the box cuts it: a ray that comes in from the side meets the water only where it crosses the ripples, so inside the box it
looks like it is already inside, and the CSG gets the wrong answer. (The test of this page that does it as CSG failed for that reason.) The pond as one function has a root
on its wall, so a ray from the side enters it there.roots are where the function crosses zero
The ground, with a pit
The ground is a slab, the top of which is the grass at y = 0, with a cylinder taken out of it for the pit:
difference
cube scale 100 3 100 at 0 -3 0 material grass
cylinder -1 1 closed scale 3 1 3 material mud
end
Each shape of the difference keeps its own material, so the pit's wall and floor are mud and the slab is grass, picture and bumps. The water sits in the pit with a hand's breadth to spare: it does not touch the rim, and its bottom is below the pit's floor, so there is no surface that lies exactly in another's (Triangles and meshes from files's lesson).
Everything else
- Stones round the rim: a loop of 28, each squashed, turned and sized by
rand. - The bench: a definition. The seat is a loop of five slats, the back a loop of three leaning slats, the legs and posts a loop of two ends. The wood is a stripes pattern.
- The tree of Trees, plants and a garden, by
use branch(3.0, 0.28, depth, seed) at 4.5 0 5.5, at depth 4. - Grass: tufts of three blades on a loose grid of 29 ร 29, each blade a thin cone with its tip up, its height, lean and turn from
rand; a tuft is skipped byifwhere it would be in the pond or its stones (xยฒ + zยฒ > 14.5), under the tree, or under the bench. The blades are agroup, a single shape with a bounding-volume hierarchy of Groups and trees of boxes, so a ray does not test them all.
# A garden with a pond, a tree, a wooden bench and grass.
# tools/render_scene.sh scenes/pond_garden.scene out/pond_garden.png 60
# Change the tree with --set depth=4 --set seed=7, the picture with --set w=200 --set h=120, and add mist with --set mist=0.05.
param w = 400
param h = 240
size w h
camera from -8.5 3.4 -13 to 1 2.2 1 fov 56
light point at -14 24 -12
param aa = 1
if aa > 0
antialias adaptive 1 0.15
end
# morning mist: --set mist=0.05 makes the air thicker toward the ground (density 0.05 at the ground, thinning with height)
param mist = 0
if mist > 0
fog density mist falloff 0.45 color 0.84 0.89 0.95
end
# a pair of pictures for two eyes, side by side: --set eyes=0.5 (the eyes that far apart; --set eyes=0.5 with a smaller w and h is quicker)
param eyes = 0
if eyes > 0
stereo separation eyes gap 8
end
param depth = 4
param seed = 5
include "parts/tree_parts.scene"
# ---- materials ----
material grass
color 1 1 1
ambient 0.34 diffuse 0.85 specular 0
texture ../textures/grass.ppm planar scale 0.03
bump normal ../textures/grass_normal.ppm planar strength 1.2 scale 0.03
end
material mud
color 0.42 0.33 0.22
ambient 0.3 diffuse 0.8 specular 0
end
material stone
color 0.62 0.6 0.56
ambient 0.15 diffuse 0.8 specular 0.1 shininess 30
end
material water
color 0.2 0.45 0.5
ambient 0.1 diffuse 0.25 specular 0.9 shininess 300
reflective 0.45 transparency 0.7 ior 1.33
end
material wood
color 1 1 1
ambient 0.18 diffuse 0.8 specular 0.15 shininess 40
pattern stripes 0.52 0.34 0.18 0.43 0.27 0.14 scale 0.08
end
material blade
color 0.3 0.58 0.17
ambient 0.25 diffuse 0.75 specular 0.05 shininess 10
end
material sky
color 0.58 0.76 0.95
ambient 0.95 diffuse 0 specular 0
end
# ---- the ground, with a pit for the pond, and the sky ----
# a slab whose top is the grass at y = 0, with a round pit 1 deep: the pit's wall and floor are mud
difference
cube scale 100 3 100 at 0 -3 0 material grass
cylinder -1 1 closed scale 3 1 3 material mud
end
plane rotate x 90 at 0 0 120 material sky
# ---- the water: one function, a cylinder of radius 2.9 under a rippled surface a little below the rim ----
surface "max(max(sqrt(x^2 + z^2) - 2.9, y + 0.06 - 0.025 * sin(7x + 3 * sin(2z)) * sin(6z + 1.5)), -1.08 - y)" bounds -3.1 -1.2 -3.1 3.1 0.2 3.1 material water
# ---- stones round the rim ----
for k in 0 to 27
sphere scale (0.28 + 0.12 * rand(k)) 0.17 (0.26 + 0.1 * rand(k + 50)) rotate y (rand(k + 9) * 180) at (3.2 * cosd(k * 360 / 28)) 0.05 (3.2 * sind(k * 360 / 28)) material stone
end
# ---- the tree ----
use branch(3.0, 0.28, depth, seed) at 4.5 0 5.5
# ---- the bench, facing the pond ----
define bench()
# the seat: five slats
for i in 0 to 4
cube scale 0.9 0.025 0.065 at 0 0.45 (-0.26 + 0.13 * i) material wood
end
# the back: three slats, leaning back a little
for j in 0 to 2
cube scale 0.9 0.04 0.018 rotate x 12 at 0 (0.72 + 0.14 * j) 0.34 material wood
end
# a leg at each end, front and back, and the back posts
for e in 0 to 1
cube scale 0.04 0.225 0.3 at (-0.82 + 1.64 * e) 0.225 0 material wood
cube scale 0.04 0.45 0.03 at (-0.82 + 1.64 * e) 0.45 0.34 material wood
end
end
use bench() rotate y -105 at -4.3 0 -1.2
# ---- grass: tufts of three blades on a loose grid, none in the pond, the stones, the tree or the bench ----
group
for i in -14 to 14
for j in -14 to 14
let px = i * 1.3 + 0.9 * rand(i * 31 + j * 7 + 1)
let pz = j * 1.3 + 0.9 * rand(i * 17 + j * 13 + 2)
if ((px * px) + (pz * pz)) > 14.5
if (((px - 4.5) * (px - 4.5)) + ((pz - 5.5) * (pz - 5.5))) > 1.4
if (((px + 4.3) * (px + 4.3)) + ((pz + 1.2) * (pz + 1.2))) > 1.6
for b in 0 to 2
let t = i * 101 + j * 37 + b * 11
let hgt = 0.3 + 0.25 * rand(t)
cone -1 0 closed scale 0.03 hgt 0.03 rotate z ((rand(t + 1) - 0.5) * 36) rotate y (rand(t + 2) * 360) at (px + 0.25 * (rand(t + 3) - 0.5)) hgt (pz + 0.25 * (rand(t + 4) - 0.5)) material blade
end
end
end
end
end
end
end
Scenarios and oracles
- Texture and bump against the library: the pattern is a
texture_mapof the smoothed picture with the mapping and the transformation written, its colour at 20 points is the one built by calls; abump normalhas its mapping, strength and transformation,bump heighthas strength 1 unless one is given; a picture that is not there, a mapping or a bump that is not one, are reported with their line. - Paths: a scene file in
tests/datathat namestiny.ppmreads the picture next to it. - The pond against its formulas: with flat water the top is at
y = 0and the bed aty = -1, a ray fromy = 5hits them att = 5and6; with ripples the top is where0.05 sin(5x) sin(4z)says, to 10โปโต; a ray outside the circle misses; a ray along the water enters and leaves through the wall, att = 2and8. - A scatter that skips a place: an 11 ร 11 grid with the middle left out by an
ifhas exactly as many spheres as the test counts (92 of 121); a ring of 24 stones is 15 degrees apart at radius 3.3. include: another file's sphere is in the scene, its material and definition used by name, a value given from outside reaches theparamof the including file, a file that includes itself is caught, a missing file is named, an error in an included file names the file and the line.
The language's earlier tests (the language grew include, texture and bump) still pass:
The picture
About 2 000 blades of grass, 28 stones, a tree of 121 branches and its leaves, a bench of 12 boards, a pit and a pond. A scene of that size takes about half a minute to read (every band of the picture does it) and a good while to draw.
> tools/render_scene.sh scenes/pond_garden.scene out/pond_garden.png 60
progress: the port is written to D:/Projects_Organized/raytrace/out/pond_garden.png.progress; ask with v2_interp.exe tools/render_status.patlang --file D:/Projects_Organized/raytrace/out/pond_garden.png.progress
rendered 400x240 in 60 bands by threads in 3423420 ms
rendered by 18 threads in 3637 s wall clock
Checking it independently
The exporter sends the world the interpreter built (the slab with its pit, the pictures as U and B lines, the water as its text, the blades as cones) and the
checker renders it with its own code, its own picture reader, texture lookup and bump frame, and finds the water's roots by sampling, nothing like the interval solver.
Two thousand shapes make a slow checker, so the check is made on a small picture without antialiasing (--set w=200 --set h=120 --set aa=0), every fourth pixel in each direction.
(Its first run, on the full adaptive picture, showed 42 of 375 pixels different, for the reason given in Trees, plants and a garden: cones were exported without their limits, and
the blades are cones.)
> tools/render_scene.sh scenes/pond_garden.scene out/pond_check.png 30 --set w=200 --set h=120 --set aa=0
progress: the port is written to D:/Projects_Organized/raytrace/out/pond_check.png.progress; ask with v2_interp.exe tools/render_status.patlang --file D:/Projects_Organized/raytrace/out/pond_check.png.progress
rendered 200x120 in 30 bands by threads in 368971 ms
rendered by 18 threads in 562 s wall clock
> v2_interp.exe tools/export_scene.patlang --scene file --file scenes/pond_garden.scene --set w=200 --set h=120 --set aa=0 --out out/pond_check.txt
wrote out/pond_check.txt (2926 shapes)
> powershell.exe -NoProfile -File tools/verify_recursive.ps1 out/pond_check.png -SceneFile out/pond_check.txt -Stride 4
decoded by .NET: 200x120; pixels differing from the independent recursive tracer by more than 1 level: 0 (max difference 0); stride 4 in each direction, 1500 pixels checked
Negative control: the same picture against the tree check's scene.
> powershell.exe -NoProfile -File tools/verify_recursive.ps1 out/pond_check.png -SceneFile out/tree_check.txt -Stride 4
decoded by .NET: 200x120; pixels differing from the independent recursive tracer by more than 1 level: 1484 (max difference 224); stride 4 in each direction, 1500 pixels checked
Plants and Species of Tree
Trees, plants and a garden built one tree from a limb that calls itself. This page keeps that idea and gives it different parameters, to get five kinds of tree, and adds the plants that fill a garden under them: ferns, flowers, bushes, reeds and lily pads. Nothing here is new to the renderer. Every plant is a definition in the scene language of A language for scenes and models, a few lines long, with the numbers it needs as parameters.
The only addition to the language is two functions on numbers, floor(n) and mod(a, b), so that a loop can
lay flowers in a pattern (every third bush a different colour) without a table.mod(a,b) gives the remainder after dividing a by b
# floor(a) and mod(a, b), a - b floor(a / b), of numbers: for counting and cycling in a scene (a function of x, y, z has no floor here)
if name == "floor" or name == "mod" then
let na = ex_constant(a)
let nb = 1
if name == "mod" then
let nb = ex_constant(b)
end
if na == false or nb == false then
return ex_fail(st, name + " takes numbers, not something with x, y or z in it")
end
if name == "floor" then
return fa_num(floor(na))
end
if nb == 0 then
return ex_fail(st, "mod by zero")
end
return fa_num(na - nb * floor(na / nb))
end
Species
A species is a choice of three things: how many branches leave each limb, how they leave it (the angle, the bend), and what hangs on the ends.
| species | branches per limb | leaves |
|---|---|---|
| oak | 4, wide-spreading | large round clusters |
| birch | 3, held close to the limb, pale bark | small light leaves that droop |
| willow | arches that rise, bend over and hang | strands of leaves |
| spruce | whorls of drooping boughs, long at the bottom and short at the top | flat sprays of needles along each bough and its side shoots |
| palm | none: a curved trunk | a crown of long drooping fronds |
# Species of tree, to be included. Each is a definition that uses itself, with its own rules for how many
# branches leave a limb, how far they spread, how fast they shorten, and what the leaves are like.
# include "parts/species.scene"
# use oak(4.5, 0.4, 3, 7) at 0 0 0 oak(height of the trunk, its radius, depth, seed)
# use birch(5, 0.18, 4, 2) use willow(3, 0.25, 14, 5) use spruce(7.5, 16, 3) use palm(6, 0.2, 7, 4)
# All of them grow from the origin, up the y axis.
include "tree_parts.scene"
material birch_bark
color 1 1 1
ambient 0.2 diffuse 0.8 specular 0.05 shininess 10
pattern checkers 0.88 0.87 0.8 0.3 0.28 0.25 scale 0.22
end
material oak_bark
color 0.3 0.22 0.15
ambient 0.12 diffuse 0.8 specular 0 shininess 5
end
material palm_bark
color 1 1 1
ambient 0.2 diffuse 0.8 specular 0.05 shininess 10
pattern stripes 0.58 0.47 0.32 0.46 0.36 0.24 rotate z 90 scale 0.09
end
material oak_leaf_a
color 0.18 0.45 0.12
ambient 0.15 diffuse 0.75 specular 0.05 shininess 15
end
material oak_leaf_b
color 0.26 0.52 0.14
ambient 0.15 diffuse 0.75 specular 0.05 shininess 15
end
material oak_leaf_c
color 0.34 0.55 0.16
ambient 0.15 diffuse 0.75 specular 0.05 shininess 15
end
material birch_leaf_a
color 0.55 0.72 0.25
ambient 0.2 diffuse 0.75 specular 0.1 shininess 20
end
material birch_leaf_b
color 0.68 0.78 0.3
ambient 0.2 diffuse 0.75 specular 0.1 shininess 20
end
material willow_leaf_a
color 0.45 0.62 0.2
ambient 0.2 diffuse 0.75 specular 0.1 shininess 20
end
material willow_leaf_b
color 0.58 0.7 0.27
ambient 0.2 diffuse 0.75 specular 0.1 shininess 20
end
material needles
color 0.07 0.28 0.14
ambient 0.15 diffuse 0.8 specular 0 shininess 5
end
material needles_light
color 0.12 0.36 0.18
ambient 0.15 diffuse 0.8 specular 0 shininess 5
end
material frond
color 0.2 0.5 0.15
ambient 0.2 diffuse 0.75 specular 0.15 shininess 30
end
# ---- a limb of a given material, as limb(), for the other barks ----
define limb_of(len, r0, r1, kind)
if kind == 1
cone r1 r0 closed scale 1 (-len / (r0 - r1)) 1 at 0 (r0 * len / (r0 - r1)) 0 material birch_bark
else
if kind == 2
cone r1 r0 closed scale 1 (-len / (r0 - r1)) 1 at 0 (r0 * len / (r0 - r1)) 0 material oak_bark
else
cone r1 r0 closed scale 1 (-len / (r0 - r1)) 1 at 0 (r0 * len / (r0 - r1)) 0 material palm_bark
end
end
end
# ---- oak: a thick short trunk, four wide-spreading branches to a limb, big round leaf clusters ----
define oak_leaves(size, s)
for j in 0 to 3
if rand(s + j) < 0.34
sphere scale (size * (0.6 + 0.4 * rand(s + j + 10))) at ((rand(s + j + 20) - 0.5) * size * 1.4) ((rand(s + j + 30) - 0.35) * size) ((rand(s + j + 40) - 0.5) * size * 1.4) material oak_leaf_a
else
if rand(s + j) < 0.67
sphere scale (size * (0.6 + 0.4 * rand(s + j + 10))) at ((rand(s + j + 20) - 0.5) * size * 1.4) ((rand(s + j + 30) - 0.35) * size) ((rand(s + j + 40) - 0.5) * size * 1.4) material oak_leaf_b
else
sphere scale (size * (0.6 + 0.4 * rand(s + j + 10))) at ((rand(s + j + 20) - 0.5) * size * 1.4) ((rand(s + j + 30) - 0.35) * size) ((rand(s + j + 40) - 0.5) * size * 1.4) material oak_leaf_c
end
end
end
end
define oak_branch(len, r, n, s)
use limb_of(len, r, r * 0.72, 2)
if n > 0
for k in 0 to 3
let t = s * 7 + k * 3 + 1
use oak_branch(len * (0.66 + 0.16 * rand(t)), r * 0.68, n - 1, t) rotate z (30 + 34 * rand(t + 1)) rotate y (90 * k + 70 * rand(t + 2)) at 0 (len * (0.72 + 0.22 * rand(t + 3))) 0
end
else
use oak_leaves(0.9, s) at 0 len 0
end
if n == 1
use oak_leaves(0.7, s + 5) at 0 (len * 0.7) 0
end
end
define oak(h, r, depth, seed)
use oak_branch(h, r, depth, seed)
end
# ---- birch: slender and pale, three branches held close to the limb, light small leaves that droop at the ends ----
define birch_leaves(size, s)
for j in 0 to 2
if rand(s + j) < 0.5
sphere scale (size * (0.5 + 0.5 * rand(s + j + 10))) (size * 0.7) (size * (0.5 + 0.5 * rand(s + j + 12))) at ((rand(s + j + 20) - 0.5) * size * 1.3) ((rand(s + j + 30) - 0.6) * size) ((rand(s + j + 40) - 0.5) * size * 1.3) material birch_leaf_a
else
sphere scale (size * (0.5 + 0.5 * rand(s + j + 10))) (size * 0.7) (size * (0.5 + 0.5 * rand(s + j + 12))) at ((rand(s + j + 20) - 0.5) * size * 1.3) ((rand(s + j + 30) - 0.6) * size) ((rand(s + j + 40) - 0.5) * size * 1.3) material birch_leaf_b
end
end
end
# n0 is the depth the tree started with, so that n0 - n counts the generations from the trunk: later ones lean out more
define birch_branch(len, r, n, s, n0)
use limb_of(len, r, r * 0.8, 1)
if n > 0
for k in 0 to 2
let t = s * 7 + k * 3 + 1
use birch_branch(len * (0.55 + 0.1 * rand(t)), r * 0.72, n - 1, t, n0) rotate z (5 + 6 * rand(t + 1) + 2 * (n0 - n)) rotate y (120 * k + 60 * rand(t + 2)) at 0 (len * (0.8 + 0.2 * rand(t + 3))) 0
end
else
use birch_leaves(0.6, s) at 0 len 0
end
if n == 1
use birch_leaves(0.5, s + 5) at 0 (len * 0.6) 0
end
end
define birch(h, r, depth, seed)
use birch_branch(h, r, depth, seed, depth)
end
# ---- willow: a short trunk, and from its top long branches that rise, arch over and hang, with strands of leaves ----
#
# An arch is a chain of segments, each leaning a little further over than the one before (rotate z bend
# each time, the same way, so the chain curves in one plane); theta is how far from the vertical the segment
# leans, which is how a strand is hung: turned by 180 - theta it points straight down, whatever the arch does.
define willow_strands(s, theta)
for j in 0 to 2
let ll = 0.55 + 0.45 * rand(s + j + 10)
if rand(s + j) < 0.5
sphere scale 0.045 ll 0.045 at ((rand(s + j + 20) - 0.5) * 0.25) ll ((rand(s + j + 40) - 0.5) * 0.25) rotate z (180 - theta) material willow_leaf_a
else
sphere scale 0.045 ll 0.045 at ((rand(s + j + 20) - 0.5) * 0.25) ll ((rand(s + j + 40) - 0.5) * 0.25) rotate z (180 - theta) material willow_leaf_b
end
end
end
define willow_arch(len, r, n, theta, bend, s)
use limb_of(len, r, r * 0.9, 2)
use willow_strands(s, theta) at 0 (len * 0.6) 0
if n > 0
use willow_arch(len, r * 0.9, n - 1, theta + bend, bend, s + 3) rotate z bend at 0 len 0
end
end
define willow(h, r, arches, seed)
use limb_of(h, r, r * 0.8, 2)
for k in 0 to (arches - 1)
let t = seed * 5 + k * 11
use willow_arch(0.8, 0.05, 8, 36 + 18 * rand(t), 9 + 5 * rand(t + 1), t) rotate z (36 + 18 * rand(t)) rotate y (k * 360 / arches + 20 * rand(t + 2)) at 0 h 0
end
end
# ---- spruce: a straight trunk with whorls of drooping boughs, long at the bottom, short at the top ----
# A bough is a chain of flattened needle sprays, each shorter and thinner than the one before and bent a little
# further down; near its base it throws a side shoot to each side, which are shorter chains of the same.
define spray(len, r, kind)
if kind == 0
cone (r * 0.55) r closed scale 1 (-len / (r * 0.45)) 0.45 at 0 (r * len / (r * 0.45)) 0 material needles
else
cone (r * 0.55) r closed scale 1 (-len / (r * 0.45)) 0.45 at 0 (r * len / (r * 0.45)) 0 material needles_light
end
end
define bough(len, r, n, bend, kind)
use spray(len, r, kind)
if n > 0
use bough(len * 0.82, r * 0.78, n - 1, bend, kind) rotate z (-bend) at 0 len 0
end
end
define shoot_pair(len, r, n, bend, kind)
use bough(len, r, n, bend, kind) rotate z (-35) rotate y 50
use bough(len, r, n, bend, kind) rotate z (-35) rotate y (-50)
end
define spruce_bough(len, kind)
use bough(len, 0.12 + 0.15 * len, 4, 11, kind)
use shoot_pair(len * 0.5, 0.14, 2, 11, kind) at 0 (len * 0.25) 0
use shoot_pair(len * 0.38, 0.12, 1, 11, kind) at 0 (len * 0.6) 0
end
define spruce(h, tiers, seed)
use limb_of(h, 0.22, 0.04, 2)
for i in 0 to (tiers - 1)
let f = i / (tiers - 1)
let ty = h * (0.12 + 0.84 * f)
let len = ((0.2 + 0.8 * (1 - f)) * (0.9 + 0.2 * rand(seed + i)))
let up = 100 - 55 * f
let k = 6 + floor(2 * (1 - f))
for j in 0 to (k - 1)
let kind = floor(2 * rand(seed + 10 * i + j))
use spruce_bough(len, kind) rotate z (-up) rotate y (360 * j / k + 360 * rand(seed + i + 50)) at 0 ty 0
end
end
cone -1 0 closed scale 0.09 0.5 0.09 at 0 (h + 0.5) 0 material needles
end
# ---- palm: a trunk that curves, and a crown of long drooping fronds ----
define palm_trunk(len, r, n, bend)
use limb_of(len, r, r * 0.93, 3)
if n > 0
use palm_trunk(len, r * 0.93, n - 1, bend) rotate z bend at 0 len 0
else
for k in 0 to 8
use palm_frond(len * 2.6, k) rotate y (40 * k + 12 * rand(k)) at 0 len 0
end
end
end
# one frond: a flat blade that rises a little and droops, with a darker midrib
define palm_frond(len, k)
sphere scale 0.28 0.02 (len * 0.5) rotate x (-18 - 12 * rand(k + 3)) at 0 (0 - 0.15) (len * 0.48) material frond
sphere scale 0.06 0.03 (len * 0.52) rotate x (-12 - 10 * rand(k + 3)) at 0 (0 - 0.05) (len * 0.5) material palm_leaf_dark
end
material palm_leaf_dark
color 0.12 0.32 0.1
ambient 0.2 diffuse 0.75 specular 0.1 shininess 20
end
define palm(h, r, segments, seed)
use palm_trunk(h / segments, r, segments, 3 + 2 * rand(seed))
end
Plants
A fern frond is a rib with a pair of leaflets at each step, each pair shorter than the one before; a fern is several fronds rising and arching outward. A flower is a stem, a heart and a ring of petals, each petal a squashed sphere. A bush is a heap of leafy balls, a reed a slender stalk with a cattail near the top, a lily a flat disc on the water, with a flower on some.
# Plants smaller than trees, to be included.
# include "parts/plants.scene"
# use fern(0.9, 9, 3) at 0 0 0 fern(length of a frond, leaflets a side, seed): a spray of seven fronds
# use flower(0.45, 9, 2) at 0 0 0 flower(stem height, petals, colour 1 pink, 2 yellow, 3 white, 4 violet)
# use bush(0.7, 4) at 0 0 0 bush(radius, seed)
# use reed(1.6, 3) at 0 0 0 reed(height, seed): a cattail
# use lily(0.35, 5) at 0 0 0 lily(radius, seed): a pad lying on the water at y = 0, with a flower on some
# All stand on the origin, up the y axis.
material stem
color 0.25 0.5 0.15
ambient 0.2 diffuse 0.75 specular 0.05 shininess 10
end
material fern_a
color 0.15 0.45 0.12
ambient 0.2 diffuse 0.75 specular 0.1 shininess 20
end
material fern_b
color 0.22 0.55 0.15
ambient 0.2 diffuse 0.75 specular 0.1 shininess 20
end
material petal_pink
color 0.95 0.55 0.7
ambient 0.25 diffuse 0.75 specular 0.1 shininess 30
end
material petal_yellow
color 0.97 0.85 0.2
ambient 0.25 diffuse 0.75 specular 0.1 shininess 30
end
material petal_white
color 0.97 0.97 0.92
ambient 0.25 diffuse 0.75 specular 0.1 shininess 30
end
material petal_violet
color 0.55 0.35 0.85
ambient 0.25 diffuse 0.75 specular 0.1 shininess 30
end
material flower_heart
color 0.9 0.65 0.1
ambient 0.25 diffuse 0.75 specular 0.1 shininess 30
end
material bush_a
color 0.16 0.42 0.12
ambient 0.2 diffuse 0.75 specular 0.05 shininess 10
end
material bush_b
color 0.24 0.5 0.15
ambient 0.2 diffuse 0.75 specular 0.05 shininess 10
end
material reed_green
color 0.4 0.55 0.2
ambient 0.2 diffuse 0.75 specular 0.05 shininess 10
end
material cattail
color 0.38 0.22 0.1
ambient 0.2 diffuse 0.8 specular 0.05 shininess 10
end
material pad
color 0.12 0.4 0.16
ambient 0.2 diffuse 0.75 specular 0.3 shininess 60
end
# ---- a fern: fronds that rise and arch outward, each a rib with a pair of leaflets at every step, shorter toward the tip ----
# a leaflet: a flat ellipsoid, its base at the origin, pointing along +x
define leaflet(l)
sphere scale l (l * 0.1) (l * 0.22) at l 0 0 material fern_a
end
define fern_frond(len, n, s)
cylinder 0 len closed scale 0.01 1 0.01 material stem
for j in 1 to n
let f = j / (n + 1)
let ll = 0.42 * len * (1 - 0.85 * f) * (0.9 + 0.2 * rand(s + j))
use leaflet(ll) rotate z (0 - 62) at 0 (len * f) 0
use leaflet(ll) rotate z (0 - 62) rotate y 180 at 0 (len * f) 0
end
use leaflet(len * 0.1) rotate z 90 at 0 len 0
end
define fern(len, n, s)
for k in 0 to 6
use fern_frond(len * (0.8 + 0.4 * rand(s + k)), n, s * 3 + k) rotate z (28 + 24 * rand(s + k + 7)) rotate y (51.4 * k + 15 * rand(s + k + 3))
end
end
# ---- a flower: a stem, a heart, a ring of petals ----
define petal(l, colour)
if colour == 1
sphere scale l (l * 0.15) (l * 0.38) at l 0 0 material petal_pink
else
if colour == 2
sphere scale l (l * 0.15) (l * 0.38) at l 0 0 material petal_yellow
else
if colour == 3
sphere scale l (l * 0.15) (l * 0.38) at l 0 0 material petal_white
else
sphere scale l (l * 0.15) (l * 0.38) at l 0 0 material petal_violet
end
end
end
end
define flower(h, petals, colour)
cylinder 0 h closed scale 0.012 1 0.012 material stem
sphere scale 0.035 at 0 h 0 material flower_heart
for k in 0 to (petals - 1)
use petal(0.1, colour) rotate z (0 - 14) rotate y (k * 360 / petals) at 0 h 0
end
use leaflet(0.12) rotate z 35 at 0 (h * 0.3) 0
use leaflet(0.12) rotate z 35 rotate y 180 at 0 (h * 0.45) 0
end
# ---- a bush: a heap of leafy balls ----
define bush(r, s)
for k in 0 to 13
let a = rand(s + k) * 360
let d = r * 0.7 * rand(s + k + 20)
let hgt = r * (0.25 + 0.75 * rand(s + k + 40)) * (1 - 0.6 * d / r)
if rand(s + k + 60) < 0.5
sphere scale (r * (0.3 + 0.2 * rand(s + k + 80))) at (d * cosd(a)) hgt (d * sind(a)) material bush_a
else
sphere scale (r * (0.3 + 0.2 * rand(s + k + 80))) at (d * cosd(a)) hgt (d * sind(a)) material bush_b
end
end
end
# ---- a reed: a slender stalk, leaning a little, with a dark brown cattail near the top ----
define reed(h, s)
cylinder 0 h closed scale 0.015 1 0.015 rotate z (rand(s) * 8 - 4) rotate x (rand(s + 1) * 8 - 4) material reed_green
cylinder 0 (h * 0.16) closed scale 0.045 1 0.045 at 0 (h * 0.72) 0 rotate z (rand(s) * 8 - 4) rotate x (rand(s + 1) * 8 - 4) material cattail
end
# ---- a lily pad on the water, with a flower on some ----
define lily(r, s)
cylinder -0.012 0.012 closed scale r 1 r material pad
if rand(s) < 0.4
if rand(s + 1) < 0.5
use flower(0.03, 9, 3) at (r * 0.2) 0.012 0
else
use flower(0.03, 9, 1) at (r * 0.2) 0.012 0
end
end
end
The arboretum
The pond garden of Trees, plants and a garden, with a row of the five species behind it, ferns under them, two flower beds, bushes, reeds and lily pads at the water.
# An arboretum: the garden of the pond, with a tree of each species behind it, and the smaller plants.
# tools/render_scene.sh scenes/arboretum.scene out/arboretum.png 60
# The picture with --set w=200 --set h=120, mist with --set mist=0.05, a stereo pair with --set eyes=0.5.
param w = 400
param h = 240
size w h
camera from -8.5 3.4 -13 to 1 2.2 1 fov 56
light point at -14 24 -12
param aa = 1
if aa > 0
antialias adaptive 1 0.15
end
# morning mist: --set mist=0.05 makes the air thicker toward the ground (density 0.05 at the ground, thinning with height)
param mist = 0
if mist > 0
fog density mist falloff 0.45 color 0.84 0.89 0.95
end
# a pair of pictures for two eyes, side by side: --set eyes=0.5 (the eyes that far apart; --set eyes=0.5 with a smaller w and h is quicker)
param eyes = 0
if eyes > 0
stereo separation eyes gap 8
end
param seed = 5
include "parts/species.scene"
include "parts/plants.scene"
# ---- materials ----
material grass
color 1 1 1
ambient 0.34 diffuse 0.85 specular 0
texture ../textures/grass.ppm planar scale 0.03
bump normal ../textures/grass_normal.ppm planar strength 1.2 scale 0.03
end
material mud
color 0.42 0.33 0.22
ambient 0.3 diffuse 0.8 specular 0
end
material stone
color 0.62 0.6 0.56
ambient 0.15 diffuse 0.8 specular 0.1 shininess 30
end
material water
color 0.2 0.45 0.5
ambient 0.1 diffuse 0.25 specular 0.9 shininess 300
reflective 0.45 transparency 0.7 ior 1.33
end
material wood
color 1 1 1
ambient 0.18 diffuse 0.8 specular 0.15 shininess 40
pattern stripes 0.52 0.34 0.18 0.43 0.27 0.14 scale 0.08
end
material blade
color 0.3 0.58 0.17
ambient 0.25 diffuse 0.75 specular 0.05 shininess 10
end
material sky
color 0.58 0.76 0.95
ambient 0.95 diffuse 0 specular 0
end
# ---- the ground, with a pit for the pond, and the sky ----
# a slab whose top is the grass at y = 0, with a round pit 1 deep: the pit's wall and floor are mud
difference
cube scale 100 3 100 at 0 -3 0 material grass
cylinder -1 1 closed scale 3 1 3 material mud
end
plane rotate x 90 at 0 0 120 material sky
# ---- the water: one function, a cylinder of radius 2.9 under a rippled surface a little below the rim ----
surface "max(max(sqrt(x^2 + z^2) - 2.9, y + 0.06 - 0.025 * sin(7x + 3 * sin(2z)) * sin(6z + 1.5)), -1.08 - y)" bounds -3.1 -1.2 -3.1 3.1 0.2 3.1 material water
# ---- stones round the rim ----
for k in 0 to 27
sphere scale (0.28 + 0.12 * rand(k)) 0.17 (0.26 + 0.1 * rand(k + 50)) rotate y (rand(k + 9) * 180) at (3.2 * cosd(k * 360 / 28)) 0.05 (3.2 * sind(k * 360 / 28)) material stone
end
# ---- the trees, one of each species, in an arc behind the pond ----
use oak(3.0, 0.38, 3, seed) at -9 0 8.5
use birch(4.6, 0.17, 4, seed + 1) at -4 0 11
use spruce(7.5, 16, seed + 2) at 1.5 0 12
use willow(3.0, 0.25, 14, seed) at 5.5 0 7
use palm(6.0, 0.2, 7, seed + 3) at 10.5 0 10
# ---- ferns under the trees, flowers in two beds, bushes, reeds and lilies at the pond ----
use fern(0.9, 9, 3) at -7.2 0 6.4
use fern(0.8, 8, 8) at -10.5 0 6.8
use fern(0.9, 9, 5) at -2.6 0 9.2
use fern(0.8, 8, 12) at 3.2 0 9.6
for k in 0 to 17
use flower(0.35 + 0.12 * rand(k), 7 + mod(k, 3), 1 + mod(k, 4)) at (-6.5 + 0.3 * mod(k, 6) + 0.15 * rand(k + 20)) 0 (-3.5 + 0.35 * floor(k / 6) + 0.15 * rand(k + 40))
end
for k in 0 to 17
use flower(0.3 + 0.12 * rand(k + 60), 8 + mod(k, 3), 1 + mod(k + 2, 4)) at (5.0 + 0.3 * mod(k, 6) + 0.15 * rand(k + 80)) 0 (-2.5 + 0.35 * floor(k / 6) + 0.15 * rand(k + 100))
end
use bush(0.8, 4) at -8 0 1.5
use bush(0.55, 9) at -7 0 -1.0
use bush(0.7, 14) at 9 0 3
use bush(0.5, 21) at 7.7 0 1
for k in 0 to 6
use reed(1.3 + 0.6 * rand(k), k * 3) at (2.6 + 0.16 * k) 0 (-1.8 + 0.5 * rand(k + 30))
end
for k in 0 to 4
use reed(1.2 + 0.5 * rand(k + 50), k * 3 + 7) at (-2.8 - 0.12 * k) 0 (2.0 + 0.2 * k)
end
# lily pads on the water (its surface is a little below y = 0)
for k in 0 to 8
use lily(0.28 + 0.1 * rand(k), k * 2) at (1.7 * rand(k + 10) * cosd(k * 40 + 20)) (0 - 0.045) (1.7 * rand(k + 15) * sind(k * 40 + 20))
end
# ---- the bench, facing the pond ----
define bench()
# the seat: five slats
for i in 0 to 4
cube scale 0.9 0.025 0.065 at 0 0.45 (-0.26 + 0.13 * i) material wood
end
# the back: three slats, leaning back a little
for j in 0 to 2
cube scale 0.9 0.04 0.018 rotate x 12 at 0 (0.72 + 0.14 * j) 0.34 material wood
end
# a leg at each end, front and back, and the back posts
for e in 0 to 1
cube scale 0.04 0.225 0.3 at (-0.82 + 1.64 * e) 0.225 0 material wood
cube scale 0.04 0.45 0.03 at (-0.82 + 1.64 * e) 0.45 0.34 material wood
end
end
use bench() rotate y -105 at -4.3 0 -1.2
# ---- grass: tufts of three blades on a loose grid, none in the pond, the stones, the tree or the bench ----
group
for i in -14 to 14
for j in -14 to 14
let px = i * 1.3 + 0.9 * rand(i * 31 + j * 7 + 1)
let pz = j * 1.3 + 0.9 * rand(i * 17 + j * 13 + 2)
if ((px * px) + (pz * pz)) > 14.5
if (((px - 4.5) * (px - 4.5)) + ((pz - 5.5) * (pz - 5.5))) > 1.4
if (((px + 4.3) * (px + 4.3)) + ((pz + 1.2) * (pz + 1.2))) > 1.6
for b in 0 to 2
let t = i * 101 + j * 37 + b * 11
let hgt = 0.3 + 0.25 * rand(t)
cone -1 0 closed scale 0.03 hgt 0.03 rotate z ((rand(t + 1) - 0.5) * 36) rotate y (rand(t + 2) * 360) at (px + 0.25 * (rand(t + 3) - 0.5)) hgt (pz + 0.25 * (rand(t + 4) - 0.5)) material blade
end
end
end
end
end
end
end
Scenarios and oracles
The scene is checked as a scene, by counting what it builds, with no other renderer involved.
- Counts. An oak at depth 2 is 1 + 4 + 16 = 21 limbs; a birch at depth 3 is 1 + 3 + 9 + 27 = 40; a willow of 14 arches of 9 segments is 1 + 126; a spruce of 5 whorls is 34 boughs of 15 needle sprays, with trunk and tip 512 cones; a palm, 8 trunk cones and 9 fronds; a fern 7 fronds of 9 leaflet pairs; a flower of 9 petals 12 spheres.
- Materials. An oak's limbs are all oak bark and a birch's all birch bark; the flower's colour is the last number.
- Shape. A spruce reaches at least its tip's height and stays a narrow crown; a willow's strands hang from its arches; a birch's crown is narrower for its height than an oak's; a bush stays inside its radius.
- Seeds. The same seed gives the same tree, another gives another, for oak, birch and willow; a lily has a flower
when
rand(seed) < 0.4. floorandmod.mod(-1, 3)is 2,floor(-0.2)is -1,mod(7.5, 2)is 1.5;floorof something withxin it andmodby 0 are refused.
The picture
The scene language tests of A language for scenes and models still pass with the two new functions:
How it is checked
> v2_interp.exe tests/run.patlang --node scene/garden --depth 2
[ ok ] The garden
[ ok ] Pictures on materials
[ ok ] A texture line makes a texture_map pattern: planar mapping of a smoothed picture
[ ok ] A bump line makes a normal map with its mapping and strength
[ ok ] A scene file in tests/data reads the picture next to it by its bare name
[ ok ] Include runs another file here: its sphere is in the scene, then the 2 posts of the loop
[ ok ] Water and scatter
[ ok ] A pond with flat water: the top at y = 0 and the bed at y = -1, a ray from y = 5 hits ...
[ ok ] A scatter of points on a grid that leaves a hole where the pond is
checks: 6 passed, 0 failed, 0 blocked, 0 skipped, 0 not run
ALL PASSED
> v2_interp.exe tests/run.patlang --node scene/plants --depth 2
[ ok ] Plants and trees
[ ok ] Species of tree
[ ok ] An oak has four branches to a limb: depth 2 is 1 + 4 + 16 = 21 limbs
[ ok ] A spruce of 7.5: the cones' origins (each cone's own apex, which for a long frustum lies ...
[ ok ] The same seed gives the same tree: the same bounds
[ ok ] Small plants
[ ok ] A fern is 7 fronds, each a rib, 9 pairs of leaflets and a tip: 7 cylinders and 7 * 19 = ...
[ ok ] Counting in the language
[ ok ] Floor(3.7) = 3, mod(7, 3) = 1, mod(-1, 3) = 2 (a number mod b is never negative for b > 0)
[ ok ] Animals
[ ok ] A robin is 20 x 26 body feathers, 10 x 16 head feathers, 5 tail feathers, 2 x 22 wing ...
checks: 6 passed, 0 failed, 0 blocked, 0 skipped, 0 not run
ALL PASSED