The tile language · guide

Weighted ranges

A weighting wraps a range and says which parts of it come up more often.

The result

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

// A weighted range says which sizes are likelier: `low` favours the small end 4 to 1, so there
// are many small stones and a few big ones.
tile size="1x1" seed=7 {
    stack {
        base
        dirt
        scatter perSquare=14 { rock size="low(3dmm .. 12dmm, 4)" }
    }
}
A weighted range says which sizes are likelier: low favours the small end 4 to 1, so there are many small stones and a few big ones.

Say it plainly

A plain range makes every value equally likely. Wrap it in a weighting and the odds change: mostly small, mostly in the middle, mostly at the ends, or one of a few values you list.

The weightings are a short fixed set of nine. Only the range carries units; the numbers after it are plain.

The rules

A weighted range says which parts of a range are likelier

A range that is drawn once per thing can say which parts of it are likelier. The range goes inside a function:

weighting := ("flat" | "low" | "high" | "bell" | "peak" | "ends") "(" range ( "," number )* ")"
           | "steps" "(" range ( "," weight )+ ")"
           | "mix" "(" part "," weight ( "," part "," weight )+ ")"       part := a call above, over the same range
list      := "[" item ( "," item )+ "]"                                   item := value ( ":" weight )?
range     := sum ".." sum | "[" sum ".." sum "]"

Nine functions in all. A comma inside brackets makes a list; .. makes a range. The range carries its units like any other value (units): 1dmm .. 6dmm for a size, 0.2sq .. 0.6sq for a position. The numbers after the range are plain numbers and have none.

scatter at="foot(cliff)" perSquare=55 reach="4dmm" { stone size="low(1dmm .. 6dmm, 11)" }
scatter perSquare=3 { rock size="bell(6dmm .. 10dmm)" }
scatter perSquare=3 { stone size="[3dmm, 4dmm:3, 5.5dmm]" }
flat
1dmm .. 6dmm or flat(1dmm .. 6dmm)
Every value equally likely.
low
low(1dmm .. 6dmm, 4)
Mostly low. The ratio is how many times likelier the low end is than the high end: 1 is flat, 4 the default, a fraction leans high.
high
high(1dmm .. 6dmm, 4)
Mostly high: the mirror of low.
bell
bell(1dmm .. 6dmm, 0.2, 0.5)
Mostly in the middle. Spread is a share of the width (0.05 to 1); the centre is optional. Cut at the range.
peak
peak(1dmm .. 6dmm, 0.5, 0.5)
A favourite value falling off in a straight line over the spread. Cut at the range, so a wide spread leaves the ends above zero; a centre at 0 or 1 makes a ramp.
ends
ends(1dmm .. 6dmm, 1, 0.5)
The bell turned over: a valley at the centre, rising as a power. 1 is a straight V, 2 a parabola, 0 flat; a centre at an end makes a ramp away from it.
steps
steps(1dmm .. 6dmm, 1, 4, 2)
Drawn by hand: the range cut into equal bins, one weight each (up to 32), flat inside a bin. A weight of 0 leaves a gap.
list
[1dmm:4, 2dmm:5, 3dmm:1]
One of the values written, each as likely as its weight (1 when left out). Values need not be whole or evenly spaced, and a list has no range of its own.
mix
mix(bell(1dmm .. 6dmm), 3, flat(1dmm .. 6dmm), 1)
A blend of weightings over the same range, each part as likely as its weight: mostly typical, a few anywhere.

Each curve is the density over the range: higher means likelier, the dotted line is the plain range. A list has no density, so its values stand as bars, as tall as their share.

The numbers after the range are plain, and have limits

Only the range has units; the numbers after it are plain. low and high take a ratio over 0 (4 by default, no upper limit). bell and peak take a spread of 0.05 to 1 and a centre of 0 to 1. ends takes a power of 0 to 8 (1 by default) and the valley's centre. steps takes 2 to 32 weights and mix 2 to 16 parts; a list holds up to 64 values. A weight is 0 or more, and at least one must be above 0. A number outside its limits is dt::range, with the limits in the help; dharmatiles elements rock lists every function with its defaults and limits.

A list is the values written, each as likely as its weight

[1:4, 2:5, 3:1] on a count draws 1, 2 or 3, each as likely as its weight; a missing weight is 1, so [1, 2, 3, 4, 5, 6] is a six-sided die, and on a count (count, stems) the same as 1..6. On a size, 1dmm .. 6dmm is every size between and the list is only the sizes written: size="[2dmm, 5dmm:3, 8.5dmm]". A weight of 0 is allowed beside one above 0. A value written twice is a dt::weighting error, and its help gives the list to write: [1:4, 2:6] for [1:4, 2:5, 2:1]. Values are drawn in ascending order, so a list moves and scales like any range.

A mix blends weightings over one range

mix(bell(1dmm .. 6dmm), 3, flat(1dmm .. 6dmm), 1) is three parts bell to one part flat. Every part is written over the same range (a different one is a dt::weighting error), and a part is a call, never a list or another mix.

A weighting wraps a plain range

A weighting wraps a plain range: low(bell(1dmm .. 6dmm)) and low(3) are dt::weighting errors. A weighting on a range of no width has no effect, and check says so in a note.

Every control that draws takes a weighting

A size, a count, a density, a course or a bay of a wall, a blade's length or height, how deep a rock is buried, how wide a shattered patch is, a tree's heights and a point's range in at=. A control that is a band never does. The "takes" column of each element page says weighted range where it applies.

A weighted range on a top is a cloud

A body's top= and a pin's top may be a weighted range (clouds). A within distance is read as a band, not a draw: low(…) there is a dt::weighting error whose help gives the range to write. flat(…) is the plain range and is accepted anywhere a range is.

Errors this page explains

Next

Next: units and kinds, how a length is written and checked.