asafefe.dev
Lab

Lab/18

Metaballs

Each blob adds to a smooth field, and the canvas fills wherever the sum crosses a threshold. One blob follows the pointer.

  • Canvas
  • Generative
Move to pull, click to add

Installation

Add Metaballs to your project with the shadcn CLI. The files land in components/lab, ready to edit.

$ pnpm dlx shadcn@latest add @soultel/lab-metaballs

Or by URL: https://asafefe.dev/r/lab-metaballs.json

Brings along

  • utils
  • @soultel/lab-canvas

Usage

example.tsx10 lines
import { Metaballs } from "@/components/lab/metaballs"

export function Hero() {
  return (
    <section className="relative h-[420px]">
      <Metaballs className="absolute inset-0" />
      <h1 className="relative">Hello</h1>
    </section>
  )
}

Props

PropTypeDefaultDescription
mode"smooth" | "pixel""smooth"Anti-aliased edges or chunky pixels.
colorstring"var(--primary)"Blob color.
backgroundstring"var(--background)"Solid color behind the blobs.
countnumber7Blobs on start.
maxBlobsnumber12Cap including clicked-in blobs.
scalenumber1Blob size relative to the shorter side.
followPointer / addOnClickbooleantruePointer follow and click to add.
refRef<MetaballsHandle>-reset() scatters a fresh set.