Power-User Systems

Rubiks Cube

A Rubik's cube that scrambles and solves itself on an endless loop while spinning like a planet. Two independent rotation layers, and every quarter-turn is quantised back to exact integers, so an hour of turns drifts by nothing at all.

Install

bun add three @react-three/fiber clsx tailwind-merge

Then copy 2 files into your project:

  • components/registry/rubiks-cube/rubiks-cube.tsx
  • lib/utils.ts

Props

PropTypeDefaultDescription
autoRotatebooleantrueSpin the whole cube on its own axis, independently of the solve loop. Off leaves the cube still while it keeps scrambling and solving.
rotationSpeednumber1Multiplier on the ambient spin rate. A drag re-aims the spin axis but never changes this — direction is yours, speed is the component's.
moveDurationnumber380How long one quarter-turn takes. The ease overshoots slightly and settles back, which is the mechanical click a real cube makes.
scrambleMoveCountnumber12Quarter-turns per scramble. The solve is this sequence replayed backwards and negated, so a longer scramble buys a longer solve for free.
pauseBetweenCyclesnumber700Beat of stillness between scramble and solve. Zero runs the two together into one continuous churn.
cameraDistancenumber11Orbit radius, which is what sets the cube's apparent size. Drag anywhere to orbit; elevation stops short of the poles so the cube never tumbles sideways.
gapnumber0.06Space between cubies, in cubie widths. Widen it and the black core shows through the seams, exactly as a real cube's does.
palette"classic" | "amethyst" | "mono" | "neon""classic"Named sticker scheme. The component also takes a `colors` record to override any individual face.
bodyColorstring (hex)"#16161c"Plastic behind the stickers, and the core seen through the seams.
backgroundstring (hex)"#0b0d14"The dark field the cube turns in.
glossybooleantrueWet-lacquer clearcoat plus a faint oil-slick sheen, lit by a small studio environment. Off leaves flat matte plastic.
glowbooleanfalseEmissive stickers plus an additive amethyst halo at the silhouette. Off by default: it is a flourish, not the point.

What It Demonstrates

Rotate
Spin an element around a point.
Orbit
An element circling around another in a continuous path.
Loop
An animation that repeats, a set number of times or infinitely.
Drag
Moving an element by grabbing it, often with momentum when released.
Easing
The rate at which an animation speeds up or slows down.
Idle animation
Subtle motion that plays while an element is just sitting there, waiting to be interacted with.

Related Components

Appears In