can make a ppm
This commit is contained in:
33
src/main.rs
33
src/main.rs
@@ -1,6 +1,10 @@
|
||||
use canvas::Canvas;
|
||||
use color::Color;
|
||||
use structs::Tuple;
|
||||
|
||||
use std::fmt;
|
||||
use std::fs::File;
|
||||
use std::io::prelude::*;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Environment {
|
||||
@@ -57,15 +61,30 @@ fn main() {
|
||||
|
||||
let mut ball = Projectile::new(
|
||||
Tuple::point(0.0, 0.0, 1.0),
|
||||
Tuple::vector(10.0, 0.0, 100.0),
|
||||
Tuple::vector(2.2, 0.0, 21.0),
|
||||
);
|
||||
|
||||
let mut tick = 0;
|
||||
println!("tick {} the ball {}", tick, ball);
|
||||
while ball.position.z() > 0.0 {
|
||||
ball.tick(&env);
|
||||
let mut canvas = Canvas::new(300, 300);
|
||||
let color = Color::new(1.0, 1.0, 0.0);
|
||||
while ball.position.z() < canvas.height() as f32
|
||||
&& ball.position.z() >= 0.0
|
||||
&& ball.position.x() < canvas.width() as f32
|
||||
&& ball.position.x() >= 0.0 {
|
||||
canvas.write_pixel(ball.position.x() as usize, canvas.height() - ball.position.z() as usize, color);
|
||||
|
||||
println!("tick {} the ball {}", tick, ball);
|
||||
tick += 1;
|
||||
ball.tick(&env);
|
||||
}
|
||||
|
||||
let ppm = canvas.to_ppm();
|
||||
|
||||
let mut f = match File::create("out.ppm") {
|
||||
Ok(f) => f,
|
||||
Err(e) => panic!("file error. {}", e),
|
||||
};
|
||||
|
||||
let _ = match f.write_all(ppm.as_bytes()) {
|
||||
Ok(w) => w,
|
||||
Err(e) => panic!("did not write. {}", e),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user