simple-gas-sim/gas_sim.py

23 lines
828 B
Python
Raw Normal View History

2023-05-20 10:12:48 +02:00
from math import hypot
class GasSim:
2023-05-20 20:05:38 +02:00
def __init__(self, particle_radius, particle_compressibility, particle_friction, substeps):
2023-05-20 10:12:48 +02:00
self.particle_radius = particle_radius
self.particle_compressibility = particle_compressibility
2023-05-20 20:05:38 +02:00
self.particle_friction = particle_friction
2023-05-20 10:12:48 +02:00
self.substeps = substeps
self.particles = []
2023-05-20 20:05:38 +02:00
self.walls = []
2023-05-20 10:12:48 +02:00
def add_particle(self, pos, vel = (0, 0)):
2023-05-20 20:05:38 +02:00
self.particles.append([pos, vel])
2023-05-20 10:12:48 +02:00
def cursor_particle_collide_test(self, cursor_pos, cursor_radius):
for particle in self.particles:
2023-05-20 20:05:38 +02:00
if hypot(particle[0][0] - cursor_pos[0], particle[0][1] - cursor_pos[1]) <= cursor_radius + self.particle_radius:
return True
def add_wall(self, start, end):
self.walls.append((start, end))