added cursor force and more other changes

This commit is contained in:
2023-05-21 01:08:22 +02:00
parent 77bc6c4c71
commit d2fd778fbc
4 changed files with 76 additions and 40 deletions

View File

@@ -2,22 +2,39 @@ from math import hypot
class GasSim:
def __init__(self, particle_radius, particle_compressibility, particle_friction, substeps):
def __init__(self, particle_radius, particle_compressibility, particle_friction, substeps, window_aspect):
self.particle_radius = particle_radius
self.particle_compressibility = particle_compressibility
self.particle_friction = particle_friction
self.substeps = substeps
self.window_aspect = window_aspect
self.particles = []
self.walls = []
def add_particle(self, pos, vel = (0, 0)):
self.particles.append([pos, vel])
def add_particle(self, pos, vel = [0, 0]):
self.particles.append([list(pos).copy(), vel.copy()])
def cursor_particle_collide_test(self, cursor_pos, cursor_radius):
def circle_particle_collide_test(self, pos, radius):
for particle in self.particles:
if hypot(particle[0][0] - cursor_pos[0], particle[0][1] - cursor_pos[1]) <= cursor_radius + self.particle_radius:
if hypot(particle[0][0] - pos[0], particle[0][1] - pos[1]) <= radius + self.particle_radius:
return True
def add_wall(self, start, end):
self.walls.append((start, end))
def circle_force(self, pos, radius, vector, dt):
for i, particle in enumerate(self.particles):
if hypot(particle[0][0] - pos[0], particle[0][1] - pos[1]) <= radius + self.particle_radius:
self.particles[i][1][0] += vector[0] * dt
self.particles[i][1][1] += vector[1] * dt
def update(self, dt):
# substeps
for _ in range(self.substeps):
# update particles
for i, particle in enumerate(self.particles):
#
# position
self.particles[i][0][0] += particle[1][0] * dt / self.substeps
self.particles[i][0][1] += particle[1][1] * dt / self.substeps