# pins

The text becomes pin art: a field of metal pins around the words with the letters pushed out in relief.

A field of thin metal pins seen through the page camera gathers around the words, their domed tips catching a studio light. The field follows the shape of the text and thins out at its edge, the last pins smaller and sunk into the page, so no plate or box shows. The pins inside the letters stand out toward the viewer, so the text rises as a crisp relief over the low pins, which sit dimmer and fainter in its shade; the raised pins cast soft shadows on the field and the page, and their shafts show at the edges in perspective. Pins are spaced in ems, so a letter is the same number of pins wide at any font size. As the heading comes into view the letters rise out of the flat field in a wave from left to right, overshooting a little, while the flat pins bob as the wave passes. The pointer presses the pins in under a soft circle, or pushes them out with press out, and they spring back with a wobble when it moves on. The bars style turns the pins into square bars, like a city skyline, and the domes style into round buttons, like a tactile display.

Module `text`, category Text. Import `@dioramajs/text/pins`. [Source](https://github.com/MasterKurosava/diorama/blob/main/packages/text/src/pins.ts)

A science museum's exhibit hero on a dark background with the words Touch it standing out of a field of silver pins.

```html title="index.html"
<section class="pn-hall">
  <p class="pn-kicker">Hall of the Senses · new exhibit</p>
  <h2 class="pn-title" data-dio="pins">Touch it</h2>
  <p class="pn-line">Forty hands-on stations about touch, pressure and texture. Press, pull and feel your way through Gallery 2, open daily from 9 a.m.</p>
</section>
```

## Usage

Put it on: a heading or a short label in a bold or display font, 48 px and larger. Not img, video, canvas, svg or form fields.

`start()` registers `pins`, so the attribute alone puts it on an element.

```html
<h1 data-dio="pins">Press here</h1>
```

In page transitions: Leaving a page the pins sink back into the field and fade; entering, they rise again.

## Params

| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `style` (rebuilds) | `data-dio-style` | `'pins' \| 'bars' \| 'domes'` | `'pins'` | pins are thin metal pins; bars are square bars; domes are round plastic buttons. |
| `press` (rebuilds) | `data-dio-press` | `'in' \| 'out'` | `'in'` | in presses the pins under the pointer down; out pushes them up toward the viewer. |
| `gap` (rebuilds) | `data-dio-gap` | `number` 0.03 to 0.15 em | `0.06` | Distance between the centers of neighboring pins in ems; it widens on long text to keep the pin count. |
| `height` | `data-dio-height` | `number` 0 to 80 px | `26` | How far the letters stand out of the field; 0 leaves the field flat. |
| `radius` | `data-dio-radius` | `number` 0 to 200 px | `70` | Reach of the soft circle the pointer presses; 0 turns the pointer off. |
| `color` | `data-dio-color` | `color` | `'currentColor'` | Color of the pins, any CSS color; currentColor takes the text color. |
| `duration` | `data-dio-duration` | `number` 0 to 4 s | `1.6` | Time from the first pin rising to the last, the wave across the field included. |
| `seed` (rebuilds) | `data-dio-seed` | `number` 1 to 100 | `1` | Picks the small differences between pins and their timing. |

Changing a param marked rebuilds re-runs the effect setup.

### Variants

- `style`: `pins`, `bars`, `domes`
  - `pins` are thin metal pins.
  - `bars` are square bars.
  - `domes` are round plastic buttons.
- `press`: `in`, `out`
  - `in` presses the pins under the pointer down.
  - `out` pushes them up toward the viewer.

## Inputs and frames

Reads [`delta`](/docs/api/inputs#input-delta), [`height`](/docs/api/inputs#input-height), [`presence`](/docs/api/inputs#presence), [`reducedMotion`](/docs/api/inputs#input-reducedMotion), [`size`](/docs/api/inputs#size), [`width`](/docs/api/inputs#input-width), [`x`](/docs/api/inputs#input-x), [`y`](/docs/api/inputs#input-y). Draws only while something on it moves, then stops. Full rate while the letters rise and while pressed pins move and spring back; none at rest, under a still pointer or with the pointer away. The relief stays drawn at rest. See [how a frame is decided](/docs/concepts/frames).

## Reduced motion and touch

With reduced motion it shows a still frame: motion inputs are zero and time stands still. The letters stand in relief from the start and stay still: no rising wave, no pressing, and no frames of their own.

Runs on every device. A finger pressing the field presses the pins under it and drags the soft circle along; they spring back when it lifts. Nothing follows a hover.

```ts
import { start } from '@dioramajs/diorama'

start({ effects: { pins: { reducedMotion: 'off' } } })
```

## Cost and quality

Loads 11.8 KB the first time a page uses it. GPU: Two draws: one instanced mesh of lit pins, about 200 triangles each (18 for bars), with up to 18 reads of a small height texture per pixel for the shadows and the shade between pins, and one quad for the shadow on the page. Memory: A canvas of the text at its CSS size and its distance field, read once on the CPU, and a half-float texture of one texel per pin, rewritten only while pins move.

- low: At most 4,000 pins instead of 16,000, so the gap widens on long text, and fewer samples for the shadows.
- medium: At most 8,800 pins.

See [the quality plugin](/docs/effects/quality).

## Recipes

### Square bars for a city skyline

`style="bars"` swaps the pins for square bars with a beveled top that fill the field edge to edge, so the raised letters look like blocks of towers seen from above. Their sides take the light by the way they face, and the tall ones cast shadows on the low ones. A larger `gap` makes chunkier blocks, and a larger `height` taller towers whose sides show more in perspective.

An urban design studio's heading Downtown in blue square bars on a pale gray background.

```html title="index.html"
<section class="pn-city">
  <p class="pn-kicker">Ward &amp; Ostrom · urban design</p>
  <h2 class="pn-towers" data-dio="pins" data-dio-style="bars" data-dio-height="48" data-dio-gap="0.1">Downtown</h2>
</section>
```

### Round buttons that rise under the finger

`style="domes"` draws round plastic buttons, like the pins of a braille display, and `press="out"` makes the pointer push them up toward the viewer instead of in. On a phone the buttons rise under a finger and settle when it lifts.

A braille display product line, Read by touch, in dark round buttons on a cream background.

```html title="index.html"
<section class="pn-dots">
  <h2 class="pn-read" data-dio="pins" data-dio-style="domes" data-dio-press="out" data-dio-gap="0.11" data-dio-height="18">Read by touch</h2>
  <p class="pn-line">A refreshable braille display with 40 cells, for your laptop and your phone.</p>
</section>
```

### Pins in a color of their own

The pins take the color of the text by default, as polished metal: dark text gives gunmetal pins, light text silver ones. `color` sets another one, for example a steel gray under a colored heading.

```html
<h2 data-dio="pins" data-dio-color="#c0c4cc" data-dio-height="40">Made by hand</h2>
```

## Notes

The pins are real 3D objects in the space of the page, one instanced draw for all of them, seen through the same camera as the page, so the raised ones lean away from the middle of the screen and show their shafts at the edges of the letters. A distance field of the glyphs is built once on the CPU, and each pin stands out by a smooth function of its distance to the letter edge, so the letters rise as plateaus whose edges ramp down over a pin or two. Every pin is lit by a studio light: metal tips reflect a softbox and catch a sharp highlight, the shafts are darker, the pins around a tall one shade it, and the raised pins cast soft shadows on the field and the page.

The field follows the shape of the words: pins stand only within about a sixth of an em of the letters, the last ones smaller and sunk into the page, so it has no edge or plate around it. The low pins sit dimmer and fainter than the risen ones, so the letters read on a light page and a dark one alike. `gap` is the distance between the centers of neighboring pins in ems, 0.06 by default, so a letter is the same number of pins wide at any font size; the pins never come closer than 3 px. The field holds at most 16,000 pins, fewer on slower devices; past that the gap widens.

On view the letters rise in a wave from left to right, and `duration` is the time the whole rise takes. The pointer presses a soft circle `radius` pixels wide: hovering presses lightly, a click or a finger deeper, and the pins spring back when it moves on; `radius="0"` turns it off. Frames run only while pins move: at rest the relief stays drawn and the effect draws nothing. Under reduced motion the letters stand in relief from the start and the pointer does nothing.

The text stays real text in the DOM: screen readers read it, search engines index it, and find in page works, while the pins are drawn in its place. Text with `text-shadow`, `-webkit-text-stroke`, `background-clip: text` or a vertical writing mode stays as it is, with a warning in development. `style`, `press`, `gap` and `seed` rebuild the effect when they change; the other params change live.

## Related

- [assemble](/docs/effects/assemble.md): Thousands of lit particles fly out of the depth around the page and gather into a heading.
- [blinds](/docs/effects/blinds.md): A heading printed across real 3D slats that turn over in a wave, lit and casting shadows, to show it.
- [counter](/docs/effects/counter.md): Stats count up to their value on real 3D mechanics: odometer drums, slot machine reels or flip cards.
- [dust](/docs/effects/dust.md): A heading crumbles into fine sand that lifts off the page and drifts away in depth as it scrolls out, or on a click.
- [emboss](/docs/effects/emboss.md): Letters pressed into or raised out of paper, leather, brushed metal, stone or plaster, lit by a light that follows the pointer.
- [extrude](/docs/effects/extrude.md): A headline becomes a solid 3D block: beveled letters with lit side walls, seen in perspective, that turn toward the pointer.
- [fire](/docs/effects/fire.md): The letters burn: flames rise from their tops, sparks drift up in depth and the firelight flickers on the page.
- [hologram](/docs/effects/hologram.md): A heading becomes a 3D hologram: projected from a glowing emitter, built of slices in depth, crossed by scan lines.
- [Reduced motion](/docs/guides/reduced-motion.md)
- [Performance and quality](/docs/guides/performance.md)
