TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/apursley2012/aurora-borealis/llms.txt
Use this file to discover all available pages before exploring further.
StarField component paints a living night sky directly onto a full-screen HTML <canvas> element. It runs entirely outside of React’s render cycle — after the initial mount, all updates happen through a requestAnimationFrame loop that drives star movement, opacity oscillation, and the occasional shooting star. The canvas is transparent so it composites cleanly over AuroraBackground without blocking its gradient layers.
Usage
StarField accepts no props. Star density, twinkle speed, and shooting-star parameters are all controlled by constants inside the component file.Star generation
On mount and on everyresize event the component recalculates the number of stars to fill the current viewport using a density formula:
| Property | Range | Purpose |
|---|---|---|
x | 0 – canvas.width | Horizontal position |
y | 0 – canvas.height | Vertical position |
size | 0.5 – 2 px | Radius of the drawn circle |
opacity | 0.0 – 1.0 (random) | Starting brightness |
speed | 0 – 0.05 px/frame | Upward drift velocity |
twinkleSpeed | 0.005 – 0.025 | Opacity change per frame |
twinkleDir | +1 or −1 | Current twinkle direction |
rgba(236, 254, 255, opacity) — a near-white cyan that reads as neutral starlight over teal and violet aurora bands.
Animation loop
TherequestAnimationFrame loop performs three operations per frame for each star:
1. Upward drift
Each star moves upward by itsspeed value every frame:
y < 0), it wraps to the bottom of the canvas with a freshly randomised x position, creating a continuous slow parallax.
2. Twinkling
Opacity walks linearly usingtwinkleSpeed and twinkleDir:
3. Drawing
Each star is rendered as a filled circle:ctx.clearRect at the start of every frame so transparent compositing over the aurora background remains correct.
Shooting star system
Trigger probability
Each frame has a 0.5 % chance of spawning a new shooting star (threshold:
Math.random() > 0.995). A maximum of 3 shooting stars can be active simultaneously.Trail appearance
Each shooting star is drawn as a gradient line —
rgba(236, 254, 255, opacity) at the head fading to fully transparent at the tail — using the Canvas 2D createLinearGradient API.Shooting star properties
| Property | Value / Range | Notes |
|---|---|---|
Initial x | 0 – canvas.width | Random horizontal spawn |
Initial y | 0 | Always spawns at the top edge |
length | 20 – 100 px | Trail length |
speed | 5 – 15 px/frame | Travel velocity |
angle | π/4 ± 0.1 rad | Near-45° diagonal |
opacity | 1.0 (initial) | Decreases by 0.015 per frame |
Fade and removal
Each active shooting star loses0.015 opacity per frame. Once opacity <= 0, it is removed from the active array, freeing a slot for a future spawn. The combination of travel speed and fade rate means the longest possible shooting star trail is visible for approximately 67 frames (~1.1 s at 60 fps).
Resize behavior
useEffect cleanup) alongside cancellation of the requestAnimationFrame handle, preventing memory leaks in strict-mode double-invocations and during hot-module replacement.
Performance notes
The canvas is positioned with
fixed inset-0, set to pointer-events-none, and given a transparent background. This ensures it never captures user input and that the browser’s compositor can layer it directly over AuroraBackground without a paint invalidation.requestAnimationFrame callback rather than in React state, there are zero re-renders after mount. The only React involvement is the initial useEffect that obtains the canvas ref and starts the loop.
Customization
All customization requires editingcomponents/StarField.js. There are no props.
Star density
Adjust the divisor in the density formula. Smaller values produce more stars; larger values produce fewer:Twinkle speed
ThetwinkleSpeed for each star is set during initStars:
Shooting star probability
The spawn check runs once per frame:- Raise the threshold (e.g.
0.998) for rarer events. - Lower the threshold (e.g.
0.990) for more frequent streaks. - Change
3to allow more simultaneous shooting stars.