# Moon

The phase machine: a lunation whose crescent is the projection of the terminator circle rather than a drawn shape, with libration rocking the body so the limb craters come round and go again.

> For the complete index, see [llms.txt](https://robocn.dev/llms.txt). A Markdown version of any page is available by appending `.md` to its URL or by sending an `Accept: text/markdown` header.

## Install

```bash
bunx --bun shadcn@latest add https://robocn.dev/r/celestial-moon.json
```

Registry item: `celestial-moon` · [`https://robocn.dev/r/celestial-moon.json`](https://robocn.dev/r/celestial-moon.json)

## Notes

- A crescent drawn as two offset circles is nearly right at a crescent, wrong at a gibbous, and flips the wrong way at quarter. None of that is drawn here: the night side is the camera-facing half of the terminator great circle closed against the unlit half of the limb, so the flip happens because the geometry does it.
- Libration runs on a period of its own, which is why the near side is a range and not a fixed picture. Those ratios are illustrative rather than real periods, and the docs say so rather than the drawing implying otherwise.
- Each crater is a circle on the body, so it projects to an ellipse squashed toward the limb, and its floor sits on the side the light is not coming from — the same light the terminator was built from.
- Solved: the terminator and its projection, the lit fraction, the crater foreshortening and its shading, the libration frame, and the silhouette. Illustrated: the crater rim relief and the mare outlines.
- No ephemeris. `phase` is a number, not a date, and nothing here is a real body.

## Usage

```tsx
import { CelestialMoon } from "@/components/ui/celestial-moon"

<CelestialMoon behavior="cycle" craters={60} maria={3} />
<CelestialMoon phase={0.25} interactive onPhaseChange={setPhase} />
```

## Props

| name | type | default | description |
| --- | --- | --- | --- |
| `view` | `"plan" | "front" | "profile" | "iso"` | `"front"` | Where the camera stands. One body, four projections: straight down, straight on, side elevation, or three-quarter from above. |
| `phase` | `number` | — | Controlled lunation: 0 new, 0.25 first quarter, 0.5 full. Supplying it stops the loop. |
| `behavior` | `"cycle" | "libration" | "static"` | `"cycle"` | Cycle runs the lunation; libration holds near full, where the rocking is the only thing left to see. |
| `speed` | `number` | `0.09` | Lunations per second. |
| `animate` | `boolean` | `true` | Off parks the body at `offset` and stops rendering. A reduced-motion preference does the same. |
| `paused` | `boolean` | `false` | Freeze where it stands. |
| `offset` | `number` | `0` | Seconds of clock offset, so a row of them breaks step. Named `offset` because `phase` is the lunation. |
| `interactive` | `boolean` | `false` | Drag across it to scrub the lunation; arrows 2.5 percent, shift an eighth, Home new and End full. |
| `onPhaseChange` | `(phase: number) => void` | — | Fires on every drag and key press, in controlled mode too. |
| `craters` | `number` | `46` | Craters on the surface, clamped to 0..200. Placed on the body, so they ride the libration. |
| `maria` | `number` | `3` | Dark plains, clamped to 0..6. |
| `libration` | `number` | `1` | How far the body rocks, 0 locked to 1 full. |
| `tilt` | `number` | `5` | Degrees the pole leans out of vertical. |
| `seed` | `number` | `7` | Any integer. The same seed is the same face, every render. |
| `variant` | `"solid" | "outline" | "blueprint" | "wire"` | `"solid"` | How the machine is painted. Geometry never changes between variants. |
| `size` | `"xs" | "sm" | "md" | "lg" | "xl" | number` | `"md"` | Rendered width in pixels, or a step on the scale. |
| `signal` | `"idle" | "ready" | "warning"` | — | Status-lamp state using neutral, accent, or shell colour; each component documents its visual default in the demo. |
| `label` | `string` | — | Optional technical caption under the drawing. |
| `color` | `string` | `var(--robot-shell)` | Body panels — the colour the machine reads as. |
| `accent` | `string` | `var(--robot-accent)` | Status colour: tip light, live tool, readouts. |
| `metal` | `string` | `var(--robot-metal)` | Bare machined parts: collars, bolts, tool bodies. |
| `dark` | `string` | `var(--robot-dark)` | Cast joints, base, shadow side. |
| `palette` | `Partial<RobotPalette>` | — | Override any subset of roles at once, including glow and grid. |

## Source

- `src/components/ui/celestial-moon.tsx`
