# Cross trainer

A crank and rocker whose footpad rides the coupler: the stride and the shape of the foot path are what the link lengths produce, not a traced ellipse.

> 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/cross-trainer.json
```

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

## Notes

- Solved: the path. The pedal arm is the coupler of a four-bar and the footpad is a point rigidly fixed on it, so what it draws is a coupler curve — closed, egg-shaped and not an ellipse. `trainerFootPath` samples the solved loop over a whole revolution.
- Solved: the stride. It is the horizontal extent of that curve, and the rise is its vertical extent. Neither is a prop; change a link length and both move, and so does the shape between them.
- Solved: the phase. The two sides are the same linkage half a revolution apart, and the grip is the swing arm carried on past its pivot — so arms and feet cannot drift out of step.
- Illustrated: there is no resistance model here at all. The flywheel is drawn, not spun — nothing computes inertia, brake torque or what the path costs. `rowing-erg` is the machine in this family that does dynamics.
- Design note: docs/gym-machines.md.

## Usage

```tsx
import { CrossTrainer } from "@/components/ui/cross-trainer"

// Runs its own stride.
<CrossTrainer behavior="stride" />

// Change a link length and the path changes shape, not just size.
<CrossTrainer crank={44} coupler={96} padAlong={150} />

// Or turn the crank by hand, which stops the loop.
<CrossTrainer crankAngle={140} onCrankAngleChange={setCrankAngle} interactive />
```

## Props

| name | type | default | description |
| --- | --- | --- | --- |
| `crankAngle` | `number` | — | Crank angle in degrees. Supplying it stops the loop. |
| `onCrankAngleChange` | `(crankAngle: number) => void` | — | Fires while it is dragged or keyed, so interaction works in controlled mode too. Dragging turns the wheel by its bearing about the crank centre. |
| `behavior` | `"stride" | "sprint" | "coast" | "static"` | `"stride"` | What it does with nobody driving it. `coast` is a run-down that slows without stopping. |
| `crank` | `number` | `36` | The driven link. A longer crank lengthens the stride — but not by twice it, because the linkage is what decides. |
| `coupler` | `number` | `80` | The pedal arm, between the crank pin and the swing arm. |
| `padAlong` | `number` | `140` | How far along the pedal arm the footpad is fixed. Past the coupler pin, so the arm is carried on and the path is amplified. |
| `showPath` | `boolean` | `true` | Draw the closed path the footpad actually follows. |
| `interactive` | `boolean` | `false` | Hand it to a person: drag across it, or focus it and use the arrow keys. It eases back into the behaviour on release. |
| `showGround` | `boolean` | `true` | Draw the contact shadow and the ground line beneath it. |
| `label` | `string` | — | Optional technical caption under the drawing. |
| `view` | `"plan" | "front" | "profile" | "iso"` | `"profile"` | Where the camera stands. One machine, four projections: straight down, straight on, side elevation, or three-quarter from above. |
| `speed` | `number` | `0.3` | Cycles per second. |
| `animate` | `boolean` | `true` | Off parks the machine at phase and stops rendering. A reduced-motion preference does the same. |
| `paused` | `boolean` | `false` | Freeze where it stands. |
| `phase` | `number` | `0` | Seconds of offset, so a row of machines breaks step. |
| `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. |
| `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/cross-trainer.tsx`
