particlefx 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. particlefx-1.0.0/LICENSE +21 -0
  2. particlefx-1.0.0/PKG-INFO +361 -0
  3. particlefx-1.0.0/README.md +291 -0
  4. particlefx-1.0.0/particlefx/__init__.py +78 -0
  5. particlefx-1.0.0/particlefx/components/__init__.py +41 -0
  6. particlefx-1.0.0/particlefx/components/effects.py +963 -0
  7. particlefx-1.0.0/particlefx/components/effects_config.json +851 -0
  8. particlefx-1.0.0/particlefx/components/effects_config.schema.json +203 -0
  9. particlefx-1.0.0/particlefx/components/effects_factory.py +478 -0
  10. particlefx-1.0.0/particlefx/components/palettes.json +68 -0
  11. particlefx-1.0.0/particlefx/core/__init__.py +88 -0
  12. particlefx-1.0.0/particlefx/core/particle.py +1995 -0
  13. particlefx-1.0.0/particlefx/core/particle_numba.py +171 -0
  14. particlefx-1.0.0/particlefx/core/particle_numpy.py +567 -0
  15. particlefx-1.0.0/particlefx/core/particle_taichi.py +340 -0
  16. particlefx-1.0.0/particlefx/core/spatial_hash.py +153 -0
  17. particlefx-1.0.0/particlefx/renderers/__init__.py +59 -0
  18. particlefx-1.0.0/particlefx/renderers/fluid_renderer.py +581 -0
  19. particlefx-1.0.0/particlefx/renderers/fluid_renderer_modernGL.py +906 -0
  20. particlefx-1.0.0/particlefx/renderers/particle_renderer_moderngl.py +561 -0
  21. particlefx-1.0.0/particlefx/renderers/particle_sim_gpu.py +326 -0
  22. particlefx-1.0.0/particlefx/renderers/pil_renderer.py +587 -0
  23. particlefx-1.0.0/particlefx/renderers/postfx.py +302 -0
  24. particlefx-1.0.0/particlefx/renderers/pygame_renderer.py +439 -0
  25. particlefx-1.0.0/particlefx/systems/__init__.py +13 -0
  26. particlefx-1.0.0/particlefx/systems/combat_effects.py +634 -0
  27. particlefx-1.0.0/particlefx/systems/fireworks_system.py +795 -0
  28. particlefx-1.0.0/particlefx/systems/weather_system.py +336 -0
  29. particlefx-1.0.0/particlefx.egg-info/PKG-INFO +361 -0
  30. particlefx-1.0.0/particlefx.egg-info/SOURCES.txt +51 -0
  31. particlefx-1.0.0/particlefx.egg-info/dependency_links.txt +1 -0
  32. particlefx-1.0.0/particlefx.egg-info/requires.txt +28 -0
  33. particlefx-1.0.0/particlefx.egg-info/top_level.txt +1 -0
  34. particlefx-1.0.0/pyproject.toml +102 -0
  35. particlefx-1.0.0/setup.cfg +4 -0
  36. particlefx-1.0.0/tests/test_attractor_lights.py +200 -0
  37. particlefx-1.0.0/tests/test_combat.py +411 -0
  38. particlefx-1.0.0/tests/test_depth_fade.py +74 -0
  39. particlefx-1.0.0/tests/test_effects.py +401 -0
  40. particlefx-1.0.0/tests/test_effects_factory.py +172 -0
  41. particlefx-1.0.0/tests/test_effects_schema.py +92 -0
  42. particlefx-1.0.0/tests/test_fireworks.py +143 -0
  43. particlefx-1.0.0/tests/test_gpu_sim.py +103 -0
  44. particlefx-1.0.0/tests/test_particle.py +754 -0
  45. particlefx-1.0.0/tests/test_particle_numba.py +154 -0
  46. particlefx-1.0.0/tests/test_particle_numpy.py +481 -0
  47. particlefx-1.0.0/tests/test_particle_taichi.py +93 -0
  48. particlefx-1.0.0/tests/test_performance.py +372 -0
  49. particlefx-1.0.0/tests/test_postfx.py +152 -0
  50. particlefx-1.0.0/tests/test_renderers.py +422 -0
  51. particlefx-1.0.0/tests/test_spatial_hash_pool.py +255 -0
  52. particlefx-1.0.0/tests/test_weather.py +274 -0
  53. particlefx-1.0.0/tests/test_web_main.py +51 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 siwpan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,361 @@
1
+ Metadata-Version: 2.4
2
+ Name: particlefx
3
+ Version: 1.0.0
4
+ Summary: 纯 Python + NumPy 粒子系统库 — 多渲染器(pygame/PIL/ModernGL)+ 效果工厂 + Taichi 流体后端 + GPU 模拟
5
+ Author: 全哥
6
+ License: MIT License
7
+
8
+ Copyright (c) 2026 siwpan
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://gitee.com/siwpan/particlefx
29
+ Project-URL: Repository, https://gitee.com/siwpan/particlefx
30
+ Project-URL: Issues, https://gitee.com/siwpan/particlefx/issues
31
+ Project-URL: Changelog, https://gitee.com/siwpan/particlefx/blob/master/CHANGELOG.md
32
+ Keywords: particle,particle-system,effects,vfx,pygame,numpy,rendering,gpu
33
+ Classifier: Development Status :: 4 - Beta
34
+ Classifier: Intended Audience :: Developers
35
+ Classifier: Operating System :: OS Independent
36
+ Classifier: Programming Language :: Python :: 3
37
+ Classifier: Programming Language :: Python :: 3.10
38
+ Classifier: Programming Language :: Python :: 3.11
39
+ Classifier: Programming Language :: Python :: 3.12
40
+ Classifier: Programming Language :: Python :: 3.13
41
+ Classifier: Programming Language :: Python :: 3.14
42
+ Classifier: Topic :: Multimedia :: Graphics
43
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
44
+ Classifier: Topic :: Games/Entertainment
45
+ Requires-Python: >=3.10
46
+ Description-Content-Type: text/markdown
47
+ License-File: LICENSE
48
+ Requires-Dist: numpy>=1.24
49
+ Provides-Extra: pygame
50
+ Requires-Dist: pygame-ce>=2.4; extra == "pygame"
51
+ Provides-Extra: pil
52
+ Requires-Dist: Pillow>=10.0; extra == "pil"
53
+ Provides-Extra: numba
54
+ Requires-Dist: numba>=0.60; extra == "numba"
55
+ Provides-Extra: taichi
56
+ Requires-Dist: taichi>=1.7; extra == "taichi"
57
+ Provides-Extra: gpu
58
+ Requires-Dist: moderngl>=5.10; extra == "gpu"
59
+ Requires-Dist: pygame-ce>=2.4; extra == "gpu"
60
+ Provides-Extra: schema
61
+ Requires-Dist: jsonschema>=4.0; extra == "schema"
62
+ Provides-Extra: all
63
+ Requires-Dist: pygame-ce>=2.4; extra == "all"
64
+ Requires-Dist: Pillow>=10.0; extra == "all"
65
+ Requires-Dist: numba>=0.60; extra == "all"
66
+ Requires-Dist: taichi>=1.7; extra == "all"
67
+ Requires-Dist: moderngl>=5.10; extra == "all"
68
+ Requires-Dist: jsonschema>=4.0; extra == "all"
69
+ Dynamic: license-file
70
+
71
+ # particlefx — 独立粒子系统
72
+
73
+ [![PyPI version](https://img.shields.io/pypi/v/particlefx)](https://pypi.org/project/particlefx/)
74
+ [![PyPI Python versions](https://img.shields.io/pypi/pyversions/particlefx)](https://pypi.org/project/particlefx/)
75
+ [![PyPI license](https://img.shields.io/pypi/l/particlefx)](https://pypi.org/project/particlefx/)
76
+
77
+ > 仓库:<https://gitee.com/siwpan/particlefx> | 许可:MIT(见 [LICENSE](LICENSE))
78
+ > 注:文中 <PATH> 为路径占位符,请替换为你本机实际的目录 / 可执行文件路径。
79
+
80
+ ## 安装
81
+
82
+ ```bash
83
+ pip install particlefx # 仅核心(NumPy)
84
+ pip install "particlefx[pygame]" # + pygame 渲染器
85
+ pip install "particlefx[all]" # + 全部可选依赖
86
+ ```
87
+
88
+ **发行名 vs 导入名**:PyPI 上的发行名是 `particlefx`,Python 导入名同为 `particlefx`(无连字符差异)。
89
+
90
+ ```python
91
+ from particlefx import ParticleSystem, Emitter, ForceField
92
+ from particlefx.renderers import PygameRenderer
93
+ ```
94
+
95
+ ## 设计理念
96
+
97
+ 1. **独立性**:不依赖任何项目,纯 Python + NumPy 实现
98
+ 2. **可复用性**:pip 安装即用,也可复制 `particlefx/` 目录到目标项目微调
99
+ 3. **简洁性**:只提供核心功能,不添加冗余特性
100
+
101
+ ## 项目结构
102
+
103
+ ```
104
+ particlefx/
105
+ ├── particlefx/ # Python 包(命名空间根)
106
+ │ ├── core/
107
+ │ │ ├── particle.py # 核心粒子类(Particle/ParticleSystem/Emitter/ForceField/
108
+ │ │ │ # ParticleAttractor/ParticlePool/碰撞/光照/LOD/事件)
109
+ │ │ ├── particle_numpy.py # NumPy 向量化粒子系统(SoA)
110
+ │ │ ├── particle_numba.py # v5.0:Numba JIT 更新内核(可选依赖)
111
+ │ │ ├── particle_taichi.py # v5.0:Taichi WCSPH 流体后端(可选依赖)
112
+ │ │ └── spatial_hash.py # v5.0:均匀网格空间哈希
113
+ │ ├── renderers/
114
+ │ │ ├── pygame_renderer.py # Pygame 渲染器(additive/screen 混合 + Bloom)
115
+ │ │ ├── pil_renderer.py # PIL 渲染器(离屏/GIF/视频帧/分层渲染)
116
+ │ │ ├── postfx.py # v5.0:可编程后处理链(Bloom/色调映射/晕影/色差/颗粒)
117
+ │ │ ├── fluid_renderer.py # CPU 折中版 SSFR 流体渲染
118
+ │ │ ├── particle_renderer_moderngl.py # GPU 实例化粒子(含软粒子深度淡出)
119
+ │ │ ├── fluid_renderer_modernGL.py # GPU 统一渲染器(4 种路径 + 软粒子)
120
+ │ │ └── particle_sim_gpu.py # v5.0:Compute Shader 全 GPU 模拟
121
+ │ ├── components/
122
+ │ │ ├── effects.py / effects_factory.py # 效果工厂(代码 + JSON 声明式)
123
+ │ │ ├── effects_config.json # 30+ 预设效果配方
124
+ │ │ ├── effects_config.schema.json # v5.0:配方 JSON Schema
125
+ │ │ └── palettes.json # 主题调色板库
126
+ │ └── systems/
127
+ │ ├── fireworks_system.py # 烟花(14 样式 × 10 调色板)
128
+ │ ├── weather_system.py # 天气(6 种)
129
+ │ └── combat_effects.py # 战斗特效(攻击/技能/飘字/死亡)
130
+ ├── examples/ # 交互 Demo + 视频生成器 + pygbag Web 入口
131
+ ├── docs/ # api.md / effects.md / enhancements.md
132
+ └── tests/ # pytest 全套测试
133
+ ```
134
+
135
+ ## 核心类
136
+
137
+ ### Particle(粒子)
138
+
139
+ 单个粒子的数据结构:
140
+
141
+ ```python
142
+ @dataclass
143
+ class Particle:
144
+ x: float # x 位置
145
+ y: float # y 位置
146
+ vx: float # x 速度
147
+ vy: float # y 速度
148
+ life: float # 剩余生命值 (0-1)
149
+ max_life: float # 最大生命值
150
+ size: float # 大小
151
+ color: Tuple[int, int, int] # RGB 颜色
152
+ alpha: float = 1.0 # 透明度 (0-1)
153
+ ```
154
+
155
+ ### ParticleSystem(粒子系统管理器)
156
+
157
+ 管理所有粒子、发射器和力场:
158
+
159
+ ```python
160
+ ps = ParticleSystem(max_particles=1000)
161
+ ps.add_emitter(emitter)
162
+ ps.add_force_field(gravity)
163
+ ps.update(dt, audio_data)
164
+ ps.render(renderer)
165
+ ```
166
+
167
+ ### Emitter(发射器)
168
+
169
+ 发射粒子:
170
+
171
+ ```python
172
+ emitter = Emitter(
173
+ x=width//2, y=height,
174
+ rate=50.0, # 发射速率(粒子/秒)
175
+ spread=3.14, # 扩散角度(弧度)
176
+ speed=200.0, # 发射速度
177
+ life=2.0, # 粒子生命值
178
+ size=3.0, # 粒子大小
179
+ color=(255, 200, 50) # 粒子颜色
180
+ )
181
+ ```
182
+
183
+ ### ForceField(力场)
184
+
185
+ 模拟重力、风力、吸引力等:
186
+
187
+ ```python
188
+ # 重力(向下)
189
+ gravity = ForceField(field_type='gravity', strength=100.0)
190
+
191
+ # 风力(向右)
192
+ wind = ForceField(field_type='wind', strength=50.0)
193
+
194
+ # 吸引力(指向某点)
195
+ attractor = ForceField(field_type='attraction', x=400, y=300, strength=200.0)
196
+ ```
197
+
198
+ ## 使用方法
199
+
200
+ ### 1. pip 安装(推荐)
201
+
202
+ ```bash
203
+ pip install particlefx
204
+ ```
205
+
206
+ 装完直接用,无需复制目录:
207
+
208
+ ```python
209
+ from particlefx import ParticleSystem, Emitter, ForceField
210
+ from particlefx.renderers import PygameRenderer
211
+ ```
212
+
213
+ ### 2. 复制到目标项目
214
+
215
+ 若需深度微调,也可复制包目录到目标项目:
216
+
217
+ ```bash
218
+ # 复制到其他目标项目(按需微调)
219
+ cp -r particlefx/ <你的项目目录>/particlefx/
220
+ ```
221
+
222
+ ### 3. 微调适配
223
+
224
+ 根据目标项目的架构进行微调:
225
+
226
+ - **pywallpaper**:已集成 `particle.py` 原语,可以直接使用
227
+ - **draw**:需要创建新的渲染器(`draw/renderers/particle_renderer.py`)
228
+
229
+ ### 4. 使用示例
230
+
231
+ ```python
232
+ from particlefx import ParticleSystem, Emitter, ForceField
233
+ from particlefx.renderers import PygameRenderer
234
+
235
+ # 创建粒子系统
236
+ ps = ParticleSystem(max_particles=1000)
237
+
238
+ # 创建发射器
239
+ emitter = Emitter(x=400, y=300, rate=50.0, ...)
240
+ ps.add_emitter(emitter)
241
+
242
+ # 创建力场
243
+ gravity = ForceField(field_type='gravity', strength=100.0)
244
+ ps.add_force_field(gravity)
245
+
246
+ # 更新和渲染
247
+ ps.update(dt)
248
+ renderer = PygameRenderer(screen)
249
+ ps.render(renderer)
250
+ ```
251
+
252
+ ## 示例效果
253
+
254
+ ### 烟花(Fireworks)
255
+
256
+ ```bash
257
+ cd examples/
258
+ python fireworks.py
259
+ ```
260
+
261
+ ### 其他效果(待创建)
262
+
263
+ - 雨水(Rain)
264
+ - 雪花(Snow)
265
+ - 爆炸(Explosion)
266
+ - 魔法效果(Magic)
267
+
268
+ ## 音频驱动
269
+
270
+ 粒子系统支持音频驱动:
271
+
272
+ ```python
273
+ # 更新时传入音频数据
274
+ audio_data = {
275
+ 'rms': 0.5, # 音频 RMS 能量
276
+ 'beat': True, # 是否检测到节拍
277
+ 'band_energy': [0.1, 0.2, 0.3] # 频段能量
278
+ }
279
+ ps.update(dt, audio_data)
280
+ ```
281
+
282
+ 在 `Emitter.emit()` 中,可以根据 `audio_data` 调整发射速率:
283
+
284
+ ```python
285
+ if audio_data:
286
+ energy = audio_data.get('rms', 1.0)
287
+ current_rate *= (1.0 + energy * 2.0) # 根据音频能量调整发射速率
288
+ ```
289
+
290
+ ## 性能优化
291
+
292
+ ### NumPy 向量化
293
+
294
+ 将粒子数据存储在 NumPy 数组中,使用向量化计算:
295
+
296
+ ```python
297
+ # TODO: 创建 ParticleSystemNumpy 类
298
+ class ParticleSystemNumpy:
299
+ def __init__(self):
300
+ self.positions = np.zeros((max_particles, 2)) # x, y
301
+ self.velocities = np.zeros((max_particles, 2)) # vx, vy
302
+ self.lives = np.zeros(max_particles) # life
303
+ # ...
304
+ ```
305
+
306
+ ### Numba JIT 编译
307
+
308
+ 使用 Numba 编译粒子更新循环:
309
+
310
+ ```python
311
+ from numba import jit
312
+
313
+ @jit(nopython=True)
314
+ def update_particles(positions, velocities, lives, dt):
315
+ # ...
316
+ ```
317
+
318
+ ## 依赖
319
+
320
+ - **必需**:NumPy
321
+ - **可选**(对应 pip extras):
322
+ - `pygame-ce` — pygame 渲染器(`particlefx/renderers/pygame_renderer.py`)
323
+ - `Pillow` — PIL 渲染器(`particlefx/renderers/pil_renderer.py`)
324
+ - `numba` — JIT 更新内核
325
+ - `taichi` — WCSPH 流体后端
326
+ - `moderngl` — GPU 渲染器 / Compute Shader 模拟
327
+ - `jsonschema` — 效果配方 Schema 校验
328
+
329
+ ## v5.0 增强功能(2026)
330
+
331
+ 按"成本从低到高"落地的 9 项增强,全部保持**可选依赖零开销 + 向后兼容**:
332
+
333
+ | # | 增强 | 入口 | 可选依赖 |
334
+ |---|------|------|---------|
335
+ | ① | 对象池 + 空间哈希 | `ParticleSystem(use_pool=True, use_spatial_hash=True)` | 无 |
336
+ | ② | Numba JIT 更新内核 | `particlefx.core.particle_numba.NumbaParticleSystem` | numba |
337
+ | ③ | 软粒子深度淡出 | `GPUParticleRenderer(enable_depth_fade=True)` | moderngl |
338
+ | ④ | 浏览器 Web 导出 | `pygbag --app_name web_main examples` | pygbag |
339
+ | ⑤ | 粒子吸引子 + 粒子光源 | `ParticleAttractor` / `enable_pairwise_force` / `enable_particle_lights` | 无 |
340
+ | ⑥ | 可编程后处理链 | `particlefx.renderers.postfx.PostFXChain` | 无 |
341
+ | ⑦ | JSON Schema 校验 | `EffectsFactory(validate=True)` | jsonschema(可选) |
342
+ | ⑧ | Taichi SPH 流体 | `particlefx.core.particle_taichi.TaichiSPHSystem` | taichi |
343
+ | ⑨ | Compute 全 GPU 模拟 | `particlefx.renderers.particle_sim_gpu.GPUParticleSimulator` | moderngl |
344
+
345
+ 详见 [docs/enhancements.md](docs/enhancements.md)。
346
+
347
+ ## 许可证
348
+
349
+ MIT License(可自由复制、修改、使用)
350
+
351
+ ## 作者
352
+
353
+ - 全哥(独立开发者)
354
+ - AI 助手(WorkBuddy)
355
+
356
+ ## 更新日志
357
+
358
+ 详见 [CHANGELOG.md](CHANGELOG.md)。
359
+
360
+ - **2026-10-21**:v1.0.0 发布至 PyPI(发行名 `particlefx`),源码重组为 `particlefx/` 命名空间包
361
+ - **2026-06-23**:初始版本,创建核心类和示例效果
@@ -0,0 +1,291 @@
1
+ # particlefx — 独立粒子系统
2
+
3
+ [![PyPI version](https://img.shields.io/pypi/v/particlefx)](https://pypi.org/project/particlefx/)
4
+ [![PyPI Python versions](https://img.shields.io/pypi/pyversions/particlefx)](https://pypi.org/project/particlefx/)
5
+ [![PyPI license](https://img.shields.io/pypi/l/particlefx)](https://pypi.org/project/particlefx/)
6
+
7
+ > 仓库:<https://gitee.com/siwpan/particlefx> | 许可:MIT(见 [LICENSE](LICENSE))
8
+ > 注:文中 <PATH> 为路径占位符,请替换为你本机实际的目录 / 可执行文件路径。
9
+
10
+ ## 安装
11
+
12
+ ```bash
13
+ pip install particlefx # 仅核心(NumPy)
14
+ pip install "particlefx[pygame]" # + pygame 渲染器
15
+ pip install "particlefx[all]" # + 全部可选依赖
16
+ ```
17
+
18
+ **发行名 vs 导入名**:PyPI 上的发行名是 `particlefx`,Python 导入名同为 `particlefx`(无连字符差异)。
19
+
20
+ ```python
21
+ from particlefx import ParticleSystem, Emitter, ForceField
22
+ from particlefx.renderers import PygameRenderer
23
+ ```
24
+
25
+ ## 设计理念
26
+
27
+ 1. **独立性**:不依赖任何项目,纯 Python + NumPy 实现
28
+ 2. **可复用性**:pip 安装即用,也可复制 `particlefx/` 目录到目标项目微调
29
+ 3. **简洁性**:只提供核心功能,不添加冗余特性
30
+
31
+ ## 项目结构
32
+
33
+ ```
34
+ particlefx/
35
+ ├── particlefx/ # Python 包(命名空间根)
36
+ │ ├── core/
37
+ │ │ ├── particle.py # 核心粒子类(Particle/ParticleSystem/Emitter/ForceField/
38
+ │ │ │ # ParticleAttractor/ParticlePool/碰撞/光照/LOD/事件)
39
+ │ │ ├── particle_numpy.py # NumPy 向量化粒子系统(SoA)
40
+ │ │ ├── particle_numba.py # v5.0:Numba JIT 更新内核(可选依赖)
41
+ │ │ ├── particle_taichi.py # v5.0:Taichi WCSPH 流体后端(可选依赖)
42
+ │ │ └── spatial_hash.py # v5.0:均匀网格空间哈希
43
+ │ ├── renderers/
44
+ │ │ ├── pygame_renderer.py # Pygame 渲染器(additive/screen 混合 + Bloom)
45
+ │ │ ├── pil_renderer.py # PIL 渲染器(离屏/GIF/视频帧/分层渲染)
46
+ │ │ ├── postfx.py # v5.0:可编程后处理链(Bloom/色调映射/晕影/色差/颗粒)
47
+ │ │ ├── fluid_renderer.py # CPU 折中版 SSFR 流体渲染
48
+ │ │ ├── particle_renderer_moderngl.py # GPU 实例化粒子(含软粒子深度淡出)
49
+ │ │ ├── fluid_renderer_modernGL.py # GPU 统一渲染器(4 种路径 + 软粒子)
50
+ │ │ └── particle_sim_gpu.py # v5.0:Compute Shader 全 GPU 模拟
51
+ │ ├── components/
52
+ │ │ ├── effects.py / effects_factory.py # 效果工厂(代码 + JSON 声明式)
53
+ │ │ ├── effects_config.json # 30+ 预设效果配方
54
+ │ │ ├── effects_config.schema.json # v5.0:配方 JSON Schema
55
+ │ │ └── palettes.json # 主题调色板库
56
+ │ └── systems/
57
+ │ ├── fireworks_system.py # 烟花(14 样式 × 10 调色板)
58
+ │ ├── weather_system.py # 天气(6 种)
59
+ │ └── combat_effects.py # 战斗特效(攻击/技能/飘字/死亡)
60
+ ├── examples/ # 交互 Demo + 视频生成器 + pygbag Web 入口
61
+ ├── docs/ # api.md / effects.md / enhancements.md
62
+ └── tests/ # pytest 全套测试
63
+ ```
64
+
65
+ ## 核心类
66
+
67
+ ### Particle(粒子)
68
+
69
+ 单个粒子的数据结构:
70
+
71
+ ```python
72
+ @dataclass
73
+ class Particle:
74
+ x: float # x 位置
75
+ y: float # y 位置
76
+ vx: float # x 速度
77
+ vy: float # y 速度
78
+ life: float # 剩余生命值 (0-1)
79
+ max_life: float # 最大生命值
80
+ size: float # 大小
81
+ color: Tuple[int, int, int] # RGB 颜色
82
+ alpha: float = 1.0 # 透明度 (0-1)
83
+ ```
84
+
85
+ ### ParticleSystem(粒子系统管理器)
86
+
87
+ 管理所有粒子、发射器和力场:
88
+
89
+ ```python
90
+ ps = ParticleSystem(max_particles=1000)
91
+ ps.add_emitter(emitter)
92
+ ps.add_force_field(gravity)
93
+ ps.update(dt, audio_data)
94
+ ps.render(renderer)
95
+ ```
96
+
97
+ ### Emitter(发射器)
98
+
99
+ 发射粒子:
100
+
101
+ ```python
102
+ emitter = Emitter(
103
+ x=width//2, y=height,
104
+ rate=50.0, # 发射速率(粒子/秒)
105
+ spread=3.14, # 扩散角度(弧度)
106
+ speed=200.0, # 发射速度
107
+ life=2.0, # 粒子生命值
108
+ size=3.0, # 粒子大小
109
+ color=(255, 200, 50) # 粒子颜色
110
+ )
111
+ ```
112
+
113
+ ### ForceField(力场)
114
+
115
+ 模拟重力、风力、吸引力等:
116
+
117
+ ```python
118
+ # 重力(向下)
119
+ gravity = ForceField(field_type='gravity', strength=100.0)
120
+
121
+ # 风力(向右)
122
+ wind = ForceField(field_type='wind', strength=50.0)
123
+
124
+ # 吸引力(指向某点)
125
+ attractor = ForceField(field_type='attraction', x=400, y=300, strength=200.0)
126
+ ```
127
+
128
+ ## 使用方法
129
+
130
+ ### 1. pip 安装(推荐)
131
+
132
+ ```bash
133
+ pip install particlefx
134
+ ```
135
+
136
+ 装完直接用,无需复制目录:
137
+
138
+ ```python
139
+ from particlefx import ParticleSystem, Emitter, ForceField
140
+ from particlefx.renderers import PygameRenderer
141
+ ```
142
+
143
+ ### 2. 复制到目标项目
144
+
145
+ 若需深度微调,也可复制包目录到目标项目:
146
+
147
+ ```bash
148
+ # 复制到其他目标项目(按需微调)
149
+ cp -r particlefx/ <你的项目目录>/particlefx/
150
+ ```
151
+
152
+ ### 3. 微调适配
153
+
154
+ 根据目标项目的架构进行微调:
155
+
156
+ - **pywallpaper**:已集成 `particle.py` 原语,可以直接使用
157
+ - **draw**:需要创建新的渲染器(`draw/renderers/particle_renderer.py`)
158
+
159
+ ### 4. 使用示例
160
+
161
+ ```python
162
+ from particlefx import ParticleSystem, Emitter, ForceField
163
+ from particlefx.renderers import PygameRenderer
164
+
165
+ # 创建粒子系统
166
+ ps = ParticleSystem(max_particles=1000)
167
+
168
+ # 创建发射器
169
+ emitter = Emitter(x=400, y=300, rate=50.0, ...)
170
+ ps.add_emitter(emitter)
171
+
172
+ # 创建力场
173
+ gravity = ForceField(field_type='gravity', strength=100.0)
174
+ ps.add_force_field(gravity)
175
+
176
+ # 更新和渲染
177
+ ps.update(dt)
178
+ renderer = PygameRenderer(screen)
179
+ ps.render(renderer)
180
+ ```
181
+
182
+ ## 示例效果
183
+
184
+ ### 烟花(Fireworks)
185
+
186
+ ```bash
187
+ cd examples/
188
+ python fireworks.py
189
+ ```
190
+
191
+ ### 其他效果(待创建)
192
+
193
+ - 雨水(Rain)
194
+ - 雪花(Snow)
195
+ - 爆炸(Explosion)
196
+ - 魔法效果(Magic)
197
+
198
+ ## 音频驱动
199
+
200
+ 粒子系统支持音频驱动:
201
+
202
+ ```python
203
+ # 更新时传入音频数据
204
+ audio_data = {
205
+ 'rms': 0.5, # 音频 RMS 能量
206
+ 'beat': True, # 是否检测到节拍
207
+ 'band_energy': [0.1, 0.2, 0.3] # 频段能量
208
+ }
209
+ ps.update(dt, audio_data)
210
+ ```
211
+
212
+ 在 `Emitter.emit()` 中,可以根据 `audio_data` 调整发射速率:
213
+
214
+ ```python
215
+ if audio_data:
216
+ energy = audio_data.get('rms', 1.0)
217
+ current_rate *= (1.0 + energy * 2.0) # 根据音频能量调整发射速率
218
+ ```
219
+
220
+ ## 性能优化
221
+
222
+ ### NumPy 向量化
223
+
224
+ 将粒子数据存储在 NumPy 数组中,使用向量化计算:
225
+
226
+ ```python
227
+ # TODO: 创建 ParticleSystemNumpy 类
228
+ class ParticleSystemNumpy:
229
+ def __init__(self):
230
+ self.positions = np.zeros((max_particles, 2)) # x, y
231
+ self.velocities = np.zeros((max_particles, 2)) # vx, vy
232
+ self.lives = np.zeros(max_particles) # life
233
+ # ...
234
+ ```
235
+
236
+ ### Numba JIT 编译
237
+
238
+ 使用 Numba 编译粒子更新循环:
239
+
240
+ ```python
241
+ from numba import jit
242
+
243
+ @jit(nopython=True)
244
+ def update_particles(positions, velocities, lives, dt):
245
+ # ...
246
+ ```
247
+
248
+ ## 依赖
249
+
250
+ - **必需**:NumPy
251
+ - **可选**(对应 pip extras):
252
+ - `pygame-ce` — pygame 渲染器(`particlefx/renderers/pygame_renderer.py`)
253
+ - `Pillow` — PIL 渲染器(`particlefx/renderers/pil_renderer.py`)
254
+ - `numba` — JIT 更新内核
255
+ - `taichi` — WCSPH 流体后端
256
+ - `moderngl` — GPU 渲染器 / Compute Shader 模拟
257
+ - `jsonschema` — 效果配方 Schema 校验
258
+
259
+ ## v5.0 增强功能(2026)
260
+
261
+ 按"成本从低到高"落地的 9 项增强,全部保持**可选依赖零开销 + 向后兼容**:
262
+
263
+ | # | 增强 | 入口 | 可选依赖 |
264
+ |---|------|------|---------|
265
+ | ① | 对象池 + 空间哈希 | `ParticleSystem(use_pool=True, use_spatial_hash=True)` | 无 |
266
+ | ② | Numba JIT 更新内核 | `particlefx.core.particle_numba.NumbaParticleSystem` | numba |
267
+ | ③ | 软粒子深度淡出 | `GPUParticleRenderer(enable_depth_fade=True)` | moderngl |
268
+ | ④ | 浏览器 Web 导出 | `pygbag --app_name web_main examples` | pygbag |
269
+ | ⑤ | 粒子吸引子 + 粒子光源 | `ParticleAttractor` / `enable_pairwise_force` / `enable_particle_lights` | 无 |
270
+ | ⑥ | 可编程后处理链 | `particlefx.renderers.postfx.PostFXChain` | 无 |
271
+ | ⑦ | JSON Schema 校验 | `EffectsFactory(validate=True)` | jsonschema(可选) |
272
+ | ⑧ | Taichi SPH 流体 | `particlefx.core.particle_taichi.TaichiSPHSystem` | taichi |
273
+ | ⑨ | Compute 全 GPU 模拟 | `particlefx.renderers.particle_sim_gpu.GPUParticleSimulator` | moderngl |
274
+
275
+ 详见 [docs/enhancements.md](docs/enhancements.md)。
276
+
277
+ ## 许可证
278
+
279
+ MIT License(可自由复制、修改、使用)
280
+
281
+ ## 作者
282
+
283
+ - 全哥(独立开发者)
284
+ - AI 助手(WorkBuddy)
285
+
286
+ ## 更新日志
287
+
288
+ 详见 [CHANGELOG.md](CHANGELOG.md)。
289
+
290
+ - **2026-10-21**:v1.0.0 发布至 PyPI(发行名 `particlefx`),源码重组为 `particlefx/` 命名空间包
291
+ - **2026-06-23**:初始版本,创建核心类和示例效果