first commit
This commit is contained in:
30
gas_sim.py
Normal file
30
gas_sim.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from math import hypot
|
||||
|
||||
|
||||
class Particle:
|
||||
def __init__(self, pos, vel):
|
||||
self.pos = pos
|
||||
self.vel = vel
|
||||
|
||||
def update(self, dt):
|
||||
self.pos = (self.pos[0] + self.vel[0] * dt, self.pos[1] + self.vel[1] * dt)
|
||||
|
||||
|
||||
class GasSim:
|
||||
def __init__(self, particle_radius, particle_compressibility, substeps):
|
||||
self.particle_radius = particle_radius
|
||||
self.particle_compressibility = particle_compressibility
|
||||
self.substeps = substeps
|
||||
|
||||
self.particles = []
|
||||
|
||||
def add_particle(self, pos, vel = (0, 0)):
|
||||
self.particles.append(Particle(pos, vel))
|
||||
|
||||
def return_particles_pos(self):
|
||||
return tuple(particle.pos for particle in self.particles)
|
||||
|
||||
def cursor_particle_collide_test(self, cursor_pos, cursor_radius):
|
||||
for particle in self.particles:
|
||||
if hypot(particle.pos[0] - cursor_pos[0], particle.pos[1] - cursor_pos[1]) <= cursor_radius + self.particle_radius:
|
||||
return True
|
||||
Reference in New Issue
Block a user