跳到正文
Skillpedia
智能体101k · #976

worker-visualizer

它能做什么

在浏览器中创建一个运行流畅(每秒60帧)的视觉动画。它会在后台执行大量计算,不会让主页面卡顿,并将结果显示在 canvas 上。

适用场景

  • ✓当你想看实时的粒子或物理模拟效果时。
  • ✓用于制作复杂的视觉特效,比如动态分形图。
  • ✓在开发需要大量计算、又不希望拖慢界面的功能时。

技能链接

https://github.com/nexu-io/open-design/blob/main/design-templates/worker-visualizer/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/nexu-io/open-design/blob/main/design-templates/worker-visualizer/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“创建一个模拟,让1000个粒子相互吸引,并将其显示在 canvas 上。”

每周 5 个新技能,1 分钟读完。

工作原理

代码会把工作拆分开:一部分在单独的区域(Web Worker)中处理大量计算,另一部分只负责把结果画到屏幕上。这样能确保页面始终保持响应。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Worker Visualizer Skill

Produce a single self-contained index.html that moves heavy per-frame compute into a Web Worker and renders the result to a canvas, keeping the main thread at a smooth 60fps.

Why this is a powered artifact

OpenDesign detects new Worker( / SharedArrayBuffer / OffscreenCanvas and renders this file in powered preview — a cross-origin-isolated iframe with allow-same-origin. That means external and blob Web Workers construct successfully, SharedArrayBuffer is defined (crossOriginIsolated === true), and importScripts works. In the old opaque sandbox all three failed; here they just work.

Resource map

worker-visualizer/
├── SKILL.md      ← you're reading this
└── example.html  ← a working 12k-particle SharedArrayBuffer sim (READ FIRST)

Workflow

Step 0 — Read the reference

Read example.html. Note the split: the worker integrates positions each tick; the main thread only reads + draws. It feature-detects crossOriginIsolated and uses a SharedArrayBuffer for zero-copy when available, falling back to a transferable postMessage copy otherwise. Always ship that fallback so the artifact still animates if isolation is off.

Step 1 — Choose the workload

Pick ONE compute-bound job worth offloading:

  • Particle / N-body field (default): thousands of bodies with a cheap force law.
  • Fractal: Mandelbrot/Julia escape-time into an ImageData buffer.
  • Cellular automata / reaction-diffusion: grid updated in the worker.
  • Data/audio visualizer: transform a stream into bars/rings each frame.

Step 2 — Build index.html

  • One file, zero external requests. Build the worker from a Blob + URL.createObjectURL (inline its source), or embed it as a data: URL.
  • Prefer SharedArrayBuffer for large per-frame state: allocate on the main thread, pass the SharedArrayBuffer to the worker, and read the same Float32Array/Uint8ClampedArray view while drawing. Guard on typeof SharedArrayBuffer !== 'undefined' && crossOriginIsolated.
  • Fallback path: if not isolated, postMessage a transferable ArrayBuffer each frame.
  • Consider OffscreenCanvas + canvas.transferControlToOffscreen() to render inside the worker for the heaviest scenes.

Step 3 — Overlay + brand

  • HUD with the title and 2–3 live stat tiles (particle count, transport mode, fps). Map accent color to the active DESIGN.md when present; otherwise a dark ground with one vivid accent.

Step 4 — Self-review (P0)

  • Worker constructs with no SecurityError; sim runs.
  • Main-thread render holds ~60fps under the full workload.
  • SharedArrayBuffer path engages when crossOriginIsolated is true; postMessage fallback engages otherwise — verify BOTH branches degrade cleanly.
  • No unbounded growth: velocities/positions stay stable over minutes.
  • The "Transport" stat truthfully reports which path is live.
常见问题

什么是“Web Worker”?

它就像浏览器里的一个“幕后帮手”,能在不干扰你所看到的主界面的情况下处理繁重任务。

什么是“SharedArrayBuffer”?

这是一种较高级的方式,可以在主线程和帮手(Web Worker)之间共享超大数据,而无需把所有数据全部复制一遍,因此速度更快。

为什么动画能达到60fps?

这个工具经过优化,能够高效地完成计算和绘制,确保动画流畅、观看舒适,就像游戏一样。

详情

作者的原始描述

A real-time data/particle/simulation visualizer whose heavy compute runs in a Web Worker (off the main thread), optionally sharing memory with the UI via SharedArrayBuffer, and renders to a canvas at 60fps. Produced as a single self-contained `index.html`. Use when the brief asks for a "web worker", "simulation", "particle system", "physics", "off-main-thread", "fractal", "real-time compute", or "

repo: nexu-io/open-design

热度

GitHub 星标
101k
排名
#976
许可证
Apache-2.0
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能