File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed
Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change 405405
406406 std::cout < < "P3\n" < < image_width < < ' ' < < image_height < < "\n255\n";
407407
408- for (int j = image_height-1; j > = 0; --j) {
409- std::clog < < "\rScanlines remaining: " < < j < < ' ' < < std::flush;
410- for (int i = 0; i < image_width; ++i) {
408+ // Scale factors to convert pixel location to the range [0,1].
409+ double xscale = (image_width < 2) ? 1.0 : (1.0 / (image_width - 1));
410+ double yscale = (image_height < 2) ? 1.0 : (1.0 / (image_height - 1));
411+
412+ for (int py = 0; py < image_height; ++py) {
413+ std::clog < < "\rScanlines remaining: " < < (image_height - py) < < ' ' < < std::flush;
414+ for (int px = 0; px < image_width; ++px) {
411415 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
412- color pixel_color(double(i)/(image_width-1), double(j)/(image_height-1) , 0.25);
416+ color pixel_color(xscale * px, yscale * py , 0.25);
413417 write_color(std::cout, pixel_color);
414418 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
415419 }
You can’t perform that action at this time.
0 commit comments