use std::path::PathBuf; use particle_system::{Particle, ParticleSystem, Point, Vector}; use ppm::PPM; use solver::Solver; mod constraint; mod particle_system; mod ppm; mod solver; fn main() { let ppm = PPM { width: 100, height: 200, prefix: PathBuf::from("./out"), }; let dt = 0.01; let mut system = ParticleSystem { particles: vec![ Particle::new(Point::origin(), 4.0), Particle::new(Point::new(-30.0, 0.0), 15.0), Particle::new(Point::new(20.0, 0.0), 30.0), Particle::new(Point::new(5.0, 20.0), 50.0), ], constraints: vec![], t: 0.0, }; system.add_anchor_constraint(0); system.add_beam_constraint([0, 2]); system.add_beam_constraint([1, 2]); system.add_beam_constraint([1, 3]); system.add_beam_constraint([2, 3]); let gravity = -9.8 * Vector::y(); for i in 0..150_00 { for particle in &mut system.particles { particle.reset_force(); // Apply custom forces particle.apply_force(gravity * particle.mass); } system.particles[0].apply_force(gravity); // Extra force on particle 0 if i % 10 == 0 { println!("Iteration #{i}"); println!("{:#?}", system.particles); ppm.save_frame(&system.particles, system.t); } system.enforce_constraints(dt); system.step(dt); } }