summaryrefslogtreecommitdiff
path: root/src/ppm.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/ppm.rs')
-rw-r--r--src/ppm.rs41
1 files changed, 0 insertions, 41 deletions
diff --git a/src/ppm.rs b/src/ppm.rs
deleted file mode 100644
index 01cdebb..0000000
--- a/src/ppm.rs
+++ /dev/null
@@ -1,41 +0,0 @@
-use std::{fs::File, io::Write, path::PathBuf};
-
-use crate::particle_system::{Particle, Vector, N, Scalar};
-
-pub struct PPM {
- pub prefix: PathBuf,
- pub width: usize,
- pub height: usize,
- // pixels_per_unit: usize,
-}
-
-impl PPM {
- fn render_particles(&self, particles: &Vec<Particle>) -> String {
- let mut s = format!("P3\n{} {}\n255\n", self.width, self.height);
- let white = "255 255 255 ";
- let black = "0 0 0 ";
-
- for pixel_row in 0..self.height {
- for pixel_col in 0..self.width {
- let point = Vector::new(pixel_col as Scalar, (pixel_row as Scalar) * -1.0)
- + Vector::new(self.width as Scalar / -2.0, self.height as Scalar / 2.0);
- let color = match particles.iter().any(|p| {
- (p.position - point).coords.norm() <= (p.mass).powf(1.0 / (N as f64))
- }) {
- true => black,
- false => white,
- };
- s += color;
- }
- }
- s
- }
-
- pub fn save_frame(&self, particles: &Vec<Particle>, time: Scalar) {
- let file_name = format!("frame-{:08.3}", time);
- let path = self.prefix.join(file_name);
- let mut file = File::create(path).unwrap();
- let data = self.render_particles(particles);
- file.write(data.as_bytes()).unwrap();
- }
-}