The tile language · guide

Parts

A part is a name for a thing or a layer: a let with a body, in a parts file that a tile brings in with use.

The result

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

use "parts/grass" lawn

tile size="1x2" seed=7 {

    // From the middle of the south edge to the middle of the north edge,
    // 9 design millimetres wide, wandering up to 3 off its points.
    line trail width="9dmm" wobble="3dmm" { through south "(0.65sq, 1sq)" north }

    // Everything beside the path: one fill point on each side of it.
    region verge { boundedBy trail; fill "(0.15sq, 1sq)"; fill "(0.85sq, 1sq)" }

    stack {
        base
        dirt                                    // the whole tile, at the ground height
        dirt at=trail top="$bottom + [0.4dmm .. 0.8dmm]" clods=none   // the path: a second dirt along it, a little proud and smooth

        scatter at=verge count=5 {
            rock size="4dmm .. 10dmm" shape=rounded buried="30%"   // shape: or angular, flat
        }

        lawn at=verge cover="85%"
    }
}
A path of bare dirt winding up a 1×2 tile through grass, with rocks beside it. lawn is a part: it comes from library/parts/grass.dtile by a use line.

Say it plainly

Parts files hold definitions. A use line names the file and the definitions it brings in, so a reader always knows where a name came from.

A definition is called like an element. Its params are set as properties, and a place such as at= passes through to the elements inside it.

The rules

A use line names the file and the definitions it brings in

Parts files hold definitions that tiles bring in by name. A use line names the file and the definitions it brings in, so a reader knows where every name came from:

use "parts/grass" lawn long-grass

A bare path such as "parts/grass" is the bundled library, and "lib:parts/grass" says so explicitly. "./mine" or "../shared/x" is a file in the author's project. Anything else is an error.

A let with a body names a thing or a layer, called like an element

A let with a body has param lines and either one entry written bare or one stack. The body says what it names: one bare entry that is an unplaced thing (let oak { tree … }) names a thing, so it can be placed with at= or scattered (scatter count=2 { oak }); any other bare entry, and every stack, names a layer. Several entries are written in a stack, which is always a layer. It is called like an element; its params are set as properties, and a place (at=) passes through to the elements inside it. A definition can call another. Definitions that call each other in a loop are an error (dt::loop). A let has a value or a body, never both, and a body is never empty. The old word for this was define: it is refused (dt::retired) with the fix of writing let over it.

dharmatiles version="1.0.0"

// library/parts/grass.dtile
let lawn {
    param length "3.5dmm .. 6.5dmm"   // blade length along the ground
    param height "1.5dmm .. 2dmm"     // how tall a blade stands over the ground
    param clearings 0                 // patches of bare earth per square
    param cover "100%"                // share of the ground grassed over

    stack {
        grass length=length height=height clearings=clearings cover=cover
    }
}

// Long, tall blades: the species of 2x2-grass-tree.
let long-grass {
    stack {
        lawn length="5dmm .. 9dmm" height="2dmm .. 3dmm"
    }
}

A param is a name of a kind, from kind= or its default

A param is a name, and its kind is what it holds: the kind written with kind=, else the kind of its default, never the way it is used. param length "3.5dmm .. 6.5dmm" is a length, param clearings 0 a plain number, and a caller that writes length=5 gets dt::unit asking for 5dmm. It may be used anywhere a let of its kind may, in a formula (count="clearings + 1") as well as a control's whole value. A param whose default names a thing (param leaf pebble) holds a thing, and one whose default names a layer (param ground dirt) holds a layer: the caller passes another by name (shrub leaf=boulder, bank ground=water), as things and layers says. A param with no default says what it holds with kind= (param leaf kind=thing), and the caller must give it. A tile has no params. Expert controls live in parts files:

Expert controls live in parts files

dharmatiles version="1.0.0"

// library/parts/trees.dtile
let oak {
    tree top="$bottom + 59dmm" {
        trunk height="18dmm"
        crown width="44dmm" clumps=60 shape=wide
        branch split="34deg" eagerness=0.6 target=0.25 balance=0.8 exponent=3 minRadius="0.9dmm"
    }
}

A call's top= is the tree's. A tile places one oak as oak at="(1sq, 1sq)" top="$bottom + 60dmm", or several as scatter count=2 { oak }.

Errors this page explains

Next

Next: things and layers, what an element makes and how a thing is passed by name.