
Black Hole
A black hole bending light around it, its glowing disc lensed over the top of its shadow.
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 black-hole.js, ittybitty-shader.js, runtime.js, pointer.js, texture.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="black-hole" style="width: 100%; aspect-ratio: 16 / 10;"></ittybitty-shader>
<!-- Or with JavaScript, for full control: -->
<canvas id="black-hole" aria-hidden="true" style="width: 100%; aspect-ratio: 16 / 10; display: block"></canvas>
<script type="module">
import { blackHole } from './black-hole.js';
const canvas = document.getElementById('black-hole');
const effect = blackHole(canvas, {
showSky: true,
showDisc: true,
showHole: true,
speed: 0.4,
tilt: 0.12,
size: 1,
disc: 1,
doppler: 0.6,
stars: 0.6,
quality: 0.5,
background: 'stars',
image: '',
interactive: true,
responsiveness: 0.4,
hot: '#fff1d6',
cool: '#ff7a2e',
// Performance
dpr: 1,
adaptive: true,
});
// Later: effect.set(…), effect.pause(), effect.resume(), effect.destroy()
</script>
Details
Each ray of light is traced as gravity bends it, which is what makes the famous image: the far side of the accretion disc is lifted up and over the shadow, a thin photon ring hugs its edge, and the side spinning towards you burns brighter. Stars, or your image, are pulled into an Einstein ring behind it. The pointer orbits the view. Heavy by design; adaptive resolution is on.
- Payload
- 8.0 KB brotli for black-hole.js and ittybitty-shader.js and runtime.js and pointer.js and texture.js, measured at build time. See the method.
- Resolution
- Device pixel ratio capped 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. 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.