
ittybitty
Topography
Contour lines of a slowly shifting landscape.
This browser cannot run WebGL2, so this is a still image. The code below works wherever WebGL2 is available.
Code
The usage always matches the preview, layers and performance settings included. No build step or package.
Copy embed gives one block to paste into any page or site builder, no setup. For your own code: add topography.js, ittybitty-shader.js, runtime.js, 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="topography" style="width: 100%; height: 480px;"></ittybitty-shader>
<!-- Or with JavaScript, for full control: -->
<canvas id="topography" aria-hidden="true" style="width: 100%; height: 480px; display: block"></canvas>
<script type="module">
import { topography } from './topography.js';
const canvas = document.getElementById('topography');
const effect = topography(canvas, {
showBackground: true,
speed: 0.2,
scale: 1,
density: 14,
weight: 1,
index: 5,
tint: 0.25,
style: 'lines',
interactive: true,
responsiveness: 0.5,
palette: [[0, '#2f6f73'], [0.5, '#8a8f5a'], [1, '#c2703d']],
background: '#f3efe6',
// Performance
dpr: 2,
adaptive: true,
});
// Later: effect.set(…), effect.pause(), effect.resume(), effect.destroy()
</script>
Details
A warped noise landscape drawn as contour lines that stay a constant width at any zoom or density, with a heavier index line every few. The ground takes a faint tint from its elevation. It moves slowly, so it runs at 30 frames a second.
- Payload
- 6.0 KB brotli for topography.js and ittybitty-shader.js and runtime.js and pointer.js, measured at build time. See the method.
- Resolution
- Device pixel ratio capped at 2, so lines stay hairline-sharp.
- Frame rate
- Capped at 30 frames a second.
- 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 still map. Controls still update 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.