Skip to content

Commit 2c95eb8

Browse files
committed
Rename main color to pixel_color
This change also fixes references to the `ray_color` function, which used to be named just `color`. Work related to issue #422
1 parent eb5fceb commit 2c95eb8

File tree

6 files changed

+31
-31
lines changed

6 files changed

+31
-31
lines changed

books/RayTracingInOneWeekend.html

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,8 @@
344344
std::cerr << "\rScanlines remaining: " << j << ' ' << std::flush;
345345
for (int i = 0; i < image_width; ++i) {
346346
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
347-
vec3 color(double(i)/(image_width-1), double(j)/(image_height-1), 0.25);
348-
color.write_color(std::cout);
347+
vec3 pixel_color(double(i)/(image_width-1), double(j)/(image_height-1), 0.25);
348+
pixel_color.write_color(std::cout);
349349
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
350350
}
351351
}
@@ -411,8 +411,8 @@
411411
through pixels and computes the color seen in the direction of those rays. The involved steps are
412412
(1) calculate the ray from the eye to the pixel, (2) determine which objects the ray intersects, and
413413
(3) compute a color for that intersection point. When first developing a ray tracer, I always do a
414-
simple camera for getting the code up and running. I also make a simple `color(ray)` function that
415-
returns the color of the background (a simple gradient).
414+
simple camera for getting the code up and running. I also make a simple `ray_color(ray)` function
415+
that returns the color of the background (a simple gradient).
416416

417417
I’ve often gotten into trouble using square images for debugging because I transpose $x$ and $y$ too
418418
often, so I’ll stick with a 200×100 image. I’ll put the “eye” (or camera center if you think of a
@@ -459,9 +459,9 @@
459459
auto u = double(i) / (image_width-1);
460460
auto v = double(j) / (image_height-1);
461461
ray r(origin, lower_left_corner + u*horizontal + v*vertical);
462-
vec3 color = ray_color(r);
462+
vec3 pixel_color = ray_color(r);
463463
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
464-
color.write_color(std::cout);
464+
pixel_color.write_color(std::cout);
465465
}
466466
}
467467

@@ -1154,10 +1154,10 @@
11541154

11551155

11561156
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
1157-
vec3 color = ray_color(r, world);
1157+
vec3 pixel_color = ray_color(r, world);
11581158
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
11591159

1160-
color.write_color(std::cout);
1160+
pixel_color.write_color(std::cout);
11611161
}
11621162
}
11631163

@@ -1334,14 +1334,14 @@
13341334
std::cerr << "\rScanlines remaining: " << j << ' ' << std::flush;
13351335
for (int i = 0; i < image_width; ++i) {
13361336
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
1337-
vec3 color(0, 0, 0);
1337+
vec3 pixel_color(0, 0, 0);
13381338
for (int s = 0; s < samples_per_pixel; ++s) {
13391339
auto u = (i + random_double()) / (image_width-1);
13401340
auto v = (j + random_double()) / (image_height-1);
13411341
ray r = cam.get_ray(u, v);
1342-
color += ray_color(r, world);
1342+
pixel_color += ray_color(r, world);
13431343
}
1344-
color.write_color(std::cout, samples_per_pixel);
1344+
pixel_color.write_color(std::cout, samples_per_pixel);
13451345
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
13461346
}
13471347
}
@@ -1499,16 +1499,16 @@
14991499
for (int j = image_height-1; j >= 0; --j) {
15001500
std::cerr << "\rScanlines remaining: " << j << ' ' << std::flush;
15011501
for (int i = 0; i < image_width; ++i) {
1502-
vec3 color(0, 0, 0);
1502+
vec3 pixel_color(0, 0, 0);
15031503
for (int s = 0; s < samples_per_pixel; ++s) {
15041504
auto u = (i + random_double()) / (image_width-1);
15051505
auto v = (j + random_double()) / (image_height-1);
15061506
ray r = cam.get_ray(u, v);
15071507
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
1508-
color += ray_color(r, world, max_depth);
1508+
pixel_color += ray_color(r, world, max_depth);
15091509
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
15101510
}
1511-
color.write_color(std::cout, samples_per_pixel);
1511+
pixel_color.write_color(std::cout, samples_per_pixel);
15121512
}
15131513
}
15141514

@@ -1811,7 +1811,7 @@
18111811
`hit_record` is just a way to stuff a bunch of arguments into a struct so we can send them as a
18121812
group. When a ray hits a surface (a particular sphere for example), the material pointer in the
18131813
`hit_record` will be set to point at the material pointer the sphere was given when it was set up in
1814-
`main()` when we start. When the `color()` routine gets the `hit_record` it can call member
1814+
`main()` when we start. When the `ray_color()` routine gets the `hit_record` it can call member
18151815
functions of the material pointer to find out what ray, if any, is scattered.
18161816

18171817
<div class='together'>
@@ -1951,7 +1951,7 @@
19511951
</div>
19521952

19531953
<div class='together'>
1954-
We need to modify the color function to use this:
1954+
We need to modify the `ray_color()` function to use this:
19551955

19561956
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
19571957
vec3 ray_color(const ray& r, const hittable& world, int depth) {
@@ -2009,14 +2009,14 @@
20092009
for (int j = image_height-1; j >= 0; --j) {
20102010
std::cerr << "\rScanlines remaining: " << j << ' ' << std::flush;
20112011
for (int i = 0; i < image_width; ++i) {
2012-
vec3 color(0, 0, 0);
2012+
vec3 pixel_color(0, 0, 0);
20132013
for (int s = 0; s < samples_per_pixel; ++s) {
20142014
auto u = (i + random_double()) / (image_width-1);
20152015
auto v = (j + random_double()) / (image_height-1);
20162016
ray r = cam.get_ray(u, v);
2017-
color += ray_color(r, world, max_depth);
2017+
pixel_color += ray_color(r, world, max_depth);
20182018
}
2019-
color.write_color(std::cout, samples_per_pixel);
2019+
pixel_color.write_color(std::cout, samples_per_pixel);
20202020
}
20212021
}
20222022

books/RayTracingTheNextWeek.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@
902902
[Listing [texture]: <kbd>[texture.h]</kbd> A texture class]
903903

904904
<div class='together'>
905-
Now we can make textured materials by replacing the vec3 color with a texture pointer:
905+
Now we can make textured materials by replacing the `vec3 solid_color` with a texture pointer:
906906

907907
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
908908
class lambertian : public material {
@@ -1827,7 +1827,7 @@
18271827
...
18281828
const vec3 background(0,0,0);
18291829
...
1830-
color += ray_color(r, background, world, max_depth);
1830+
pixel_color += ray_color(r, background, world, max_depth);
18311831
...
18321832
}
18331833
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

books/RayTracingTheRestOfYourLife.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@
844844
</div>
845845

846846
<div class='together'>
847-
And the color function gets a minor modification:
847+
And the `ray_color` function gets a minor modification:
848848

849849
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
850850
vec3 ray_color(const ray& r, const vec3& background, const hittable& world, int depth) {

src/InOneWeekend/main.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,14 @@ int main() {
105105
for (int j = image_height-1; j >= 0; --j) {
106106
std::cerr << "\rScanlines remaining: " << j << ' ' << std::flush;
107107
for (int i = 0; i < image_width; ++i) {
108-
vec3 color;
108+
vec3 pixel_color;
109109
for (int s = 0; s < samples_per_pixel; ++s) {
110110
auto u = (i + random_double()) / image_width;
111111
auto v = (j + random_double()) / image_height;
112112
ray r = cam.get_ray(u, v);
113-
color += ray_color(r, world, max_depth);
113+
pixel_color += ray_color(r, world, max_depth);
114114
}
115-
color.write_color(std::cout, samples_per_pixel);
115+
pixel_color.write_color(std::cout, samples_per_pixel);
116116
}
117117
}
118118

src/TheNextWeek/main.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,14 +449,14 @@ int main() {
449449
for (int j = image_height-1; j >= 0; --j) {
450450
std::cerr << "\rScanlines remaining: " << j << ' ' << std::flush;
451451
for (int i = 0; i < image_width; ++i) {
452-
vec3 color;
452+
vec3 pixel_color;
453453
for (int s = 0; s < samples_per_pixel; ++s) {
454454
auto u = (i + random_double()) / image_width;
455455
auto v = (j + random_double()) / image_height;
456456
ray r = cam.get_ray(u, v);
457-
color += ray_color(r, background, world, max_depth);
457+
pixel_color += ray_color(r, background, world, max_depth);
458458
}
459-
color.write_color(std::cout, samples_per_pixel);
459+
pixel_color.write_color(std::cout, samples_per_pixel);
460460
}
461461
}
462462

src/TheRestOfYourLife/main.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,14 @@ int main() {
120120
for (int j = image_height-1; j >= 0; --j) {
121121
std::cerr << "\rScanlines remaining: " << j << ' ' << std::flush;
122122
for (int i = 0; i < image_width; ++i) {
123-
vec3 color;
123+
vec3 pixel_color;
124124
for (int s = 0; s < samples_per_pixel; ++s) {
125125
auto u = (i + random_double()) / image_width;
126126
auto v = (j + random_double()) / image_height;
127127
ray r = cam.get_ray(u, v);
128-
color += ray_color(r, background, world, lights, max_depth);
128+
pixel_color += ray_color(r, background, world, lights, max_depth);
129129
}
130-
color.write_color(std::cout, samples_per_pixel);
130+
pixel_color.write_color(std::cout, samples_per_pixel);
131131
}
132132
}
133133

0 commit comments

Comments
 (0)