Diorama

Made for a big screen.

This site is one 3D scene, built for a computer: a wide window and a mouse. Open dioramajs.dev on a desktop or a laptop to see it.This site is one 3D scene, built for a wide window. Make this one wider, or open dioramajs.dev on a larger screen.

GitHub

DioramaDocs

pins

TextAlso in3D and product

@dioramajs/text/pinsSource

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

View as Markdown
On this page

Hall of the Senses · new exhibit

Touch it

Forty hands-on stations about touch, pressure and texture. Press, pull and feel your way through Gallery 2, open daily from 9 a.m.

Live preview needs WebGPU or WebGL 2. A science museum's exhibit hero on a dark background with the words Touch it standing out of a field of silver pins.

This example failed to draw.

Move the pointer over the pins and press to push them in. Switch the style and the press, or move the sliders.
Params of pins
style

pins are thin metal pins.

press

in presses the pins under the pointer down.

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. The tabs below are the example above, with the values you set.

To change its code, copy the source into your effects folder; the copy replaces the built-in.

Terminal window
npx @dioramajs/diorama add pins
<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>
import { start } from '@dioramajs/diorama'
const app = start()
app.attach('.pn-title', 'pins', {
style: 'pins',
press: 'in',
height: 26,
radius: 70,
duration: 1.6,
})
import { start } from '@dioramajs/diorama'
import pins from '@dioramajs/text/pins'
const app = start()
app.attach('.pn-title', pins({
style: 'pins',
press: 'in',
height: 26,
radius: 70,
duration: 1.6,
}))

Page transitions

Leaving a page the pins sink back into the field and fade; entering, they rise again. How a flight flies.

Params

Every param is also an attribute, and both app.attach() and the handle take it by name.

ParamTypeDefaultDescription
stylerebuildsdata-dio-style'pins' | 'bars' | 'domes''pins'
  • pins are thin metal pins.
  • bars are square bars.
  • domes are round plastic buttons.
pressrebuildsdata-dio-press'in' | 'out''in'
  • in presses the pins under the pointer down.
  • out pushes them up toward the viewer.
gaprebuildsdata-dio-gapnumber0.03 to 0.15 em0.06Distance between the centers of neighboring pins in ems; it widens on long text to keep the pin count.
heightdata-dio-heightnumber0 to 80 px26How far the letters stand out of the field; 0 leaves the field flat.
radiusdata-dio-radiusnumber0 to 200 px70Reach of the soft circle the pointer presses; 0 turns the pointer off.
colordata-dio-colorcolor'currentColor'Color of the pins, any CSS color; currentColor takes the text color.
durationdata-dio-durationnumber0 to 4 s1.6Time from the first pin rising to the last, the wave across the field included.
seedrebuildsdata-dio-seednumber1 to 1001Picks the small differences between pins and their timing.

Params marked rebuilds re-run the effect's setup when they change, so set them before the element shows.

Inputs and frames

It reads delta, height, presence, reducedMotion, size, width, x and 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. How a frame is decided.

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.

To change what reduced motion does, patch it in start().

import { start } from '@dioramajs/diorama'
start({ effects: { pins: { reducedMotion: 'off' } } })

Cost and quality

Download
11.8 KB min+gzip 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.
Frames
Idle at rest

It runs from the low tier up. Each tier changes this: The quality plugin picks the tier for each device.

TierWhat changes
lowAt most 4,000 pins instead of 16,000, so the gap widens on long text, and fewer samples for the shadows.
mediumAt most 8,800 pins.

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.

Ward & Ostrom · urban design

Downtown

Live preview needs WebGPU or WebGL 2. An urban design studio's heading Downtown in blue square bars on a pale gray background.

This example failed to draw.

Params of pins
<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.

Read by touch

A refreshable braille display with 40 cells, for your laptop and your phone.

Live preview needs WebGPU or WebGL 2. A braille display product line, Read by touch, in dark round buttons on a cream background.

This example failed to draw.

Params of pins
<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.

<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.