@basnijholt/particular-drift

中文文档
0.2.0发布于 2026/10/07MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 6076

Reusable WebGL particle drift renderer for image-based animations.

原始使用文档
文档目录10 节
  1. Install
  2. Vanilla Usage
  3. React Usage
  4. API
  5. Development
  6. Examples Site
  7. Publishing
  8. Browser Requirements
  9. License
  10. Original Author

Particular Drift

Reusable WebGL2 particle drift renderer for turning a fixed image into a flowing particle animation.

Original project: collidingScopes/particular-drift by Colliding Scopes.

This fork is packaged as an embeddable library. It intentionally removes the original demo UI, upload controls, and MP4 export stack so applications can hardcode their own image and own the surrounding interface.

Install

bun add github:basnijholt/particular-drift

After publishing to npm, install with:

bun add @basnijholt/particular-drift

Vanilla Usage

import { createParticularDrift } from '@basnijholt/particular-drift';

const canvas = document.querySelector<HTMLCanvasElement>('#background');

if (canvas) {
  const drift = await createParticularDrift(canvas, {
    imageUrl: '/res/branding/mindroom-logo.png',
    backgroundColor: '#0f0d2e',
    particleColor: '#dda290',
    particleCount: 120000,
    cursorMode: 'repel',
  });

  window.addEventListener('resize', drift.resize);
}

React Usage

import { ParticularDriftCanvas } from '@basnijholt/particular-drift/react';

export function AuthBackground() {
  return (
    <ParticularDriftCanvas
      imageUrl="/res/branding/mindroom-logo.png"
      options={{
        backgroundColor: '#0f0d2e',
        particleColor: '#dda290',
        particleCount: 120000,
      }}
    />
  );
}

API

createParticularDrift(canvas, options) returns:

  • loadImage(image) to load an existing TexImageSource.
  • loadImageUrl(url) to load an image URL.
  • resize() to resize the backing canvas to its rendered CSS size.
  • start() and stop() to control animation.
  • destroy() to cancel animation and release WebGL resources.

Main options:

  • imageUrl
  • imageFit: 'contain' preserves image aspect ratio inside the canvas; 'stretch' uses the original full-canvas mapping.
  • particleCount
  • particleSpeed
  • attractionStrength
  • particleOpacity
  • particleSize
  • edgeThreshold
  • edgeSearchSteps: 1, 2, or 3; controls the bounded grid radius used when particles search for nearby edges.
  • flowFieldScale
  • searchRadius
  • noiseType: '2D' or '3D'
  • interactive: enables pointer interaction when true.
  • cursorMode: 'repel' pushes particles away from the cursor; 'attract' pulls them toward it.
  • cursorRadius: normalized cursor influence radius.
  • cursorStrength: cursor force multiplier.
  • cursorReturnStrength: force that pulls disturbed particles back toward their stored image target.
  • cursorReturnDamping: damping applied while particles settle back after cursor disturbance.
  • backgroundColor
  • particleColor
  • autoStart
  • maxDevicePixelRatio: a positive cap on the canvas resolution; below 1 renders below CSS resolution, which the browser scales up (cheaper on software WebGL). Particle size is in canvas pixels, so lower particleSize/particleOpacity to keep the same look.
  • maxFramesPerSecond: caps the frame rate (default Infinity; anything but a positive number means uncapped). The simulation advances by elapsed time, so it does not slow down; lower frame rates are less smooth and settle slightly differently.

Development

bun install
bun run dev
bun test
bun run typecheck
bun run build

Examples Site

The examples site is built from index.html and demo/main.ts:

bun run build:pages
bun run preview:pages

GitHub Pages deploys the examples from the Pages workflow on main. In the repository settings, set Pages source to GitHub Actions.

Once enabled, the examples are available at:

https://basnijholt.github.io/particular-drift/

Publishing

CI publishes to npm from GitHub Actions when a GitHub Release is published, or when the Publish workflow is run manually.

Configure npm Trusted Publishing for this package with:

  • Provider: GitHub Actions
  • Owner: basnijholt
  • Repository: particular-drift
  • Workflow filename: publish.yml

Then release with a semver tag. The workflow strips the leading v, updates package.json in CI, and publishes that version to npm:

gh release create v0.1.1 --generate-notes

Browser Requirements

  • WebGL2
  • Canvas image loading must satisfy browser CORS rules when using remote image URLs.

License

MIT. See LICENSE.txt.

Original Author

Particular Drift was created by Colliding Scopes. This package is a library-focused fork of that work.

Buy Me A Coffee

版本与发布记录

@basnijholt/particular-drift 共发布 3 个版本,首次发布于 2026/05/13;过去 12 个月发布了 3 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.2.0latest2026/10/071 个月前
0.1.12026/05/135 个月前
0.1.02026/05/135 个月前

关于 @basnijholt/particular-drift 的常见问题

@basnijholt/particular-drift 是什么?

Reusable WebGL particle drift renderer for image-based animations.

如何安装 @basnijholt/particular-drift?

在项目目录运行 npm install @basnijholt/particular-drift,或使用 pnpm add / yarn add / bun add。

@basnijholt/particular-drift 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@basnijholt/particular-drift 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@basnijholt/particular-drift 可以商用吗?

@basnijholt/particular-drift 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@basnijholt/particular-drift 的下载量有多少?

根据 npm 官方下载统计,@basnijholt/particular-drift 在 2026/10/08 – 2026/11/06 这 30 天内被下载 6,076 次,日均约 203 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@basnijholt/particular-drift 还在维护吗?

最新版本 0.2.0 发布于 2026/10/07(1 个月前);至今共发布 3 个版本,其中过去 12 个月发布了 3 个;首次发布于 2026/05/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。