SVG动画案例库
浏览精选的SVG动画案例
移开即停止播放
```javascript
'use client';
import React, { useState, useEffect, useMemo, useRef } from 'react';
// --- 常量配置 ---
const VIEW_WIDTH = 1000;
const VIEW_HEIGHT = 600;
const COLORS = {
bg: '#0f172a', // Slate 900
grid: '#1e293b', // Slate 800
primary: '#06b6d4', // Cyan 500
secondary: '#8b5cf6',// Violet 500
accent: '#f43f5e', // Rose 500
success: '#10b981', // Emerald 500
warning: '#f59e0b', // Amber 500
textMain: '#f8fafc', // Slate 50
textDim: '#94a3b8', // Slat
显卡在计算机系统中负责渲染画面的完整工作流程,包括从CPU接
移开即停止播放
'use client';
import React, { useState, useEffect, useMemo, useRef } from 'react';
const VIEW_WIDTH = 1000;
const VIEW_HEIGHT = 600;
const COLORS = {
bg: '#0f172a',
primary: '#06b6d4', // Cyan
secondary: '#8b5cf6', // Violet
accent: '#f43f5e', // Rose
text: '#e2e8f0',
grid: '#1e293b',
terminal: '#10b981' // Emerald
};
const STAGES = [
{
id: 'cpu',
title: '1. CPU 指令与数据',
desc: 'CPU 发送 Draw Call,准备顶点数据 (Vertices)',
tech: 'Command Buffer / Input Assembler'
},
显卡在计算机系统中负责渲染画面的完整工作流程,包括从CPU接
移开即停止播放
'use client';
import React, { useState, useEffect, useRef } from 'react';
const VIEW_WIDTH = 1000;
const VIEW_HEIGHT = 600;
const NODE_WIDTH = 120;
const NODE_HEIGHT = 60;
const GAP = 80;
// 辅助函数:生成随机地址字符串
const randomAddr = () => `0x${Math.floor(Math.random() * 0xffff).toString(16).toUpperCase().padStart(4, '0')}`;
export const LinkedListInsertion = () => {
// 定义初始节点数据
const initialList = [
{ id: 'head', val: 10, x: 100, y: 300, addr: '0x10A4', nextAddr: '0x20B8' },
{ id: 'n2',
链表插入节点的动画
移开即停止播放
```javascript
'use client';
import React, { useState, useEffect, useMemo } from 'react';
// 视图常量
const VIEW_WIDTH = 800;
const VIEW_HEIGHT = 600;
const CENTER_X = VIEW_WIDTH / 2;
const CENTER_Y = VIEW_HEIGHT / 2 - 20;
// 几何常量 (勾股数 3-4-5 的倍数)
const A = 120; // 短边
const B = 160; // 长边
const C = 200; // 斜边
const BOX_SIZE = A + B; // 280
// 动画阶段定义
const PHASES = {
INIT: 0,
SHOW_C: 1,
TRANSITION: 2,
SHOW_AB: 3,
FORMULA: 4,
};
export const PythagoreanTheoremView = () => {
const [phase
创建一个证明勾股定理的动画
移开即停止播放
'use client';
import React, { useState, useEffect, useRef, useMemo } from 'react';
// --- Types & Constants ---
type Node = {
id: number;
value: number;
x: number;
y: number;
left?: number;
right?: number;
parent?: number;
depth: number;
};
type Edge = {
from: number;
to: number;
};
const VIEW_WIDTH = 1000;
const VIEW_HEIGHT = 700;
const NODE_RADIUS = 22;
const ANIMATION_DELAY = 700;
// Colors
const COLORS = {
bg: '#0f172a', // Slate 900
nodeDefault: '#334155', // Sl
模拟一个二叉树遍历的过程,节点被访问的时候有颜色变化。可以选
移开即停止播放
```javascript
'use client';
import React, { useState, useEffect, useRef, useMemo } from 'react';
const VIEW_WIDTH = 1000;
const VIEW_HEIGHT = 600;
// -----------------------------------------------------------------------------
// CONSTANTS & CONFIGURATION
// -----------------------------------------------------------------------------
const PHASES = {
SOIL: { id: 0, text: '虫卵随粪便排出,在土壤中休眠', duration: 3000 },
INGEST: { id: 1, text: '不洗手抓取食物,虫卵被吞下', duration: 2500 },
HATCH: { id: 2, text
模拟一个人感染蛔虫的过程,卵随人类粪便排出后,可以在土壤中休
移开即停止播放
'use client';
import React, { useState, useEffect, useRef, useMemo } from 'react';
const VIEW_WIDTH = 800;
const VIEW_HEIGHT = 600;
const GROUND_Y = 550;
const ROD_WIDTH = 300;
const ROD_HEIGHT = 40;
// Helper: Random range
const random = (min: number, max: number) => Math.random() * (max - min) + min;
// Type definitions
interface Particle {
id: number;
x: number;
y: number;
vx: number;
vy: number;
rotation: number;
vr: number; // angular velocity
color: string;
scale: num
摩擦后从地面吸起小子条
移开即停止播放
import React, { useState, useEffect, useRef, useMemo } from 'react';
const VIEW_WIDTH = 800;
const VIEW_HEIGHT = 600;
// 粒子/纸屑类型定义
interface Scrap {
id: number;
x: number;
y: number;
rotation: number;
color: string;
vx: number;
vy: number;
isStuck: boolean;
stuckOffsetX: number;
stuckOffsetY: number;
mass: number;
}
interface Electron {
id: number;
x: number;
y: number;
targetX: number;
targetY: number;
progress: number;
speed: number;
}
export const Elect
静电摩擦吸附演示 准备材料 塑料直尺 / 梳子、羊毛衫 /
广告
Ads移开即停止播放
'use client';
import React, { useState, useEffect, useRef, useMemo } from 'react';
const VIEW_WIDTH = 1000;
const VIEW_HEIGHT = 600;
const MAX_WAVE_POINTS = 600;
const SPEED = 0.015;
export const FourierSeriesView = () => {
// Animation state
const [time, setTime] = useState(0);
const [nTerms, setNTerms] = useState(1);
const [wavePath, setWavePath] = useState<{x: number, y: number}[]>([]);
// Refs for animation loop logic to avoid closure staleness
const timeRef = useRef(0);
the principle of Fourier serie
移开即停止播放
'use client';
import React, { useState, useEffect, useMemo } from 'react';
const VIEW_WIDTH = 1000;
const VIEW_HEIGHT = 600;
// x86 Stack Visualization Component
export const X86StackAnimation = () => {
// Animation State
const [stepIndex, setStepIndex] = useState(0);
const [isPlaying, setIsPlaying] = useState(true);
// Simulation Data Definitions
type StackItem = {
id: string;
addr: number;
label: string; // Human readable content
value: string; // Hex/Value
ty
x86下C语言函数调用过程堆栈的变化
移开即停止播放
'use client';
import React, { useState, useEffect, useRef } from 'react';
const VIEW_WIDTH = 1000;
const VIEW_HEIGHT = 600;
// 颜色定义 - 赛博朋克/科技风格
const COLORS = {
bg: '#0f172a',
codeBg: '#1e293b',
objectBg: '#334155',
accent: '#38bdf8', // 天蓝
highlight: '#f472b6', // 粉色
vptr: '#a3e635', // 酸橙绿
text: '#e2e8f0',
dimText: '#64748b',
path: '#475569',
gold: '#fbbf24'
};
export const VTableMechanismView = () => {
const [step, setStep] = useState(0);
const totalSteps = 6;