Prestasi
Perlu perhatianKadar bingkai: purata 52.3 fps, p5 29.9 · Tugas panjang: 0 tugas, jumlah 0 ms, terpanjang 0 ms · Sumber gzip 7.8 KB · Masa jalan 186 KB
Boids EcosystemMITCorakAnimata
Komponen React Corak oleh Animata. Dikumpul tanpa ubahan daripada Animata di bawah lesen MIT dan dipaparkan secara langsung di sini.
Laporan kualiti
Gred dan skor datang daripada pemeriksaan automatik semasa binaan atau ujian. Jika suatu pemeriksaan tidak dijalankan, ia ditanda Belum diuji — nombor tidak pernah direka.
Kadar bingkai: purata 52.3 fps, p5 29.9 · Tugas panjang: 0 tugas, jumlah 0 ms, terpanjang 0 ms · Sumber gzip 7.8 KB · Masa jalan 186 KB
Isu 0 · Pembaca skrin: Perlu perhatian
Menghormati gerakan dikurangkan
Tidak melimpah
Angka kadar bingkai dan tugas panjang diukur dalam Chromium tanpa paparan dengan WebGL perisian. Ia hanya boleh dibandingkan antara komponen di laman ini, dan tidak mewakili peranti sebenar.
Tiada pelanggaran axe-core.

Disemak 15 Nov 2026 · Angka datang daripada skrip automatik, bukan sampel tulisan tangan.
Dipaparkan pada saiz sebenar.
Salinan bermula dengan notis lesen. Kekalkannya apabila anda menggunakan kod.
<div id="root"></div>:root{--bg:#f6f4f0;--ink:#17181a;--background:40 20% 96%;--foreground:24 10% 8%;--card:0 0% 100%}html,body{min-height:100%;margin:0;background:var(--bg);color:var(--ink)}html,body{height:100%;overflow:hidden}body{display:grid;place-items:center}#root{display:grid;place-items:center;max-width:100%;max-height:100%;box-sizing:border-box;padding:16px;color:hsl(var(--foreground))}#root.full{width:100%;height:100%;padding:0}@media(prefers-reduced-motion:reduce){*,*::before,*::after{animation-play-state:paused!important;transition-duration:0s!important}}
/*! tailwindcss v4.3.5 | MIT License | https://tailwindcss.com */
@layer properties{@supports (((-webkit-hyphens:none)) and (not (margin-trim:block))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--tw-border-style:solid;--tw-font-weight:initial;--tw-tracking:initial;--tw-blur:initial;--tw-brightness:initial;--tw-contrast:initial;--tw-grayscale:initial;--tw-hue-rotate:initial;--tw-invert:initial;--tw-opacity:initial;--tw-saturate:initial;--tw-sepia:initial;--tw-drop-shadow:initial;--tw-drop-shadow-color:initial;--tw-drop-shadow-alpha:100%;--tw-drop-shadow-size:initial;--tw-animation-delay:0s;--tw-animation-direction:normal;--tw-animation-duration:initial;--tw-animation-fill-mode:none;--tw-animation-iteration-count:1;--tw-enter-blur:0;--tw-enter-opacity:1;--tw-enter-rotate:0;--tw-enter-scale:1;--tw-enter-translate-x:0;--tw-enter-translate-y:0;--tw-exit-blur:0;--tw-exit-opacity:1;--tw-exit-rotate:0;--tw-exit-scale:1;--tw-exit-translate-x:0;--tw-exit-translate-y:0}}}@layer theme{:root,:host{--font-sans:-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";--font-mono:"Paper Mono", ui-monospace, monospace;--color-yellow-300:oklch(90.5% .182 98.111);--color-yellow-500:oklch(79.5% .184 86.047);--color-blue-300:oklch(80.9% .105 251.813);--color-blue-500:oklch(62.3% .214 259.815);--color-zinc-200:oklch(92% .004 286.32);--color-zinc-700:oklch(37% .013 285.805);--color-zinc-950:oklch(14.1% .005 285.823);--color-white:#fff;--spacing:.25rem;--text-base:1rem;--text-base--line-height:calc(1.5 / 1);--text-xl:1.25rem;--text-xl--line-height:calc(1.75 / 1.25);--font-weight-medium:500;--font-weight-semibold:600;--tracking-tight:-.025em;--radius-lg:var(--radius);--ease-out:cubic-bezier(.22, 1, .36, 1);--default-font-family:var(--font-sans);--default-mono-font-family:var(--font-mono);--color-border:hsl(var(--border));--color-background:hsl(var(--background));--color-foreground:hsl(var(--foreground));--color-muted:hsl(var(--muted));--ease-apple:cubic-bezier(.4, 0, .6, 1)}}@layer base{*,:after,:before,::backdrop{box-sizing:border-box;border:0 solid;margin:0;padding:0}::file-selector-button{box-sizing:border-box;border:0 solid;margin:0;padding:0}html,:host{-webkit-text-size-adjust:100%;tab-size:4;line-height:1.5;font-family:var(--default-font-family,-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji");font-feature-settings:var(--default-font-feature-settings,normal);font-variation-settings:var(--default-font-variation-settings,normal);-webkit-tap-highlight-color:transparent}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;-webkit-text-decoration:inherit;-webkit-text-decoration:inherit;-webkit-text-decoration:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:var(--default-mono-font-family,ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace);font-feature-settings:var(--default-mono-font-feature-settings,normal);font-variation-settings:var(--default-mono-font-variation-settings,normal);font-size:1em}small{font-size:80%}sub,sup{vertical-align:baseline;font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}:-moz-focusring:where(:not(iframe)){outline:auto}progress{vertical-align:baseline}summary{display:list-item}ol,ul,menu{list-style:none}img,svg,video,canvas,audio,iframe,embed,object{vertical-align:middle;display:block}img,video{max-width:100%;height:auto}button,input,select,optgroup,textarea{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}::file-selector-button{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}:where(select:is([multiple],[size])) optgroup{font-weight:bolder}:where(select:is([multiple],[size])) optgroup option{padding-inline-start:20px}::file-selector-button{margin-inline-end:4px}::placeholder{opacity:1}@supports (not ((-webkit-appearance:-apple-pay-button))) or (contain-intrinsic-size:1px){::placeholder{color:currentColor}@supports (color:color-mix(in lab, red, red)){::placeholder{color:color-mix(in oklab, currentcolor 50%, transparent)}}}textarea{resize:vertical}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-date-and-time-value{min-height:1lh;text-align:inherit}::-webkit-datetime-edit{display:inline-flex}::-webkit-datetime-edit-fields-wrapper{padding:0}::-webkit-datetime-edit{padding-block:0}::-webkit-datetime-edit-year-field{padding-block:0}::-webkit-datetime-edit-month-field{padding-block:0}::-webkit-datetime-edit-day-field{padding-block:0}::-webkit-datetime-edit-hour-field{padding-block:0}::-webkit-datetime-edit-minute-field{padding-block:0}::-webkit-datetime-edit-second-field{padding-block:0}::-webkit-datetime-edit-millisecond-field{padding-block:0}::-webkit-datetime-edit-meridiem-field{padding-block:0}::-webkit-calendar-picker-indicator{line-height:1}:-moz-ui-invalid{box-shadow:none}button,input:where([type=button],[type=reset],[type=submit]){appearance:button}::file-selector-button{appearance:button}::-webkit-inner-spin-button{height:auto}::-webkit-outer-spin-button{height:auto}[hidden]:where(:not([hidden=until-found])){display:none!important}*{border-color:var(--color-border)}body{background-color:var(--color-background);color:var(--color-foreground)}:root{--background:0 0% 100%;--foreground:0 0% 11%;--card:0 0% 100%;--card-foreground:0 0% 11%;--popover:0 0% 100%;--popover-foreground:0 0% 11%;--primary:0 0% 11%;--primary-foreground:0 0% 100%;--secondary:0 0% 96%;--secondary-foreground:0 0% 11%;--muted:0 0% 96%;--muted-foreground:0 0% 43%;--accent:262 83% 58%;--accent-foreground:0 0% 100%;--destructive:0 84% 60%;--destructive-foreground:0 0% 98%;--border:0 0% 90%;--input:0 0% 90%;--ring:262 83% 58%;--radius:.75rem;--surface-alt:0 0% 96%;--surface-card:0 0% 100%;--surface-dark:0 0% 7%;--text-secondary:0 0% 43%;--ink:#76756f;--ink-faint:#e3e3e3;--link:210 100% 40%;--link-hover:210 100% 32%;--shadow-sm:0 1px 2px #0000000d;--shadow-md:0 2px 8px #0000000f, 0 4px 16px #0000000a;--shadow-lg:0 4px 12px #0000000f, 0 12px 32px #00000014;--footer-surface:#f5f5f7;--footer-ink:#0f1d42;--footer-ink-muted:#1a2d5c;--footer-accent:#1a4fff;--footer-gold:#fc0;--footer-category-title:#1d1d1f;--footer-category-link:#515154;--footer-stamp:#9f9f9f}.dark{--background:0 0% 0%;--foreground:0 0% 96%;--card:0 0% 4%;--card-foreground:0 0% 96%;--popover:0 0% 4%;--popover-foreground:0 0% 96%;--primary:0 0% 96%;--primary-foreground:0 0% 0%;--secondary:0 0% 10%;--secondary-foreground:0 0% 96%;--muted:0 0% 10%;--muted-foreground:0 0% 45%;--accent:262 83% 65%;--accent-foreground:0 0% 100%;--destructive:0 62% 30%;--destructive-foreground:0 0% 98%;--border:0 0% 12%;--input:0 0% 12%;--ring:262 83% 65%;--surface-alt:0 0% 4%;--surface-card:0 0% 6%;--surface-dark:0 0% 2%;--text-secondary:0 0% 55%;--ink:#e3e3e3;--ink-faint:#76756f;--link:262 80% 70%;--link-hover:262 80% 80%;--shadow-sm:none;--shadow-md:none;--shadow-lg:none;--footer-surface:#1d1d1f;--footer-ink:#f5f5f7;--footer-ink-muted:#86868b;--footer-accent:#fc0;--footer-gold:#fc0;--footer-category-title:#f5f5f7;--footer-category-link:#86868b;--footer-stamp:#48484a}}@layer components{.text-animator-demo .text-animation-stage,[data-text-animator-demo] .text-animation-stage{perspective:900px;padding:clamp(1rem,5cqi,1.5rem);font-size:clamp(1rem,10cqi,2rem);font-weight:500;line-height:1.1}.text-animator-demo .text-animation-title,.text-animator-demo .text-animation-kinetic-word,[data-text-animator-demo] .text-animation-title,[data-text-animator-demo] .text-animation-kinetic-word{text-align:center;letter-spacing:-.025em}.text-animator-demo .text-animation-title,[data-text-animator-demo] .text-animation-title{text-wrap:balance;font-variant-numeric:tabular-nums}}@layer utilities{.pointer-events-none{pointer-events:none}.step{counter-increment:step}.step:before{height:calc(var(--spacing) * 9);width:calc(var(--spacing) * 9);border-style:var(--tw-border-style);border-width:4px;border-color:var(--color-background);background-color:var(--color-muted);text-align:center;text-indent:-1px;font-family:var(--font-mono);font-size:var(--text-base);line-height:var(--tw-leading,var(--text-base--line-height));--tw-font-weight:var(--font-weight-medium);font-weight:var(--font-weight-medium);content:counter(step);border-radius:2147483647px;justify-content:center;align-items:center;margin-top:-4px;margin-left:-50px;display:inline-flex;position:absolute}.absolute{position:absolute}.relative{position:relative}.inset-0{inset:0}.z-10{z-index:10}.flex{display:flex}.h-96{height:calc(var(--spacing) * 96)}.h-full{height:100%}.w-full{width:100%}.resize{resize:both}.items-center{align-items:center}.justify-center{justify-content:center}.overflow-hidden{overflow:hidden}.rounded-lg{border-radius:var(--radius-lg)}.text-center{text-align:center}.text-xl{font-size:var(--text-xl);line-height:var(--tw-leading,var(--text-xl--line-height))}.font-semibold{--tw-font-weight:var(--font-weight-semibold);font-weight:var(--font-weight-semibold)}.tracking-tight{--tw-tracking:var(--tracking-tight);letter-spacing:var(--tracking-tight)}.text-white\/90{color:#ffffffe6}@supports (color:color-mix(in lab, red, red)){.text-white\/90{color:color-mix(in oklab, var(--color-white) 90%, transparent)}}.blur{--tw-blur:blur(8px);filter:var(--tw-blur, ) var(--tw-brightness, ) var(--tw-contrast, ) var(--tw-grayscale, ) var(--tw-hue-rotate, ) var(--tw-invert, ) var(--tw-saturate, ) var(--tw-sepia, ) var(--tw-drop-shadow, )}@keyframes orbit-move{0%{transform:translate(-50%,-50%)rotateY(-40deg)rotateX(70deg)rotate(0)translate(100px)}to{transform:translate(-50%,-50%)rotateY(-40deg)rotateX(70deg)rotate(360deg)translate(100px)}}@keyframes counter-rotate{0%{opacity:1;transform:rotate(0)rotateX(-70deg)rotateY(40deg)scale(1)}25%{opacity:1;transform:rotate(-90deg)rotateX(-70deg)rotateY(40deg)scale(1.2)}50%{opacity:.3;transform:rotate(-180deg)rotateX(-70deg)rotateY(40deg)scale(.8)}75%{opacity:.3;transform:rotate(-270deg)rotateX(-70deg)rotateY(40deg)scale(.8)}to{opacity:1;transform:rotate(-360deg)rotateX(-70deg)rotateY(40deg)scale(1)}}@keyframes orbit-indexes{0%,25%,to{z-index:11}50%,99%{z-index:9}}}@property --tw-animation-delay{syntax:"*";inherits:false;initial-value:0s}@property --tw-animation-direction{syntax:"*";inherits:false;initial-value:normal}@property --tw-animation-duration{syntax:"*";inherits:false}@property --tw-animation-fill-mode{syntax:"*";inherits:false;initial-value:none}@property --tw-animation-iteration-count{syntax:"*";inherits:false;initial-value:1}@property --tw-enter-blur{syntax:"*";inherits:false;initial-value:0}@property --tw-enter-opacity{syntax:"*";inherits:false;initial-value:1}@property --tw-enter-rotate{syntax:"*";inherits:false;initial-value:0}@property --tw-enter-scale{syntax:"*";inherits:false;initial-value:1}@property --tw-enter-translate-x{syntax:"*";inherits:false;initial-value:0}@property --tw-enter-translate-y{syntax:"*";inherits:false;initial-value:0}@property --tw-exit-blur{syntax:"*";inherits:false;initial-value:0}@property --tw-exit-opacity{syntax:"*";inherits:false;initial-value:1}@property --tw-exit-rotate{syntax:"*";inherits:false;initial-value:0}@property --tw-exit-scale{syntax:"*";inherits:false;initial-value:1}@property --tw-exit-translate-x{syntax:"*";inherits:false;initial-value:0}@property --tw-exit-translate-y{syntax:"*";inherits:false;initial-value:0}.preview{margin-bottom:calc(var(--spacing) * 4)}.preview-light{background-color:#fefefe;background-image:radial-gradient(#efefef 1px,#0000 1px),radial-gradient(#efefef 1px,#0000 1px);background-position:0 0,10px 10px;background-size:20px 20px}.preview-dark{background-image:radial-gradient(#6a6a6a 1px,#0000 1px),radial-gradient(#6a6a6a 1px,#0000 1px);background-position:0 0,10px 10px;background-size:20px 20px}.component-list-item{border-color:var(--color-zinc-200);background-color:#fefefe;background-image:radial-gradient(#efefef 1px,#0000 1px),radial-gradient(#efefef 1px,#0000 1px);background-position:0 0,10px 10px;background-size:20px 20px}.dark .component-list-item{border-color:var(--color-zinc-700);background-color:var(--color-zinc-950);background-image:radial-gradient(#6a6a6a 1px,#0000 1px),radial-gradient(#6a6a6a 1px,#0000 1px);background-position:0 0,10px 10px;background-size:20px 20px}[style*="opacity: 1"]>.scroll-baby{color:var(--color-yellow-300)}[style*="opacity: 1"]>.scroll-baby:where(.dark,.dark *){color:var(--color-yellow-500)}[style*="opacity: 1"]>.scroll-file{color:var(--color-blue-300)}[style*="opacity: 1"]>.scroll-file:where(.dark,.dark *){color:var(--color-blue-500)}@property --tw-border-style{syntax:"*";inherits:false;initial-value:solid}@property --tw-font-weight{syntax:"*";inherits:false}@property --tw-tracking{syntax:"*";inherits:false}@property --tw-blur{syntax:"*";inherits:false}@property --tw-brightness{syntax:"*";inherits:false}@property --tw-contrast{syntax:"*";inherits:false}@property --tw-grayscale{syntax:"*";inherits:false}@property --tw-hue-rotate{syntax:"*";inherits:false}@property --tw-invert{syntax:"*";inherits:false}@property --tw-opacity{syntax:"*";inherits:false}@property --tw-saturate{syntax:"*";inherits:false}@property --tw-sepia{syntax:"*";inherits:false}@property --tw-drop-shadow{syntax:"*";inherits:false}@property --tw-drop-shadow-color{syntax:"*";inherits:false}@property --tw-drop-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-drop-shadow-size{syntax:"*";inherits:false}// animata source (MIT). npm i clsx react tailwind-merge · Tailwind CSS v4
// ── animata/background/boids-ecosystem.tsx (https://github.com/codse/animata/blob/25c27e5a874c60a56dcc1609df3b2c4f5f8456f8/animata/background/boids-ecosystem.tsx)
"use client";
import { type RefObject, useEffect, useRef } from "react";
import { cn } from "@/lib/utils";
export interface BoidAgent {
x: number;
y: number;
vx: number;
vy: number;
color: string;
}
/**
* Force point that pulls boids toward (x, y). Coordinates are normalized 0..1
* across the canvas, so callers don't need to know the canvas pixel size.
*/
export interface BoidAttractor {
x: number;
y: number;
/** 0 = no pull, 0.05 = gentle, 0.15 = strong. Default 0.05. */
strength?: number;
/** Pixel radius of influence. Default 220. */
radius?: number;
}
interface BoidsEcosystemProps {
count?: number;
background?: string;
palette?: string[];
cursorRadius?: number;
/** Force points the flock is drawn toward. Read live, safe to mutate by ref. */
attractors?: BoidAttractor[];
/**
* Receives the live agents array on mount. Mutate-in-place by the simulation;
* read positions from animation frames in the parent (do NOT trigger React state from this).
*/
agentsRef?: RefObject<BoidAgent[] | null>;
/** Triangle reads as flock; dot reads as ambient activity. */
agentShape?: "triangle" | "dot";
className?: string;
children?: React.ReactNode;
}
const DEFAULT_PALETTE = ["#f5f5f4", "#fde68a", "#93c5fd", "#fca5a5"];
export default function BoidsEcosystem({
count = 120,
background = "#0b0b12",
palette = DEFAULT_PALETTE,
cursorRadius = 90,
attractors,
agentsRef,
agentShape = "triangle",
className,
children,
}: BoidsEcosystemProps) {
const canvasRef = useRef<HTMLCanvasElement>(null);
const cursorRef = useRef<{ x: number; y: number; active: boolean }>({
x: 0,
y: 0,
active: false,
});
// All non-`count` props read from this ref each frame, so prop changes
// don't tear down the simulation.
const liveRef = useRef({ background, palette, cursorRadius, attractors, agentShape });
liveRef.current = { background, palette, cursorRadius, attractors, agentShape };
useEffect(() => {
const canvas = canvasRef.current;
if (!canvas) return;
const ctx = canvas.getContext("2d");
if (!ctx) return;
const dpr = Math.min(window.devicePixelRatio || 1, 2);
const agents: BoidAgent[] = [];
const resize = () => {
const rect = canvas.getBoundingClientRect();
canvas.width = rect.width * dpr;
canvas.height = rect.height * dpr;
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
};
resize();
const ro = new ResizeObserver(resize);
ro.observe(canvas);
const w = () => canvas.width / dpr;
const h = () => canvas.height / dpr;
const initialPalette = liveRef.current.palette;
for (let i = 0; i < count; i++) {
const a = Math.random() * Math.PI * 2;
const s = 0.6 + Math.random() * 0.6;
agents.push({
x: Math.random() * w(),
y: Math.random() * h(),
vx: Math.cos(a) * s,
vy: Math.sin(a) * s,
color: initialPalette[Math.floor(Math.random() * initialPalette.length)],
});
}
if (agentsRef) agentsRef.current = agents;
const perception = 36;
const maxSpeed = 1.8;
let raf = 0;
const step = () => {
const { background: bg, cursorRadius: cr, attractors: atts } = liveRef.current;
const W = w();
const H = h();
ctx.fillStyle = `${bg}dd`;
ctx.fillRect(0, 0, W, H);
for (const a of agents) {
let ax = 0;
let ay = 0;
let sx = 0;
let sy = 0;
let cx = 0;
let cy = 0;
let n = 0;
for (const b of agents) {
if (a === b) continue;
const dx = b.x - a.x;
const dy = b.y - a.y;
const d2 = dx * dx + dy * dy;
if (d2 < perception * perception) {
ax += b.vx;
ay += b.vy;
cx += b.x;
cy += b.y;
if (d2 < 18 * 18 && d2 > 0.0001) {
const d = Math.sqrt(d2);
sx -= dx / d;
sy -= dy / d;
}
n++;
}
}
if (n > 0) {
a.vx += (ax / n - a.vx) * 0.04;
a.vy += (ay / n - a.vy) * 0.04;
a.vx += (cx / n - a.x) * 0.0006;
a.vy += (cy / n - a.y) * 0.0006;
a.vx += sx * 0.06;
a.vy += sy * 0.06;
}
if (atts?.length) {
for (const att of atts) {
const tx = att.x * W;
const ty = att.y * H;
const dx = tx - a.x;
const dy = ty - a.y;
const d = Math.hypot(dx, dy) || 1;
const radius = att.radius ?? 220;
if (d < radius) {
const f = ((radius - d) / radius) * (att.strength ?? 0.05);
a.vx += (dx / d) * f;
a.vy += (dy / d) * f;
}
}
}
if (cursorRef.current.active) {
const dx = a.x - cursorRef.current.x;
const dy = a.y - cursorRef.current.y;
const d = Math.hypot(dx, dy);
if (d < cr && d > 0) {
const f = (cr - d) / cr;
a.vx += (dx / d) * f * 0.6;
a.vy += (dy / d) * f * 0.6;
}
}
const sp = Math.hypot(a.vx, a.vy);
if (sp > maxSpeed) {
a.vx = (a.vx / sp) * maxSpeed;
a.vy = (a.vy / sp) * maxSpeed;
}
a.x += a.vx;
a.y += a.vy;
if (a.x < 0) a.x += W;
if (a.x > W) a.x -= W;
if (a.y < 0) a.y += H;
if (a.y > H) a.y -= H;
ctx.fillStyle = a.color;
ctx.globalAlpha = 0.88;
if (liveRef.current.agentShape === "dot") {
ctx.beginPath();
ctx.arc(a.x, a.y, 1.8, 0, Math.PI * 2);
ctx.fill();
} else {
const angle = Math.atan2(a.vy, a.vx);
ctx.save();
ctx.translate(a.x, a.y);
ctx.rotate(angle);
ctx.beginPath();
ctx.moveTo(6, 0);
ctx.lineTo(-4, 3);
ctx.lineTo(-4, -3);
ctx.closePath();
ctx.fill();
ctx.restore();
}
}
raf = requestAnimationFrame(step);
};
raf = requestAnimationFrame(step);
// Listen on window so events bubble through any overlay (links, content
// wrappers, etc.). Bounds-check inside the handler so the flock only
// reacts when the cursor is within the canvas itself.
const onMove = (e: PointerEvent) => {
const r = canvas.getBoundingClientRect();
const x = e.clientX - r.left;
const y = e.clientY - r.top;
cursorRef.current.x = x;
cursorRef.current.y = y;
cursorRef.current.active = x >= 0 && x <= r.width && y >= 0 && y <= r.height;
};
const onPageLeave = () => {
cursorRef.current.active = false;
};
window.addEventListener("pointermove", onMove);
document.documentElement.addEventListener("pointerleave", onPageLeave);
window.addEventListener("blur", onPageLeave);
return () => {
cancelAnimationFrame(raf);
ro.disconnect();
window.removeEventListener("pointermove", onMove);
document.documentElement.removeEventListener("pointerleave", onPageLeave);
window.removeEventListener("blur", onPageLeave);
if (agentsRef) agentsRef.current = null;
};
}, [count, agentsRef]);
return (
<div className={cn("relative h-full w-full overflow-hidden rounded-lg", className)}>
<canvas ref={canvasRef} className="absolute inset-0 h-full w-full" style={{ background }} />
{children && (
<div className="relative z-10 flex h-full items-center justify-center pointer-events-none">
{children}
</div>
)}
</div>
);
}
// ── lib/utils.ts (https://github.com/codse/animata/blob/25c27e5a874c60a56dcc1609df3b2c4f5f8456f8/lib/utils.ts)
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
export function absoluteUrl(path: string) {
return `${process.env.NEXT_PUBLIC_APP_URL}${path}`;
}
// Linear interpolation
export function lerp(a: number, b: number, n: number) {
return (1 - n) * a + n * b;
}
// Get distance between two points
export function getDistance(x1: number, y1: number, x2: number, y2: number) {
return Math.hypot(x2 - x1, y2 - y1);
}Kawalan · HTML · CSS · JS
Sunting kod dan laraskan dengan kawalan. Pratonton dikemas kini semasa anda menaip.

Komponen ini berjalan daripada binaan berpakej, jadi skripnya baca sahaja di sini. Sunting HTML dan CSS; sumber penuh ada dalam tab Kod.
Sunting setiap komponen secara langsung, laraskan dengan kawalan, muat turun sumber penuh dan salin prompt lanjutan.
$49 sekali bayarHarga sementara
Mod ujian: tiada bayaran sebenar dikenakan.
Percuma: pratonton, butang salin dan nota pelajaran.
120 ejen kecil berkumpul seperti burung di atas kanvas gelap dalam krim lembut, kuning, biru dan merah jambu, dan berselerak di sekeliling penunjuk anda.
Wira interaktif, halaman produk AI atau simulasi dan latar belakang yang menyeronokkan.
Tetapkan count (120), background (#0b0b12), palette, cursorRadius, attractors dan agentShape (segi tiga atau titik).
Tambahkan komponen "Latar belakang boids berbondong-bondong" daripada Animata (github.com/codse/animata) (MIT) ke aplikasi React + Tailwind CSS saya. Fail sumber: https://github.com/codse/animata/blob/25c27e5a874c60a56dcc1609df3b2c4f5f8456f8/animata/background/boids-ecosystem.tsx. 120 ejen kecil berkumpul seperti burung di atas kanvas gelap dalam krim lembut, kuning, biru dan merah jambu, dan berselerak di sekeliling penunjuk anda. Gunakan untuk: Wira interaktif, halaman produk AI atau simulasi dan latar belakang yang menyeronokkan. Tetapan untuk dilaras: Tetapkan count (120), background (#0b0b12), palette, cursorRadius, attractors dan agentShape (segi tiga atau titik). Sokong tema cerah dan gelap serta hormati prefers-reduced-motion. Kekalkan notis lesen MIT.
Prompt lebih panjang dengan langkah pelarasan, kebolehcapaian dan integrasi.