跳到正文
网页珍奇柜Web Curio

粒子生命

Particle Life,Hunar Ahmad,2022 年

正在布展…

原作直展:这是 Hunar Ahmad 的原始作品,按 MIT(附带的 lil-gui 也是 MIT) 许可证收录(版本 2562787)。原作页面只改了一行:把从 CDN 加载的 lil-gui 换成随附在同一目录里的同版本副本,这样藏品不会向其他网站发请求。右上角的面板是原作自带的,可以调规则。 许可证全文 · 收录说明

它是怎么做的

  1. 第 1 步每种颜色对另一种颜色有一个 -1 到 1 的作用系数
  2. 第 2 步每帧对所有粒子对计算距离,在作用半径内按 系数/距离 施加力
  3. 第 3 步速度乘以阻尼后更新位置,边界反弹
  4. 第 4 步随机化系数表就会得到新的“生态系统”

复刻配方

一段技术配方,可以直接交给 AI 编程助手,也可以自己照着写。想指定技术栈、位置和性能预算,就把它加入实现方案。

Create a few groups of particles, each with a colour, and a square matrix of interaction coefficients between groups in [-1, 1]. Each frame, for every particle sum forces from particles of each group within a radius, using coefficient times 1/distance (or a piecewise curve that is repulsive at very short range). Add the force to velocity, multiply by a friction factor, update position and bounce or wrap at edges. Expose the matrix as sliders with a randomise button, and use a spatial grid to scale beyond a few thousand particles.

档案

能不能拿来用

原作以 MIT 许可开源:可以阅读源码学习,按许可证条款使用;在自己的项目里引用时保留原作者署名。

性能开销

视觉强度

实现难度

尺度为策展判断(1 到 5),用于比较和推荐。

核实记录:Opened https://hunar4321.github.io/particle-life/particle_life.html (200, title 'Life'); repo hunar4321/particle-life exists, licence MIT via GitHub API (Copyright 2022 Hunar Ahmad).