---
title: "segmentFrame"
description: "A frame along the line between two position props: how far each pixel is along it and across it."
group: "space"
groupTitle: "Shapes, frames & warps"
categoryId: "frames"
categorySlug: "frames"
categoryTitle: "Frames & coordinates"
kind: "function"
sourceUrl: "https://github.com/shader-effects-inc/shaders/blob/main/packages/core/src/std/frames.ts#L125"
---

# segmentFrame

A frame along the line between two position props: how far each pixel is along it and across it.

```ts
segmentFrame(slots: {from: PropRef; to: PropRef}): (params: GpuFragmentParams, surface: { uv: Expr; aspect: Expr; }) => SegmentFrame
```

Import `frames` from `shaders/std` and use `frames.segmentFrame`.

Pass `{from: p('from'), to: p('to')}` and call the result with `params` and a surface. `along` is 0 at `from` and equals `length` at `to`. `across` is the signed distance from the line. All three are aspect-corrected, in canvas-height units.

## Parameters

| Name | Type | Notes |
|---|---|---|
| `slots` | `{from: PropRef; to: PropRef}` |  |

## Example

```ts
const {along, across, length} = segmentFrame({from: p('from'), to: p('to')})(params, surfaceOf(params))
```

> **Tip.** Divide `along` by `length` for a 0–1 position along the line, the natural gradient parameter.

## See also

- [`centredFrame`](/docs/primitives/frames/centredframe) — A frame centred on a position prop: each pixel's offset from the centre and its distance.
- [`directionFrame`](/docs/primitives/frames/directionframe) — The two axes of a direction given in degrees, for patterns that run along it.
- [`surfaceOf`](/docs/primitives/frames/surfaceof) — The canvas a generator paints on: its `uv`, its `viewport` size in pixels and its `aspect`.

## Used by

[Prism](/docs/components/prism), [Waveform](/docs/components/waveform)