|
76 | 76 | #include <iostream>
|
77 | 77 |
|
78 | 78 | int main() {
|
79 |
| - const int image_width = 200; |
80 |
| - const int image_height = 100; |
| 79 | + const int image_width = 256; |
| 80 | + const int image_height = 256; |
81 | 81 |
|
82 | 82 | std::cout << "P3\n" << image_width << ' ' << image_height << "\n255\n";
|
83 | 83 |
|
84 | 84 | for (int j = image_height-1; j >= 0; --j) {
|
85 | 85 | for (int i = 0; i < image_width; ++i) {
|
86 |
| - auto r = double(i) / image_width; |
87 |
| - auto g = double(j) / image_height; |
88 |
| - auto b = 0.2; |
| 86 | + auto r = double(i) / (image_width-1); |
| 87 | + auto g = double(j) / (image_height-1); |
| 88 | + auto b = 0.25; |
| 89 | + |
89 | 90 | int ir = static_cast<int>(255.999 * r);
|
90 | 91 | int ig = static_cast<int>(255.999 * g);
|
91 | 92 | int ib = static_cast<int>(255.999 * b);
|
| 93 | + |
92 | 94 | std::cout << ir << ' ' << ig << ' ' << ib << '\n';
|
93 | 95 | }
|
94 | 96 | }
|
|
144 | 146 |
|
145 | 147 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
146 | 148 | P3
|
147 |
| - 200 100 |
| 149 | + 256 256 |
148 | 150 | 255
|
149 |
| - 0 253 51 |
150 |
| - 1 253 51 |
151 |
| - 2 253 51 |
152 |
| - 3 253 51 |
153 |
| - 5 253 51 |
154 |
| - 6 253 51 |
155 |
| - 7 253 51 |
156 |
| - 8 253 51 |
| 151 | + 0 255 63 |
| 152 | + 1 255 63 |
| 153 | + 2 255 63 |
| 154 | + 3 255 63 |
| 155 | + 4 255 63 |
| 156 | + 5 255 63 |
| 157 | + 6 255 63 |
| 158 | + 7 255 63 |
| 159 | + 8 255 63 |
| 160 | + 9 255 63 |
| 161 | + ... |
157 | 162 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
158 | 163 | [Listing [first-img]: First image output]
|
159 | 164 | </div>
|
|
180 | 185 | std::cerr << "\rScanlines remaining: " << j << ' ' << std::flush;
|
181 | 186 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
182 | 187 | for (int i = 0; i < image_width; ++i) {
|
183 |
| - auto r = double(i) / image_width; |
184 |
| - auto g = double(j) / image_height; |
185 |
| - auto b = 0.2; |
| 188 | + auto r = double(i) / (image_width-1); |
| 189 | + auto g = double(j) / (image_height-1); |
| 190 | + auto b = 0.25; |
| 191 | + |
186 | 192 | int ir = static_cast<int>(255.999 * r);
|
187 | 193 | int ig = static_cast<int>(255.999 * g);
|
188 | 194 | int ib = static_cast<int>(255.999 * b);
|
| 195 | + |
189 | 196 | std::cout << ir << ' ' << ig << ' ' << ib << '\n';
|
190 | 197 | }
|
191 | 198 | }
|
|
328 | 335 | #include <iostream>
|
329 | 336 |
|
330 | 337 | int main() {
|
331 |
| - const int image_width = 200; |
332 |
| - const int image_height = 100; |
| 338 | + const int image_width = 256; |
| 339 | + const int image_height = 256; |
333 | 340 |
|
334 | 341 | std::cout << "P3\n" << image_width << ' ' << image_height << "\n255\n";
|
335 | 342 |
|
336 | 343 | for (int j = image_height-1; j >= 0; --j) {
|
337 | 344 | std::cerr << "\rScanlines remaining: " << j << ' ' << std::flush;
|
338 | 345 | for (int i = 0; i < image_width; ++i) {
|
339 | 346 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
340 |
| - vec3 color(double(i)/image_width, double(j)/image_height, 0.2); |
| 347 | + vec3 color(double(i)/(image_width-1), double(j)/(image_height-1), 0.25); |
341 | 348 | color.write_color(std::cout);
|
342 | 349 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
343 | 350 | }
|
|
346 | 353 | std::cerr << "\nDone.\n";
|
347 | 354 | }
|
348 | 355 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
349 |
| - [Listing [main-gradient]: <kbd>[main.cc]</kbd> Creating a color gradient image] |
| 356 | + [Listing [ppm-2]: <kbd>[main.cc]</kbd> Final code for the first PPM image |
350 | 357 | </div>
|
351 | 358 |
|
352 | 359 |
|
|
448 | 455 | std::cerr << "\rScanlines remaining: " << j << ' ' << std::flush;
|
449 | 456 | for (int i = 0; i < image_width; ++i) {
|
450 | 457 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
451 |
| - auto u = double(i) / image_width; |
452 |
| - auto v = double(j) / image_height; |
| 458 | + auto u = double(i) / (image_width-1); |
| 459 | + auto v = double(j) / (image_height-1); |
453 | 460 | ray r(origin, lower_left_corner + u*horizontal + v*vertical);
|
454 | 461 | vec3 color = ray_color(r);
|
455 | 462 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
|
1138 | 1145 | for (int j = image_height-1; j >= 0; --j) {
|
1139 | 1146 | std::cerr << "\rScanlines remaining: " << j << ' ' << std::flush;
|
1140 | 1147 | for (int i = 0; i < image_width; ++i) {
|
1141 |
| - auto u = double(i) / image_width; |
1142 |
| - auto v = double(j) / image_height; |
| 1148 | + auto u = double(i) / (image_width-1); |
| 1149 | + auto v = double(j) / (image_height-1); |
1143 | 1150 | ray r(origin, lower_left_corner + u*horizontal + v*vertical);
|
1144 | 1151 |
|
1145 | 1152 |
|
|
1326 | 1333 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
1327 | 1334 | vec3 color(0, 0, 0);
|
1328 | 1335 | for (int s = 0; s < samples_per_pixel; ++s) {
|
1329 |
| - auto u = (i + random_double()) / image_width; |
1330 |
| - auto v = (j + random_double()) / image_height; |
| 1336 | + auto u = (i + random_double()) / (image_width-1); |
| 1337 | + auto v = (j + random_double()) / (image_height-1); |
1331 | 1338 | ray r = cam.get_ray(u, v);
|
1332 | 1339 | color += ray_color(r, world);
|
1333 | 1340 | }
|
|
1491 | 1498 | for (int i = 0; i < image_width; ++i) {
|
1492 | 1499 | vec3 color(0, 0, 0);
|
1493 | 1500 | for (int s = 0; s < samples_per_pixel; ++s) {
|
1494 |
| - auto u = (i + random_double()) / image_width; |
1495 |
| - auto v = (j + random_double()) / image_height; |
| 1501 | + auto u = (i + random_double()) / (image_width-1); |
| 1502 | + auto v = (j + random_double()) / (image_height-1); |
1496 | 1503 | ray r = cam.get_ray(u, v);
|
1497 | 1504 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
1498 | 1505 | color += ray_color(r, world, max_depth);
|
|
2001 | 2008 | for (int i = 0; i < image_width; ++i) {
|
2002 | 2009 | vec3 color(0, 0, 0);
|
2003 | 2010 | for (int s = 0; s < samples_per_pixel; ++s) {
|
2004 |
| - auto u = (i + random_double()) / image_width; |
2005 |
| - auto v = (j + random_double()) / image_height; |
| 2011 | + auto u = (i + random_double()) / (image_width-1); |
| 2012 | + auto v = (j + random_double()) / (image_height-1); |
2006 | 2013 | ray r = cam.get_ray(u, v);
|
2007 | 2014 | color += ray_color(r, world, max_depth);
|
2008 | 2015 | }
|
|
0 commit comments