Nebula Swirl 星空漩涡
Eighty particles in polar form, orbiting at different speeds — the ellipse comes from scaling y by 0.6. 八十个粒子用极坐标描述,各自以不同角速度公转——椭圆感是把 y 压到 0.6 换来的。
Runs live on this page. Move the pointer, click, or drag — whichever the effect listens for. 就在本页实时运行。移动鼠标、点击或拖拽——看它响应哪一种。
How it works原理拆解
Each particle stores only an angle a and a radius r. Every frame a increases by its own speed s, and the position is projected with cos(a)*r for x and sin(a)*r*0.6 for y. Squashing the y axis is what turns a flat circle into a tilted galaxy. 每个粒子只存角度 a 和半径 r。每帧 a 按自己的速度自增,位置用 cos(a)*r 算 x、sin(a)*r*0.6 算 y。把 y 轴压扁,正圆就变成了有倾角的星系。
What to change可以改的地方
- 1Change 0.6 to 0.25 for an edge-on view, or 1 for a face-on spiral.
- 2Give r a slow oscillation so the arms breathe instead of staying rigid.
- 1把 0.6 改成 0.25 是从侧面看,改成 1 就是正面俯视的漩涡。
- 2让 r 缓慢来回变化,旋臂会有呼吸感,而不是硬邦邦地转。
Source code源码
Self-contained — paste it into any HTML file and it runs. No libraries. 完全独立——粘进任意 HTML 文件就能跑,不需要任何库。