
Ship something
people remember.
A button that wakes up when you reach for it.
Diamond
A cut gem turning in studio light, throwing rainbow fire and star-shaped glints.
This browser cannot run WebGL2, so this is a still image. The code below works wherever WebGL2 is available.
Code
For your own build, add diamond.js, ittybitty-shader.js, runtime.js and pointer.js next to this page. Highlighted values follow the controls.
<!-- Quickest: one element. Size it with CSS; it fills its box. -->
<script type="module" src="./ittybitty-shader.js"></script>
<ittybitty-shader effect="diamond" style="width: 100%; height: 480px;"></ittybitty-shader>
<!-- Or with JavaScript, for full control: -->
<canvas id="diamond" aria-hidden="true" style="width: 100%; height: 480px; display: block"></canvas>
<script type="module">
import { diamond } from './diamond.js';
const canvas = document.getElementById('diamond');
const effect = diamond(canvas, {
showBackground: true,
cut: 'round',
tint: '#ffffff',
fire: 1,
brilliance: 2.42,
sparkle: 0.9,
speed: 0.4,
size: 0.62,
lighting: 'studio',
interactive: true,
responsiveness: 0.5,
background: '#050507',
// Performance
dpr: 1.5,
adaptive: true,
});
// Later: effect.set(…), effect.pause(), effect.resume(), effect.destroy()
</script>
Details
A brilliant-cut stone turns slowly under softboxes and a ring light. Its facets are real planes, raytraced in one pass: light refracts in, bounces off the pavilion by total internal reflection and leaves through the crown, each part of the spectrum bending by its own amount, so edges of light split into rainbow fire. Facets that catch a light flare into four-pointed stars. Choose the cut and the stone, and tilt it with the pointer.
- Payload
- 13.8 KB brotli for diamond.js, ittybitty-shader.js, runtime.js and pointer.js, measured at build time.
- Resolution
- Device pixel ratio capped at 1.5, so facet edges stay crisp.
- Frame rate
- Display rate.
- When unseen
- Stops rendering when the canvas leaves the viewport or the tab is hidden, and resumes where it left off.
- Reduced motion
- Shows a single still frame. The pointer still tilts it.
- Layers
- Up to five effects fuse into one shader and one draw call. Filters such as dithering and halftone process the layers beneath them.
- Browsers
- Any browser with WebGL2: Chrome and Edge 56+, Firefox 51+, Safari 15+.
- Licence
- MIT. Copy it, change it, ship it.