---
title: "foldRamp"
description: "Folds any number into 0–1 as a seamless zigzag: up from 0 to 1, back down, every 2 units."
group: "paint"
groupTitle: "Painting"
categoryId: "paint"
categorySlug: "paint"
categoryTitle: "Fields, palettes & ramps"
kind: "function"
sourceUrl: "https://github.com/shader-effects-inc/shaders/blob/main/packages/core/src/std/paint/fields.ts#L745"
---

# foldRamp

Folds any number into 0–1 as a seamless zigzag: up from 0 to 1, back down, every 2 units.

```ts
foldRamp(t: Expr): Expr
```

Import `paint` from `shaders/std` and use `paint.foldRamp`.

Scale the value first to set the cycle length. Safe anywhere, including inside a `guarded` branch.

## Parameters

| Name | Type | Notes |
|---|---|---|
| `t` | `Expr` |  |

## Example

```ts
const rgb = stops(p('colorSpace'))(foldRamp(phase), params).member('rgb')
```

## See also

- [`wrapRamp`](/docs/primitives/paint/wrapramp) — Runs a palette value back and forth `cycles` times so a ramp repeats without a seam.

## Used by

[Obsidian](/docs/components/obsidian)