{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"ringed-planet-background-with-orbiting-dust-bands-and-ring-shadow","type":"registry:block","title":"Ringed Planet Dust Bands","description":"","dependencies":[],"files":[{"path":"components/we-inc/ringed-planet-background-with-orbiting-dust-bands-and-ring-shadow.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\n\n// The values worth changing.\nconst SETTINGS = {\n  dust: [236, 220, 194], // ring dust colour as [red, green, blue]\n  planet: [\"#e3c79c\", \"#9c7451\", \"#2a1c14\"], // lit side, middle, night side\n  grains: 3200, // dust grains in the ring; fewer is cheaper\n  tilt: -0.22, // how much the ring leans, in radians\n  speed: 1, // how fast the ring turns\n};\n\nconst SCENE: any = {\n  start: 0,\n  still: 0,\n  init(ctx: any, w: any, h: any) {\n    const narrow = w < 700;\n    const R = narrow ? w * 0.3 : Math.min(w * 0.15, h * 0.3);\n    const cx = narrow ? w * 0.6 : w * 0.72;\n    const cy = narrow ? h * 0.8 : h * 0.56;\n    // Bands of dust with gaps between them, like real ring systems.\n    const bands = [[1.38, 1.55, 0.5], [1.58, 1.86, 1], [1.93, 2.12, 0.75], [2.16, 2.24, 0.35]];\n    const grains: any[] = [];\n    for (let i = 0; i < SETTINGS.grains; i++) {\n      const b = bands[Math.floor(Math.random() * bands.length)];\n      const r = b[0] + Math.random() * (b[1] - b[0]);\n      grains.push({ r, a: Math.random() * 6.2832, s: Math.random() < 0.08 ? 1.6 : 1, l: b[2] * (0.35 + Math.random() * 0.65) });\n    }\n    const stars: any[] = [];\n    for (let i = 0; i < 160; i++) stars.push({ x: Math.random() * w, y: Math.random() * h, a: 0.15 + Math.random() * 0.6, s: Math.random() < 0.1 ? 1.5 : 1 });\n    return { R, cx, cy, bands, grains, stars };\n  },\n  ring(ctx: any, st: any, t: any, front: any) {\n    const { R, cx, cy } = st;\n    const flat = 0.24;\n    const [dr, dg, db] = SETTINGS.dust;\n    ctx.save();\n    ctx.translate(cx, cy);\n    ctx.rotate(SETTINGS.tilt);\n    // A faint continuous sheen under the grains gives each band body.\n    for (const b of st.bands) {\n      ctx.strokeStyle = `rgba(${dr},${dg},${db},${(front ? 0.3 : 0.2) * b[2]})`;\n      ctx.lineWidth = (b[1] - b[0]) * R * flat * 1.15;\n      ctx.beginPath();\n      ctx.ellipse(0, 0, ((b[0] + b[1]) / 2) * R, ((b[0] + b[1]) / 2) * R * flat, 0, front ? 0 : Math.PI, front ? Math.PI : Math.PI * 2);\n      ctx.stroke();\n    }\n    ctx.fillStyle = `rgb(${dr},${dg},${db})`;\n    for (const g of st.grains) {\n      // Inner dust orbits faster than outer dust.\n      const a = g.a + (t * SETTINGS.speed * 0.12) / Math.pow(g.r, 1.5);\n      const sa = Math.sin(a);\n      if (front ? sa < 0 : sa >= 0) continue;\n      const x = Math.cos(a) * g.r * R;\n      const y = sa * g.r * R * flat;\n      // Dust on the far right is lit by the sun; dust in the planet's shadow goes dark.\n      const shadow = !front && Math.abs(x) < R * 1.02 ? 0.25 : 1;\n      ctx.globalAlpha = Math.min(1, g.l * shadow * (0.7 + 0.5 * Math.cos(a - 0.6)));\n      ctx.fillRect(x, y, g.s, g.s);\n    }\n    ctx.globalAlpha = 1;\n    ctx.restore();\n  },\n  draw(ctx: any, w: any, h: any, t: any, st: any) {\n    ctx.fillStyle = \"#05070d\";\n    ctx.fillRect(0, 0, w, h);\n    for (const s of st.stars) {\n      ctx.globalAlpha = s.a;\n      ctx.fillStyle = \"#e8ecf5\";\n      ctx.fillRect(s.x, s.y, s.s, s.s);\n    }\n    ctx.globalAlpha = 1;\n    SCENE.ring(ctx, st, t, false);\n    const { R, cx, cy } = st;\n    // The planet: lit from the upper left, with soft cloud belts and a dark limb.\n    ctx.save();\n    ctx.beginPath();\n    ctx.arc(cx, cy, R, 0, 6.2832);\n    ctx.clip();\n    const body = ctx.createRadialGradient(cx - R * 0.45, cy - R * 0.5, R * 0.1, cx, cy, R * 1.15);\n    body.addColorStop(0, SETTINGS.planet[0]);\n    body.addColorStop(0.55, SETTINGS.planet[1]);\n    body.addColorStop(1, SETTINGS.planet[2]);\n    ctx.fillStyle = body;\n    ctx.fillRect(cx - R, cy - R, R * 2, R * 2);\n    ctx.translate(cx, cy);\n    ctx.rotate(SETTINGS.tilt);\n    for (let i = -9; i <= 9; i++) {\n      const y = (i / 9) * R + Math.sin(i * 1.7 + t * 0.02) * 3;\n      ctx.fillStyle = i % 2 ? \"rgba(60,36,20,0.1)\" : \"rgba(255,236,200,0.06)\";\n      ctx.fillRect(-R * 1.2, y, R * 2.4, R * (0.05 + 0.04 * Math.abs(Math.sin(i * 2.3))));\n    }\n    ctx.rotate(-SETTINGS.tilt);\n    // Night side: the sun is up and to the left, so the lower right falls into shadow.\n    const night = ctx.createRadialGradient(-R * 0.55, -R * 0.6, R * 0.6, -R * 0.35, -R * 0.4, R * 2.1);\n    night.addColorStop(0, \"rgba(5,7,13,0)\");\n    night.addColorStop(0.55, \"rgba(5,7,13,0.55)\");\n    night.addColorStop(1, \"rgba(5,7,13,0.97)\");\n    ctx.fillStyle = night;\n    ctx.fillRect(-R, -R, R * 2, R * 2);\n    ctx.restore();\n    // A thin bright crescent on the lit edge.\n    ctx.strokeStyle = \"rgba(255,240,215,0.35)\";\n    ctx.lineWidth = 1.5;\n    ctx.beginPath();\n    ctx.arc(cx, cy, R - 0.75, Math.PI * 0.95, Math.PI * 1.6);\n    ctx.stroke();\n    SCENE.ring(ctx, st, t, true);\n  },\n};\n\n// Runs a scene on a canvas: sizes it to the block, pauses off screen and in hidden tabs, cleans up after itself.\nfunction runScene(root: any, canvas: any, scene: any, reduced: boolean) {\n  const ctx = canvas.getContext(\"2d\");\n  if (!ctx) return () => {};\n  let w = 0;\n  let h = 0;\n  let st: any = null;\n  let raf = 0;\n  let last = 0;\n  let acc = 0;\n  let onScreen = true;\n  let time = reduced ? (scene.still ?? scene.start ?? 0) : (scene.start ?? 0);\n  const ptr: any = { x: 0, y: 0, on: false, down: 0 };\n  const step = 1 / (scene.fps || 60);\n  const resize = () => {\n    const r = root.getBoundingClientRect();\n    const nw = Math.max(1, Math.round(r.width));\n    const nh = Math.max(1, Math.round(r.height));\n    if (nw === w && nh === h && st) return;\n    w = nw;\n    h = nh;\n    // Device pixels are capped at 1.5 and scaled by the scene's own quality factor.\n    const d = Math.min(window.devicePixelRatio || 1, 1.5) * (scene.scale || 1);\n    canvas.width = Math.max(1, Math.round(w * d));\n    canvas.height = Math.max(1, Math.round(h * d));\n    ctx.setTransform(canvas.width / w, 0, 0, canvas.height / h, 0, 0);\n    st = scene.init(ctx, w, h, canvas.width / w);\n    scene.draw(ctx, w, h, time, st, ptr, 0);\n  };\n  const tick = (now: number) => {\n    raf = requestAnimationFrame(tick);\n    const dt = last ? Math.min(0.1, (now - last) / 1000) : step;\n    last = now;\n    acc += dt;\n    if (acc < step * 0.95) return;\n    const used = Math.min(acc, 0.1);\n    acc = 0;\n    time += used;\n    scene.draw(ctx, w, h, time, st, ptr, used);\n  };\n  const play = () => {\n    if (raf || reduced || !onScreen || document.hidden) return;\n    last = 0;\n    raf = requestAnimationFrame(tick);\n  };\n  const stop = () => {\n    cancelAnimationFrame(raf);\n    raf = 0;\n  };\n  const ro = new ResizeObserver(resize);\n  ro.observe(root);\n  const io = new IntersectionObserver((entries: any) => {\n    onScreen = entries[0].isIntersecting;\n    if (onScreen) play();\n    else stop();\n  });\n  io.observe(root);\n  const onVis = () => (document.hidden ? stop() : play());\n  const onMove = (e: any) => {\n    const r = root.getBoundingClientRect();\n    ptr.x = e.clientX - r.left;\n    ptr.y = e.clientY - r.top;\n    ptr.on = true;\n  };\n  const onLeave = () => {\n    ptr.on = false;\n  };\n  const onDown = (e: any) => {\n    onMove(e);\n    ptr.down += 1;\n  };\n  document.addEventListener(\"visibilitychange\", onVis);\n  root.addEventListener(\"pointermove\", onMove);\n  root.addEventListener(\"pointerleave\", onLeave);\n  root.addEventListener(\"pointerdown\", onDown);\n  resize();\n  play();\n  return () => {\n    stop();\n    ro.disconnect();\n    io.disconnect();\n    document.removeEventListener(\"visibilitychange\", onVis);\n    root.removeEventListener(\"pointermove\", onMove);\n    root.removeEventListener(\"pointerleave\", onLeave);\n    root.removeEventListener(\"pointerdown\", onDown);\n  };\n}\n\nexport default function RingedPlanetBackground() {\n  const rootRef = useRef<HTMLElement>(null);\n  const canvasRef = useRef<HTMLCanvasElement>(null);\n  useEffect(() => {\n    const root = rootRef.current;\n    const canvas = canvasRef.current;\n    if (!root || !canvas) return;\n    // Visitors who prefer reduced motion get one settled frame and no loop.\n    const reduced = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    return runScene(root, canvas, SCENE, reduced);\n  }, []);\n\n  return (\n    <section ref={rootRef} className=\"relative h-[660px] w-full overflow-hidden bg-[#05070d] text-[#f1f2f6]\">\n      <canvas ref={canvasRef} aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 block h-full w-full\" />\n      <div className=\"relative z-10 mx-auto flex h-full max-w-6xl flex-col justify-start items-start text-left px-6 py-14 sm:px-10\">\n        <div className=\"max-w-xl\">\n          <p className=\"text-xs font-semibold uppercase tracking-[0.2em] text-[#ead9bc]\">Perihelion Observatory</p>\n          <h2 className=\"mt-4 text-4xl font-semibold leading-[1.05] tracking-tight sm:text-5xl lg:text-6xl\">Public nights under a dark sky.</h2>\n          <p className=\"mt-5 text-base leading-relaxed text-[#c4c9d6] sm:text-lg\">Look through the big telescope on the ridge every clear Friday, with an astronomer at the eyepiece.</p>\n          <a href=\"#\" className=\"mt-8 inline-flex h-12 items-center rounded-[6px] bg-[#ead9bc] px-6 text-sm font-semibold text-[#14100a] transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#ead9bc] focus-visible:ring-offset-2 focus-visible:ring-offset-[#05070d]\">Book a viewing night</a>\n        </div>\n      </div>\n    </section>\n  );\n}\n"}]}
