Rainbow shader preview: A crown of spectral light that dissolves into the page.
ittybitty

Rainbow

A crown of spectral light that dissolves into the page.

Code

The usage always matches the preview, layers and performance settings included. No build step or package.

Use as
Code view

Copy embed gives one block to paste into any page or site builder, no setup. For your own code: add rainbow.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="rainbow" style="width: 100%; height: 640px"></ittybitty-shader>

<!-- Or with JavaScript, for full control: -->
<canvas id="rainbow" aria-hidden="true" style="display: block; width: 100%; height: 640px"></canvas>

<script type="module">
  import { rainbow } from './rainbow.js';

  const canvas = document.getElementById('rainbow');
  const effect = rainbow(canvas, {
    speed: 0.6,
    intensity: 1.1,
    spread: 1,
    reach: 0.85,
    width: 1.5,
    sway: 0.35,
    chroma: 1,
    definition: 1,
    origin: 'top',
    interactive: true,
    responsiveness: 0.5,
    palette: 'spectrum',
    color: '#ff8a5c',
    gradient: [[0, '#6f6cff'], [0.5, '#ff7ab8'], [1, '#ffc15e']],
    background: '#f5f4f1',
    // Performance
    dpr: 0.75,
    adaptive: true,
  });

  // Later: effect.set(…), effect.pause(), effect.resume(), effect.destroy()
</script>

Details

Rays fan down from above the top edge, each taking its hue from its angle. The light fades into your page colour through OKLab, so colours stay clean all the way into the background instead of greying out. Built for the top of a landing page.

Payload
6.9 KB brotli for rainbow.js and ittybitty-shader.js and runtime.js and pointer.js, measured at build time. See the method.
Resolution
Device pixel ratio capped at 0.75. The light is soft enough that the browser upscale is invisible, for about 7× fewer pixels at 2×.
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. Colours and controls still update.
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.