
ittybitty
Rays
Soft shafts of light from a single source, like sun through a high window.
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 rays.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="rays" style="width: 100%; height: 480px;"></ittybitty-shader>
<!-- Or with JavaScript, for full control: -->
<canvas id="rays" aria-hidden="true" style="width: 100%; height: 480px; display: block"></canvas>
<script type="module">
import { rays } from './rays.js';
const canvas = document.getElementById('rays');
const effect = rays(canvas, {
showBackground: true,
speed: 0.4,
intensity: 0.9,
originX: 0.25,
originY: -0.2,
spread: 0.5,
softness: 0.6,
length: 0.5,
palette: 'solid',
color: '#fff1dc',
gradient: [[0, '#ffb38a'], [0.5, '#fff1dc'], [1, '#9cc3ff']],
style: 'shafts',
interactive: false,
responsiveness: 0.5,
background: '#101114',
// Performance
dpr: 1.5,
adaptive: true,
});
// Later: effect.set(…), effect.pause(), effect.resume(), effect.destroy()
</script>
Details
Shafts of light fan out from a source you can place anywhere, even off the canvas. They always point towards the middle, so any origin gives a usable composition. Haze between the shafts keeps them from reading as stripes.
- Payload
- 6.4 KB brotli for rays.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.
- 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.