Walk layout¶
The turtle walk: step forward by a per-unit length, then turn.
lexograph.layout.walk.walk_layout(steps, *, turn=-90.0, scale=1.0, start=(0.0, 0.0), heading=(1.0, 0.0))
¶
Walk a turtle forward by each step length, turning by turn between steps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
steps
|
Iterable[float]
|
One forward step length per unit (e.g. sentence length or rendered width). Negative steps are allowed (the turtle walks backward). |
required |
turn
|
float
|
Degrees to rotate the heading after each step. The default |
-90.0
|
scale
|
float
|
A multiplier applied to every step length. |
1.0
|
start
|
tuple[float, float]
|
The starting |
(0.0, 0.0)
|
heading
|
tuple[float, float]
|
The initial heading vector; it is normalised internally. |
(1.0, 0.0)
|
Returns:
| Type | Description |
|---|---|
Coords
|
An |
Coords
|
steps. Row 0 is |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Contract
- The result has exactly
N + 1rows forNsteps. - The distance between consecutive vertices equals
abs(step * scale)for that unit (up to floating-point error). - The output is deterministic in its inputs.
Examples:
>>> walk_layout([1.0, 1.0, 1.0]).round(6).tolist()
[[0.0, 0.0], [1.0, 0.0], [1.0, -1.0], [0.0, -1.0]]
Source code in lexograph/layout/walk.py
lexograph.layout.walk.heading_angles(steps, *, turn=-90.0, heading=(1.0, 0.0))
¶
Return the heading angle (degrees) the turtle travels along for each step.
Useful for orienting per-unit glyphs along the walk (calligraphy-on-path):
angle i is the direction of the segment drawn for unit i.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
steps
|
Iterable[float]
|
One step per unit; only the count is used. |
required |
turn
|
float
|
Degrees rotated after each step (see :func: |
-90.0
|
heading
|
tuple[float, float]
|
The initial heading vector; normalised internally. |
(1.0, 0.0)
|
Returns:
| Type | Description |
|---|---|
FloatArray
|
A length- |
Examples: