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

tone

Photo

@dioramajs/media/toneSource

Photos in brand colors: a duotone or a halftone, with color back on hover.

View as Markdown
On this page
Surf breaking over brown rocks at the foot of the cliffs

Live preview needs WebGPU or WebGL 2. A photo of surf breaking over brown rocks, shown in black and white, as a duotone or as a halftone of dots.

This example failed to draw.

The defaults give black and white. Pick color and background, switch the style to halftone, or set reveal to bring the color back.
Params of tone
style

duotone maps lightness to two colors.

reveal

none keeps the tone.

Usage

Put it on img, video. start() registers tone, 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 tone
<img
src="/media/coast/surf-1440.avif"
width="1440"
height="960"
data-dio="tone"
/>
import { start } from '@dioramajs/diorama'
const app = start()
app.attach('img', 'tone', {
style: 'duotone',
reveal: 'none',
color: '#000000',
background: '#ffffff',
strength: 1,
contrast: 1,
cell: 6,
angle: 45,
radius: 140,
duration: 0.4,
})
import { start } from '@dioramajs/diorama'
import tone from '@dioramajs/media/tone'
const app = start()
app.attach('img', tone({
style: 'duotone',
reveal: 'none',
color: '#000000',
background: '#ffffff',
strength: 1,
contrast: 1,
cell: 6,
angle: 45,
radius: 140,
duration: 0.4,
}))

Page transitions

Fades with the page transition; a flight carries the toned copy. 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'duotone' | 'halftone''duotone'
  • duotone maps lightness to two colors.
  • halftone draws dots sized by tone.
colordata-dio-colorcolor'#000000'Ink: the halftone dots. Lighter than background gives light dots on a dark ground.
backgrounddata-dio-backgroundcolor'#ffffff'Paper behind the dots. In duotone the darker of color and background takes the shadows.
strengthdata-dio-strengthnumber0 to 110 shows the original photo, 1 the full tone.
contrastdata-dio-contrastnumber0 to 21Contrast of lightness before toning.
celldata-dio-cellnumber2 to 32 px6Step of the halftone grid in CSS px.
angledata-dio-anglenumber0 to 90°45Angle of the halftone grid.
revealrebuildsdata-dio-reveal'none' | 'fade' | 'spot' | 'view''none'
  • none keeps the tone.
  • fade brings color back on hover.
  • spot shows color in a circle at the pointer.
  • view brings it back while the image is in the middle half of the viewport, which works on touch screens too.
radiusdata-dio-radiusnumber20 to 400 px140Radius of the spot.
durationdata-dio-durationnumber0 to 2 s0.4Length of the fade to color and back.

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

Inputs and frames

Draws only while something on it moves, then stops. Only while the color fades or the spot moves; none at rest. view decides in the frames the scroll draws anyway. 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. fade takes 0.15 s, and spot acts as fade.

Runs on every device. The tone stays: fade and spot need a hovering pointer. view works on touch.

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

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

Cost and quality

Download
2.1 KB min+gzip the first time a page uses it
GPU
One texture read and OKLab conversions per pixel.
Memory
The image only.
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

Room cards in the brand’s colors

Photos from different shoots look like one set once they share two colors. Give every card the brand’s ink and paper, and reveal="fade" brings the real color back under the pointer, so the reader still sees what the room looks like before booking it.

  • The Ocean Room: a white bed with a red throw by doors open to a balcony

    Ocean Room from $310

  • The Glass Room: a bed under tall steel windows that look over the hills

    Glass Room from $380

  • The Twin with Fireplace: a tea tray on a side table by a garden window

    Twin with Fireplace from $260

Live preview needs WebGPU or WebGL 2. Three hotel room photos in navy and cream that turn back to color under the pointer.

This example failed to draw.

<ul class="rooms">
<li>
<img
src="/media/hotel/ocean-room.avif"
width="800"
height="600"
data-dio="tone"
data-dio-color="#1d2a3a"
data-dio-background="#f4e3c3"
data-dio-reveal="fade"
/>
<p>Ocean Room <span>from $310</span></p>
</li>
<li>
<img
src="/media/hotel/glass-room.avif"
width="800"
height="600"
data-dio="tone"
data-dio-color="#1d2a3a"
data-dio-background="#f4e3c3"
data-dio-reveal="fade"
/>
<p>Glass Room <span>from $380</span></p>
</li>
<li>
<img
src="/media/hotel/twin-room.avif"
width="800"
height="600"
data-dio="tone"
data-dio-color="#1d2a3a"
data-dio-background="#f4e3c3"
data-dio-reveal="fade"
/>
<p>Twin with Fireplace <span>from $260</span></p>
</li>
</ul>

Light dots on a dark site

On a dark page, make color the light one: the dots are then light on a dark ground and grow in the highlights, like a screen print on black paper. A lineup of acts photographed by different people reads as one poster.

  • The f-hole, bridge and strings of a seventeenth-century cello

    Vesper Array Friday, 21:40

  • A silver flugelhorn with three rotary valves against black

    Signal Fires Saturday, 23:10

Live preview needs WebGPU or WebGL 2. Two instrument photos as light blue halftone dots on dark navy, as on a festival lineup.

This example failed to draw.

<ul class="stages">
<li>
<img
src="/media/festival/cello.webp"
width="960"
height="1200"
data-dio="tone"
data-dio-style="halftone"
data-dio-color="#7fd3ff"
data-dio-background="#081634"
/>
<p><b>Vesper Array</b> Friday, 21:40</p>
</li>
<li>
<img
src="/media/festival/flugelhorn.webp"
width="960"
height="1200"
data-dio="tone"
data-dio-style="halftone"
data-dio-color="#7fd3ff"
data-dio-background="#081634"
/>
<p><b>Signal Fires</b> Saturday, 23:10</p>
</li>
</ul>

Team photos that turn to color on phones

fade and spot need a pointer that hovers, so on a phone the photos would stay toned. reveal="view" brings the color back while a photo crosses the middle half of the viewport, as the reader scrolls a team page.

<img
src="/team/leo.avif"
data-dio="tone"
data-dio-color="#1d2a3a"
data-dio-background="#f4e3c3"
data-dio-reveal="view"
/>

The same look without WebGL

Before the engine loads, and on devices without WebGL, the photo shows in color. A CSS filter gives a close black and white for the default look; the copy draws over it once it runs.

img[data-dio~="tone"] {
filter: grayscale(1);
}

Notes

The tone changes how a photo looks, not what it says: its alt stays the same. Do not use it on pictures that carry information in their color, such as charts, maps or the color choices of a product.

For halftone, keep cell at 4 px or more. Smaller dots fall between the pixels of a standard screen and show a moiré pattern.

style and reveal rebuild the effect; the colors, strength and the grid change live, so a theme switch can write color and background from code.