
Ocean
Open sea to the horizon, with a path of sun across the swell.
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 ocean.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="ocean" style="width: 100%; height: 560px;"></ittybitty-shader>
<!-- Or with JavaScript, for full control: -->
<canvas id="ocean" aria-hidden="true" style="width: 100%; height: 560px; display: block"></canvas>
<script type="module">
import { ocean } from './ocean.js';
const canvas = document.getElementById('ocean');
const effect = ocean(canvas, {
showSky: true,
showSun: true,
showWater: true,
speed: 0.6,
zoom: 1,
waves: 0.8,
chop: 0.55,
wind: 20,
sun: 0.12,
foam: 0.5,
clouds: 0.4,
camera: 4,
interactive: true,
responsiveness: 0.5,
deep: '#041a2b',
sky: '#1b2d55',
horizon: '#f4a36c',
// Performance
dpr: 1.5,
adaptive: true,
});
// Later: effect.set(…), effect.pause(), effect.resume(), effect.destroy()
</script>
Details
Each pixel traces its view onto thirty-two wave trains that crowd ripples onto their crests and travel at the speeds real deep-water waves do. The sea reflects a clouded sky, glows where the sun shines through thin crests, gathers lacy foam that trails behind breaking peaks, and carries a path of sun that widens towards the horizon. The view rides the swell. It is one of the heavier effects, so it renders at a pixel ratio of up to 1.5 and adapts to the device.
- Payload
- 8.9 KB brotli for ocean.js and ittybitty-shader.js and runtime.js and pointer.js, measured at build time. See the method.
- Resolution
- Device pixel ratio capped at 1.5, with adaptive resolution recommended.
- 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. 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.