# Field

class in `@dioramajs/media/liquid`

```ts
import { Field } from '@dioramajs/media/liquid'
```

A displacement field over the box: `size` × `size` cells, each a vector in box px (y up) that
the pointer pushes along its path. Every step it decays, spreads to the neighbours and drifts
along itself. Deterministic: the same strokes and steps give the same field.

```ts
class Field
```

## Members

| Name | Type | Description |
| --- | --- | --- |
| `constructor` | `constructor(size: number): Field` |  |
| `peak` | `number` | Largest displacement in the field, px. |
| `size` | `number` |  |
| `x` | `Float32Array` |  |
| `y` | `Float32Array` |  |
| `clear` | `clear(): void` |  |
| `step` | `step(seconds: number, duration: number, swirl: number, width: number, height: number): void` | One step of `seconds`: the field fades to 2% over `duration`, spreads to its neighbours and, by `swirl`, drifts along itself with the box `width` × `height` px. |
| `stroke` | `stroke(ax: number, ay: number, bx: number, by: number, radius: number, width: number, height: number): void` | Pushes the cells within `radius` px of the segment from `a` to `b` (box px, y up, the box `width` × `height`) along the segment, most near it: a pass deposits about its own length. |
| `write` | `write(out: Uint16Array, width: number, height: number): void` | Packs the field into half floats, four per cell: the displacement in px, then the slope of its length (px per px), which the water style reads as the slope of a surface. |

Defined in [packages/media/src/liquid.ts](https://github.com/MasterKurosava/diorama/blob/main/packages/media/src/liquid.ts#L52).
