From 818a403bf9d2a4f9bda7d4ef9275e14f16eeaaf9 Mon Sep 17 00:00:00 2001 From: Tim Diller Date: Wed, 29 Apr 2026 19:17:22 -0500 Subject: [PATCH] initial commit of particle cloud classes --- pyproject.toml | 13 +++++++++++++ src/particle_cloud/__init__.py | 3 +++ src/particle_cloud/stuff.py | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 pyproject.toml create mode 100644 src/particle_cloud/__init__.py create mode 100644 src/particle_cloud/stuff.py diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..acd06c1 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,13 @@ +[build-system] +requires = ["setuptools>=61"] +build-backend = "setuptools.build_meta" + +[project] +name = "particle-cloud" +version = "0.0.1" +description = "particle cloud computations" +requires-python = ">=3.10" +dependencies = [] + +[tool.setuptools.packages.find] +where = ["src"] diff --git a/src/particle_cloud/__init__.py b/src/particle_cloud/__init__.py new file mode 100644 index 0000000..f6f04b7 --- /dev/null +++ b/src/particle_cloud/__init__.py @@ -0,0 +1,3 @@ +from .stuff import Particle, cloud + +__all__ = ["Particle", "cloud"] diff --git a/src/particle_cloud/stuff.py b/src/particle_cloud/stuff.py new file mode 100644 index 0000000..b52c47d --- /dev/null +++ b/src/particle_cloud/stuff.py @@ -0,0 +1,33 @@ +class Particle: + def __init__(self, mass=1.0, velocity=None, position=None): + self.mass = mass + self.velocity = list(velocity if velocity is not None else [0.0, 0.0, 0.0]) + self.position = list(position if position is not None else [0.0, 0.0, 0.0]) + + def __repr__(self): + return f"Particle(mass={self.mass}, velocity={self.velocity}, position={self.position})" + + +class cloud: + def __init__(self, particles=None): + self.particles = list(particles or []) + + def add(self, p): + self.particles.append(p) + + def step(self, dt=1.0): + for p in self.particles: + p.position = [x + v * dt for x, v in zip(p.position, p.velocity)] + return self + + def center(self): + total = sum(p.mass for p in self.particles) + if total == 0: + return [0.0, 0.0, 0.0] + answer = [0.0, 0.0, 0.0] + for p in self.particles: + answer = [a + p.mass * x for a, x in zip(answer, p.position)] + return [x / total for x in answer] + + def __repr__(self): + return f"cloud({self.particles})"