Thinking UI

Halo Rings

Thin rings of light ripple out from a dark core like sound waves, and drift inward while it listens.

Code

components/thinking-ui/orb-halo.tsx
"use client";

import { motion, useMotionValue, useSpring, useTransform } from "motion/react";
import { useEffect, useRef } from "react";
import { useMotion } from "@/lib/motion";
import { cn } from "@/lib/utils";
import { useShader } from "@/lib/webgl";

export type OrbHaloState = "idle" | "listening" | "thinking" | "speaking";

export type OrbHaloProps = {
  state?: OrbHaloState;
  /** Live audio level from 0 to 1. Omit it to use a simulated level. */
  level?: number;
  /** Size of the orb's box in px, or any CSS length. Rings ripple a little past it. */
  size?: number | string;
  className?: string;
};

// Pace of the ambient motion (idle ping, thinking arcs, ring wobble), per state
const SPEED: Record<OrbHaloState, number> = {
  idle: 0.5,
  listening: 0.8,
  thinking: 1.1,
  speaking: 1,
};

/* Thin rings of light around a dark core, in four layers that crossfade
   by state weight: one slow sonar ping (idle), rings drifting inward and
   fading into the core (listening), three still rings with comet arcs
   circling in alternate directions (thinking), and rings rippling outward
   whose radii wobble with the voice (speaking). uWave is a signed travel
   phase integrated on the CPU, so reversing direction never jumps.
   Rings use the ink color: light on dark themes, graphite on light ones.
   The host is 1.4× the orb's box, so 0.714 ≈ the box edge. */
const FRAGMENT = `
precision highp float;
uniform vec2 uResolution;
uniform float uT;
uniform float uWave;
uniform float uLevel;
uniform float uIdle;
uniform float uListen;
uniform float uThink;
uniform float uSpeak;
uniform vec3 uDark;
uniform vec3 uMid;
uniform vec3 uLight;
uniform vec3 uInk;

const float CORE = 0.33;
const float INNER = 0.37;
const float OUTER = 0.97;
const float TAU = 6.2831853;

// A thin anti-aliased line of half-width w with a faint glow around it
float ring(float d, float w, float px) {
  return 1.0 - smoothstep(w, w + px * 1.5, d) + 0.1 * exp(-d * d * 1400.0);
}

void main() {
  float res = min(uResolution.x, uResolution.y);
  vec2 p = (gl_FragCoord.xy * 2.0 - uResolution) / res;
  float px = 2.0 / res;
  float r = length(p);
  float a = atan(p.y, p.x);
  float w = max(px * 0.5, 0.0028);

  float light = 0.0;

  // Idle: one slow ping that leaves the core and fades as it widens
  float ping = fract(uT * 0.14);
  float pingR = mix(INNER, 0.86, sqrt(ping));
  light += uIdle * ring(abs(r - pingR), w, px) * smoothstep(0.0, 0.08, ping) * pow(1.0 - ping, 2.0) * 0.9;

  // Listening and speaking: rings travelling in or out
  float travel = uListen + uSpeak;
  if (travel > 0.001) {
    for (int i = 0; i < 6; i++) {
      float fi = float(i);
      float ph = fract(uWave + fi / 6.0);
      float wob = (0.006 + 0.012 * uListen + 0.07 * uLevel * uSpeak) * ph;
      wob *= sin(a * 3.0 + uT * 1.7 + fi * 2.1) * 0.6 + sin(a * 5.0 - uT * 2.3 + fi * 1.3) * 0.4;
      float rr = mix(INNER, OUTER, ph) + wob;
      float fade = smoothstep(0.0, 0.12, ph) * pow(1.0 - ph, 1.6);
      light += travel * ring(abs(r - rr), w, px) * fade * (0.6 + 0.6 * uLevel);
    }
  }

  // Thinking: three still rings, each with a comet arc chasing around it
  if (uThink > 0.001) {
    for (int i = 0; i < 3; i++) {
      float fi = float(i);
      float rr = INNER + 0.07 + fi * 0.1;
      float dir = fi == 1.0 ? -1.0 : 1.0;
      float head = uT * (1.6 - fi * 0.3) + fi * 2.1;
      float behind = mod((head - a * dir), TAU);
      float comet = exp(-behind * 1.5) * (1.0 - smoothstep(TAU - 0.12, TAU, behind));
      light += uThink * ring(abs(r - rr), w, px) * (0.14 + 0.95 * comet) * (1.0 - fi * 0.18);
    }
  }

  // A faint ring hugging the core, always there
  light += ring(abs(r - INNER), w, px) * (0.18 + 0.25 * uLevel);

  // The core: dark glass, lit softly from the top left, glowing with the voice
  float coreR = CORE * (1.0 + 0.05 * uLevel);
  float coreA = 1.0 - smoothstep(coreR - px, coreR + px, r);
  vec2 q = p / coreR;
  float key = clamp(1.0 - length(q - vec2(-0.4, 0.45)) * 0.75, 0.0, 1.0);
  vec3 core = mix(uDark * 0.5, uMid * 0.75, key * key * 0.55);
  core += uLight * (0.04 + 0.3 * uLevel * (uSpeak + 0.5 * uListen)) * pow(clamp(1.0 - length(q), 0.0, 1.0), 2.0);
  core += uLight * smoothstep(0.82, 1.0, length(q)) * 0.22;
  core = clamp(core, 0.0, 1.0);

  float ringA = clamp(light, 0.0, 1.0) * (1.0 - coreA);
  gl_FragColor = vec4(uInk * ringA + core * coreA * (1.0 - ringA), ringA + coreA * (1.0 - ringA));
}
`;

export function OrbHalo({ state = "idle", level, size = 120, className }: OrbHaloProps) {
  const m = useMotion();
  const reduce = m.reduce;
  const sim = useRef({
    clock: 0,
    time: 9.3,
    wave: 0.35,
    speed: SPEED[state],
    idle: Number(state === "idle"),
    listen: Number(state === "listening"),
    think: Number(state === "thinking"),
    speak: Number(state === "speaking"),
  });

  // The personality's emphasis spring decides how organic the pulse feels
  const rawLevel = useMotionValue(0);
  const { visualDuration, bounce } = m.personality.spring.emphasis;
  const smoothLevel = useSpring(rawLevel, { visualDuration: visualDuration * 0.5 * m.scale, bounce });
  const haloOpacity = useTransform(smoothLevel, [0, 1], [0.06, 0.26]);

  const { ref, ready, invalidate } = useShader({
    fragment: FRAGMENT,
    transparent: true,
    colors: { uDark: "--orb-1", uMid: "--orb-2", uLight: "--orb-3", uInk: "--text-primary" },
    uniforms: ({ delta }) => {
      const s = sim.current;
      const idle = Number(state === "idle");
      const listen = Number(state === "listening");
      const think = Number(state === "thinking");
      const speak = Number(state === "speaking");

      if (reduce) {
        // One still frame that still says which state it is in
        return { uT: 9.3, uWave: 0.35, uLevel: level ?? 0.15, uIdle: idle, uListen: listen, uThink: think, uSpeak: speak };
      }

      const dt = delta / m.scale;
      const ease = 1 - Math.exp(-dt * 2.5);
      s.clock += dt;
      s.speed += (SPEED[state] - s.speed) * ease;
      s.idle += (idle - s.idle) * ease;
      s.listen += (listen - s.listen) * ease;
      s.think += (think - s.think) * ease;
      s.speak += (speak - s.speak) * ease;
      s.time += s.speed * dt;

      const lvl = Math.max(0, smoothLevel.get());
      // Out with the voice (faster when louder), in while listening
      s.wave += (s.speak * (0.3 + 0.35 * lvl) - s.listen * 0.24) * dt;

      const ms = s.clock * 1000;
      const wobble = Math.abs(Math.sin(ms / 140) * Math.sin(ms / 53 + 1));
      const breathing = 0.08 * (0.5 + 0.5 * Math.sin(ms / 900));
      rawLevel.set(level ?? (state === "speaking" ? 0.2 + 0.8 * wobble : state === "listening" ? 0.1 + 0.35 * wobble : breathing));

      return { uT: s.time, uWave: s.wave, uLevel: lvl, uIdle: s.idle, uListen: s.listen, uThink: s.think, uSpeak: s.speak };
    },
    animate: () => !reduce,
  });

  // Restart the loop when reduced motion turns off; with it on, repaint the still frame
  useEffect(() => {
    invalidate();
  }, [reduce, state, level, invalidate]);

  return (
    <div
      role="img"
      aria-label={`Voice assistant ${state}`}
      className={cn("relative shrink-0", className)}
      style={{ width: size, height: size }}
    >
      {/* Soft halo that brightens with the voice */}
      <motion.div
        aria-hidden
        className="absolute -inset-[22%] rounded-full blur-2xl"
        style={{ opacity: haloOpacity, background: "radial-gradient(circle, var(--orb-3), transparent 65%)" }}
      />
      {/* Static fallback until (or unless) WebGL paints: just the core */}
      <div
        aria-hidden
        className={cn("absolute inset-[27%] rounded-full transition-opacity duration-(--motion-duration-slow)", ready && "opacity-0")}
        style={{ background: "radial-gradient(circle at 34% 28%, var(--orb-2), var(--orb-1) 60%)" }}
      />
      <div ref={ref} aria-hidden className="absolute -inset-[20%]" />
    </div>
  );
}

Motion notes

  • Direction carries meaning: rings travel outward while the assistant speaks and inward while it listens, so you can tell who has the floor at a glance.
  • Ring travel is one signed phase integrated every frame, so switching from listening to speaking slows the rings, stops them and reverses them, with no jump.
  • While speaking, each ring's radius wobbles with the level and gets wobblier as it spreads, the way sound distorts with distance. Louder speech also sends rings out faster.
  • Idle is a single slow ping and thinking is three still rings with comet arcs circling. The state layers crossfade by weight, so the orb never cuts between them. With reduced motion it renders one still frame.

Installation

  1. 1

    Install dependencies

    Terminal
    npm install motion clsx tailwind-merge
  2. 2

    Add the design tokens and motion system (once per project)

    Copy styles/tokens/*, lib/motion.tsx and lib/utils.ts, plus lib/webgl.ts from Get started.

  3. 3

    Paste the source into components/thinking-ui/orb-halo.tsx

    Copy it from the Code tab, or use Copy prompt to let your coding agent do all of this.

Usage

Example
<OrbHalo state="listening" level={micLevel} />

Props

PropTypeDefaultDescription
state"idle" | "listening" | "thinking" | "speaking""idle"Assistant state. Changes ease in over about half a second.
levelnumber—Audio level 0–1, e.g. from an AnalyserNode. Leave it out to simulate one per state.
sizenumber | string120Size of the orb's box in px, or any CSS length. The core is about half of it, and rings ripple about 35% past it.
classNamestring—Classes for the wrapper.