Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/apursley2012/cosmic-developer/llms.txt

Use this file to discover all available pages before exploring further.

StarfieldBackground is the foundation of the Cosmic Developer portfolio’s visual atmosphere. It paints a living, breathing starfield directly onto an HTML <canvas> element, filling the entire viewport with hundreds of procedurally placed stars that slowly drift and twinkle — all without touching the DOM beyond a single canvas node.

Usage

Drop <StarfieldBackground /> once inside your app shell, before any navigational or content elements. It is self-contained and requires no props.
import { S as StarfieldBackground } from '../components/cosmos/StarfieldBackground'

// In your app shell:
<StarfieldBackground />
In the Cosmic Developer app, it is mounted at the root level alongside AuroraBackground so that both background layers are always present regardless of which route is active.

How It Works

1

Canvas mount & resize

On mount, useEffect grabs the <canvas> ref and calls a resize handler that sets canvas.width and canvas.height to window.innerWidth / window.innerHeight. A resize event listener keeps these dimensions in sync whenever the browser window changes size.
2

Star generation

After every resize, the star array is rebuilt. Star count is calculated as:
Math.floor(canvas.width * canvas.height / 2000)
Each star object carries:
PropertyRangePurpose
x, y0 → viewport width/heightPosition
radius0 → 1.5 pxSize
vx, vy±0.05 px/frameDrift velocity
alpha0 → 1Current opacity
dAlpha±0.01 /frameTwinkle speed
3

Radial gradient background

Each frame, the canvas is cleared and filled with a radial gradient — #0a1535 (cosmic navy) at the center blending out to #04050d (near-black) at the edges — giving the illusion of depth even before any stars are drawn.
4

Twinkle animation via requestAnimationFrame

The draw loop runs inside a requestAnimationFrame callback. On each tick:
  • Every star’s x/y advances by its velocity. Stars that drift off one edge wrap to the opposite edge.
  • alpha steps by dAlpha. When alpha drops below 0.1 or rises above 1.0, dAlpha is negated, creating a smooth ping-pong twinkle.
  • Each star is rendered as a filled arc (rgba(245, 251, 255, alpha)).
The RAF handle is stored in let o and cancelled in the useEffect cleanup to prevent ghost loops on unmount.

Positioning & Layering

The canvas element carries the following Tailwind classes:
fixed inset-0 w-full h-full -z-20 pointer-events-none
ClassEffect
fixed inset-0Anchors the canvas to the viewport, not the document scroll
w-full h-fullFills the entire viewport
-z-20Sits below AuroraBackground (-z-10) and all page content
pointer-events-noneLets clicks and hovers pass straight through to content
Because the canvas uses position: fixed rather than position: absolute, it stays locked to the viewport during scroll — the stars never move with the page content.

Customization

All tunable values live in StarfieldBackground.js. No props are exposed by design; edit the source constants directly:

Star Density

Adjust the divisor in Math.floor(width * height / 2000). A smaller divisor (e.g. 1000) produces more stars; a larger one (e.g. 4000) thins them out.

Star Size

Math.random() * 1.5 controls max radius in pixels. Increase the multiplier for larger, more nebula-like points of light.

Drift Speed

(Math.random() - 0.5) * 0.1 sets the velocity range (±0.05 px/frame). Raise the outer multiplier for faster parallax drift.

Twinkle Speed

(Math.random() - 0.5) * 0.02 controls the dAlpha step applied per frame, producing a ±0.01 oscillation range. Increase the multiplier for a livelier twinkle; decrease it for a calmer, barely-breathing effect.
Canvas rendering avoids creating hundreds of individual DOM nodes — a <div> per star would generate significant layout and paint overhead. With the canvas approach, the browser composites a single layer regardless of star count, keeping frame times low even on mid-range devices.

Build docs developers (and LLMs) love