Skip to content

Commit 89a2bf5

Browse files
committed
fix weird lines when aspect ratio not 1:1
1 parent 5297511 commit 89a2bf5

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/camera.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl Camera {
2727
println!("P3\n{} {}\n255", self.image_width, self.image_height);
2828
for j in 0..=self.image_height {
2929
eprint!("\rScanlines remaining: {} ", self.image_height-j);
30-
for i in 0..self.image_height {
30+
for i in 0..self.image_width {
3131
let mut pixel_color = Color::new();
3232
for _ in 0..self.sample_per_pixel {
3333
let r = self.get_ray(i, j);
@@ -39,7 +39,7 @@ impl Camera {
3939
eprintln!("\rDone. \n");
4040
}
4141
fn initialize(&mut self) {
42-
//BUG when proportion != 1.0
42+
// Fix image stretcheness
4343
self.image_height = (self.image_width as f32/self.aspect_ratio) as i32;
4444
self.image_height = if self.image_height < 1 {1} else {self.image_height};
4545

src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn main() {
1616
world.add(Box::from(Sphere::new(Point3::from(0.0, 0.0, -1.0), 0.5)));
1717
world.add(Box::from(Sphere::new(Point3::from(0.0, -100.5, -1.0), 100.0)));
1818

19-
let mut cam = Camera::new(1.0, 400);
19+
let mut cam = Camera::new(16.0/9.0, 400);
2020
cam.sample_per_pixel = 100;
2121

2222
cam.render(&world);

0 commit comments

Comments
 (0)