sandpypi/simulation_core.pyx
Stan44 05e37a0bd5 made small updates to the spatial grid
rearranged some of the code for better readability
2024-12-26 14:22:19 -06:00

37 lines
912 B
Cython

# simulation_core.pyx
# Cython code for simulating the physics of the system
cimport cython
from libc.math cimport sqrt
cdef class CParticle:
cdef float x, y, vx, vy, mass, gravity
def __init__(self, float x, float y, float vx, float vy, float mass, float gravity):
self.x = x
self.y = y
self.vx = vx
self.vy = vy
self.mass = mass
self.gravity = gravity
cpdef void apply_gravity(self, float dt):
self.vy += self.gravity * dt
self.y += self.vy * dt
self.x += self.vx * dt
cdef class SimulationCore:
cdef list particles
def __init__(self):
self.particles = []
cpdef void add_particle(self, CParticle particle):
self.particles.append(particle)
cpdef void update(self, float dt):
cdef CParticle particle
for particle in self.particles:
particle.apply_gravity(dt)