The tile language · guide

Values and ranges

A quoted value is a small expression; a range in it is a value drawn afresh for each thing.

The result

The tile this source builds, from above
dharmatiles version="1.0.0"

// A range is two values and `..`: each rock draws its own size from it, keyed by the tile's seed.
tile size="1x1" seed=7 {
    stack {
        base
        dirt
        scatter count=5 { rock size="5dmm .. 11dmm" }
    }
}
A range is two values and ..: each rock draws its own size from it, keyed by the tile’s seed.

Say it plainly

Anywhere a control takes a number, you may write a sum of numbers with units, a name, a call such as min or sin, or a range such as 5dmm .. 11dmm. There are no loops and no assignments: a value is only worked out.

A range is the one place the program rolls dice. Each thing that reads a range draws its own number from it, so five rocks have five sizes, and the seed decides which five.

The rules

A quoted value is a tiny expression

value  := sum ( ".." sum )?        a range "lo .. hi", drawn afresh per thing
sum    := prod ( ("+" | "-") prod )*
prod   := unary ( ("*" | "/") unary )*
unary  := "-" unary | atom
atom   := number unit? | number "%" | name | "$" name | call | "(" sum ")" | "[" sum ".." sum "]" | list | weighting      see Weighted ranges
list   := "[" sum ( ":" number )? ( "," sum ( ":" number )? )* "]"      one value drawn, each as likely as its weight
call   := name "(" sum ( "," sum )* ")"      in a height: sin cos abs min max clamp smooth parent, and the coordinates

A range is written lo .. hi or [lo .. hi] in a control value, and the brackets go anywhere a number does: size="[1dmm .. 2dmm] + [3dmm .. 4dmm]" adds two ranges. In a height (a top=, a let) and inside a call, a range is always in brackets. A bare lo .. hi in a control value reaches over sums, so 1dmm .. 2dmm + 3dmm is 1dmm .. 5dmm; but when a value holds two bare ranges, or one beside a bracket or a weighting, each .. binds tighter than the arithmetic. The brackets always say it plainly.

A height is read with the same grammar and three differences: its names are camelCase, so a hyphen subtracts (groundHeight-2dmm); a range is always in brackets; and only a height calls functions (a weighting is written in both). A unit is one of the words on Units. This grammar is the one the program reads (dt-doc/src/expr.rs), written here and nowhere else.

An unknown function is dt::value.

A let name holds a distribution

let small "low(1dmm .. 6dmm, 11)" stands for that range with its odds, and a control that names small draws from it, each use its own roll. A tile's own let may be named by a size, count or density control; the library's $ heights may not.

A count has an equal chance for every whole number

A range on a count (count, perSquare as the number it makes, reeds' clumps and stems) is cut into one bin per whole number, ends rounded: 2..5 gives 2, 3, 4 and 5 a quarter each, the ends no rarer than the middle. A weighting moves the odds across the bins; a sum falls in the bin of its drawn place along its ends.

Sums are dice

size="[1dmm .. 2dmm] + [3dmm .. 4dmm]" adds two rolls and lands anywhere in 4dmm to 6dmm, most often near 5dmm. A name holds the range, not a roll, so s - s with let s "[1dmm .. 2dmm]" is two rolls, anywhere in -1dmm to 1dmm. Numbers and names shift and scale, and a negative factor mirrors. Dividing by a range is refused. On a count the sum is rounded. A band (top=, a pin) spans the interval of the sum (top="[1dmm .. 2dmm] - [1dmm .. 2dmm]" is a band from -1dmm to 1dmm) and its heights come up as two dice do, most often near 0.

Errors this page explains

Next

Next: weighted ranges, for saying which values of a range are likelier.