Skip to content

Commit

Permalink
fix weird lines when aspect ratio not 1:1
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy5909 committed Apr 28, 2024
1 parent 5297511 commit 89a2bf5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl Camera {
println!("P3\n{} {}\n255", self.image_width, self.image_height);
for j in 0..=self.image_height {
eprint!("\rScanlines remaining: {} ", self.image_height-j);
for i in 0..self.image_height {
for i in 0..self.image_width {
let mut pixel_color = Color::new();
for _ in 0..self.sample_per_pixel {
let r = self.get_ray(i, j);
Expand All @@ -39,7 +39,7 @@ impl Camera {
eprintln!("\rDone. \n");
}
fn initialize(&mut self) {
//BUG when proportion != 1.0
// Fix image stretcheness
self.image_height = (self.image_width as f32/self.aspect_ratio) as i32;
self.image_height = if self.image_height < 1 {1} else {self.image_height};

Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn main() {
world.add(Box::from(Sphere::new(Point3::from(0.0, 0.0, -1.0), 0.5)));
world.add(Box::from(Sphere::new(Point3::from(0.0, -100.5, -1.0), 100.0)));

let mut cam = Camera::new(1.0, 400);
let mut cam = Camera::new(16.0/9.0, 400);
cam.sample_per_pixel = 100;

cam.render(&world);
Expand Down

0 comments on commit 89a2bf5

Please sign in to comment.