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

coin

3D and productAlso inPhotoBlocks and cards

@dioramajs/model/coinSource

A coin, medal or token struck from a logo or a photo: it turns, catches the light and flips over.

View as Markdown
On this page
Northwind

Live preview needs WebGPU or WebGL 2. A navy and coral compass logo struck into a gold coin with a raised rim; it leans toward the pointer as the light runs over the metal.

This example failed to draw.

Move the pointer over the coin, drag it to see its edge and its back, or click it to turn it over. Lower ink to strike the logo in bare metal.
Params of coin
style

motion

Usage

Put it on img: the front face, the circle in the middle of its box; a transparent PNG or SVG logo, or a photo of a coin cut out round. Without WebGL the plain image shows. start() registers coin, 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 coin
<img
class="coin"
src="/media/coins/coin-logo.svg"
width="512"
height="512"
data-dio="coin"
tabindex="0"
style="touch-action: pan-y"
/>
import { start } from '@dioramajs/diorama'
const app = start()
app.attach('.coin', 'coin', {
style: 'coin',
motion: 'flip',
metal: '#d4af5f',
ink: 1,
relief: 0.6,
yaw: 0,
pitch: 0,
tilt: 14.3,
turn: 0,
spin: 0,
shadow: 0.5,
})
import { start } from '@dioramajs/diorama'
import coin from '@dioramajs/model/coin'
const app = start()
app.attach('.coin', coin({
style: 'coin',
motion: 'flip',
metal: '#d4af5f',
ink: 1,
relief: 0.6,
yaw: 0,
pitch: 0,
tilt: 14.3,
turn: 0,
spin: 0,
shadow: 0.5,
}))

Page transitions

Leaves by dithering its pixels away while shrinking to 96%, and its shadow fades with it. 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'coin' | 'medal' | 'token''coin'Shape of the object. coin: a thin disc with a narrow rim and a reeded edge, for coins and tokens of crypto and fintech sites; medal: thicker, with a wide polished rim and a smooth edge, for awards and badges; token: a thick enamel token whose edge is striped in metal and white, for loyalty programs and games.
motionrebuildsdata-dio-motion'flip' | 'toss' | 'none''flip'
  • toss throws it up, tumbling, to land on the other face.
  • none keeps the click for the page.
backrebuildsdata-dio-backstring''Back face image URL or color; empty strikes the front on the back too. A color makes a plain back of that color with the rim.
metaldata-dio-metalcolor'#d4af5f'Color of the metal: the rim, the edge and the field around a logo. On a token, the color of its enamel.
inkdata-dio-inknumber0 to 11How much the picture keeps its own colors: 1 prints them, 0 strikes it in bare metal, so only its relief shows.
reliefdata-dio-reliefnumber0 to 10.6How far the shapes of a transparent logo and the rim stand out: 0 keeps the face flat.
yawdata-dio-yawnumber-180 to 180°0Rest turn; positive shows the right edge.
pitchdata-dio-pitchnumber-70 to 70°0Rest tilt; positive shows the top edge.
tiltdata-dio-tiltnumber0 to 35°14.3How far it leans toward the pointer: 0 turns the lean off.
turndata-dio-turnnumber-720 to 720°0Turns while the page scrolls past: 360 is a whole turn from entering the viewport to leaving it. 0 turns it off.
spindata-dio-spinnumber-360 to 360 deg/s0Idle turn while nobody touches it, pausing under the pointer and for 1.5 s after: 0 turns it off.
dragdata-dio-dragbooleantrueTurns and tips it under a drag, and with the arrow keys when it has a tabindex.
shadowdata-dio-shadownumber0 to 10.5Density of the shadow on the page.

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, opacity, presence, reducedMotion and width . Draws only while something on it moves, then stops. Only while it turns, leans, coasts after a drag, flips, and while spin turns it; none at rest, and pointer moves elsewhere draw nothing. Scroll draws frames only with turn. 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. It rests as posed: no lean, spin or scroll turn. A click or Enter turns it over at once, without the flip or the toss; dragging and arrow keys still turn it, without coasting.

Runs on every device. Nothing leans. A tap flips it, unless the image sits in a link or a button. A finger turns it only when the element has `touch-action: pan-y` or `none`, and tips it only with `none`; otherwise the gesture scrolls the page.

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

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

Cost and quality

Download
5.3 KB min+gzip the first time a page uses it
GPU
A disc of about seven hundred triangles; five reads of the picture per pixel of a face for its relief, no environment map.
Memory
The front image, and the back image when given.
Frames
Idle at rest

It runs from the low tier up. Every tier draws it the same way. The quality plugin picks the tier for each device.

Recipes

A logo struck as a coin

Give the image a transparent background: a PNG, or an SVG with a width and a height in the file. Its opaque shapes are struck into the face and stand out in relief; the transparent field around them is polished metal in metal. ink keeps the logo’s own colors at 1 and strikes it in bare metal at 0, which suits a monochrome mark.

<img
src="/brand/logo.svg"
width="512"
height="512"
data-dio="coin"
data-dio-metal="#c8ccd2"
data-dio-ink="0"
/>

An award medal that lands on its back

style="medal" makes a thicker disc with a wide polished rim, and motion="toss" throws it up on a click or Enter: it tumbles and lands on the other face. back takes the reverse as an image or a color.

Best Studio 2026, gold

Live preview needs WebGPU or WebGL 2. A gold medal with a blue enamel center and a white star; a click tosses it up and it lands showing Best Studio 2026 on its back.

This example failed to draw.

Params of coin
<img
class="coin"
src="/media/coins/medal-front.webp"
width="600"
height="600"
data-dio="coin"
data-dio-style="medal"
data-dio-motion="toss"
data-dio-back="/media/coins/medal-back.webp"
tabindex="0"
/>

Tokens that turn with the scroll

turn turns a coin as the page scrolls past it, so a row of tokens shows its edges and backs without any pointer, on touch screens too. A negative turn goes the other way. style="token" is a thick enamel token with a striped edge, colored by metal.

Leaf club token One Altitude token, 2026 Northwind in silver

Live preview needs WebGPU or WebGL 2. Three coins in a row: a green token with a leaf, a gold coin with a mountain, a silver coin with a compass struck in relief; they turn as the page scrolls.

This example failed to draw.

<div class="tokens">
<img
src="/media/coins/token-logo.webp"
width="512"
height="512"
data-dio="coin"
data-dio-style="token"
data-dio-metal="#1f6f5c"
data-dio-turn="180"
/>
<img
src="/media/coins/coin-front.webp"
width="600"
height="600"
data-dio="coin"
data-dio-back="/media/coins/coin-back.webp"
data-dio-turn="-180"
/>
<img
src="/media/coins/coin-logo.svg"
width="512"
height="512"
data-dio="coin"
data-dio-metal="#c8ccd2"
data-dio-ink="0"
data-dio-relief="1"
data-dio-turn="180"
/>
</div>

Notes

The coin is the circle in the middle of the image’s box, its diameter the shorter side. A photo of a coin should be cut out round, with transparent corners; a square photo loses its corners.

An SVG becomes a picture at the size written in its file, so give it a width and a height at least as large as the coin is shown. The image keeps its alt text for screen readers, and without WebGL the plain image shows.

The coin draws only while it moves: a lean, a drag, a flip, the scroll with turn or the idle spin. A coin inside a link keeps the link’s click and does not flip on it.

style, motion and back rebuild the effect; every other param changes live.