Skip to content

Commit 553bac0

Browse files
committed
Book style pass
Resolves #16
1 parent d4af17a commit 553bac0

File tree

5 files changed

+115
-23
lines changed

5 files changed

+115
-23
lines changed

books/RayTracingInOneWeekend.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@
752752
function returns a random integer in the range 0 and RANDMAX. Hence we can get a real random number
753753
as desired with the following code snippet:
754754

755-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
755+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
756756
#ifndef RANDOMH
757757
#define RANDOMH
758758

@@ -762,13 +762,13 @@
762762
return rand() / (RAND_MAX + 1.0);
763763
}
764764
#endif
765-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
765+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
766766

767767
C++ did not traditionally have a standard random number generator, but newer versions of C++ have
768768
addressed this issue with the `<random>` header (if imperfectly according to some experts).
769769
If you want to use this, you can obtain a random number with the conditions we need as follows:
770770

771-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
771+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
772772
#ifndef RANDOMH
773773
#define RANDOMH
774774

@@ -783,7 +783,7 @@
783783
return rand_generator();
784784
}
785785
#endif
786-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
786+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
787787

788788
For a given pixel we have several samples within that pixel and send rays through each of the
789789
samples. The colors of these rays are then averaged:
@@ -902,6 +902,8 @@
902902
}
903903
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
904904

905+
Then update the `color()` function to use the new random direction generator:
906+
905907
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
906908
vec3 color(const ray& r, hitable *world, int depth) {
907909
hit_record rec;

books/RayTracingTheNextWeek.html

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -737,9 +737,7 @@
737737
public:
738738
virtual vec3 value(float u, float v, const vec3& p) const = O;
739739
};
740-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
741740

742-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
743741
class constant_texture : public texture {
744742
public:
745743
constant_texture() ( }
@@ -1070,13 +1068,13 @@
10701068

10711069
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
10721070
static vec3* perlin_generate() {
1073-
vec3 * p = new vec3[256];
1074-
for ( int i = 0; i < 256; ++i )
1075-
p[i] = unit_vector(vec3(
1076-
-1 + 2*random_double(),
1077-
-1 + 2*random_double(),
1078-
-1 + 2*random_double()
1079-
));
1071+
vec3 *p = new vec3[256];
1072+
for (int i = 0; i < 256; ++i) {
1073+
double x_random = 2*random_double() - 1;
1074+
double y_random = 2*random_double() - 1;
1075+
double z_random = 2*random_double() - 1;
1076+
p[i] = unit_vector(vec3(x_random, y_random, z_random));
1077+
}
10801078
return p;
10811079
}
10821080
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

books/RayTracingTheRestOfYourLife.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55

6-
**Ray tracing: The Rest of Your Life**
6+
**Ray Tracing: The Rest of Your Life**
77
Peter Shirley
88
Version 1.123
99
<br>Copyright 2018. Peter Shirley. All rights reserved.

src/TheNextWeek/perlin.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,13 @@ class perlin {
6464
};
6565

6666
static vec3* perlin_generate() {
67-
vec3 * p = new vec3[256];
68-
for ( int i = 0; i < 256; ++i )
69-
p[i] = unit_vector(vec3(-1 + 2*random_double(), -1 + 2*random_double(), -1 + 2*random_double()));
67+
vec3 *p = new vec3[256];
68+
for (int i = 0; i < 256; ++i) {
69+
double x_random = 2*random_double() - 1;
70+
double y_random = 2*random_double() - 1;
71+
double z_random = 2*random_double() - 1;
72+
p[i] = unit_vector(vec3(x_random, y_random, z_random));
73+
}
7074
return p;
7175
}
7276

style/book.css

Lines changed: 94 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
body {
2-
}
3-
41
/* Under-Development Warning Box */
52

63
div.warning {
7-
background: #fee;
8-
margin: 1em 4em 4em 4em;
4+
background: #fdd;
5+
margin: 1em 4em;
96
border: solid 4px red;
10-
padding: 0em 4ex 1em 4ex;
7+
padding: 0em 4ex;
118
}
129

1310
div.warning a {
@@ -28,6 +25,97 @@ div.warning p.title {
2825
color: red;
2926
}
3027

28+
29+
/* General Body Styles */
30+
31+
body {
32+
font-family: sans-serif;
33+
}
34+
35+
.md a {
36+
font-family: sans-serif;
37+
}
38+
39+
.md div.title {
40+
font-size: 220%;
41+
letter-spacing: -0.06em;
42+
}
43+
44+
.md .subtitle {
45+
font-size: 100%;
46+
font-style: italic;
47+
}
48+
49+
.md .longTOC, .md .mediumTOC, .md .shortTOC {
50+
font-family: sans-serif;
51+
}
52+
53+
.md .longTOC {
54+
width: 72%;
55+
margin: 2em auto 0 auto;
56+
padding: 0 4ex 1em 4ex;
57+
border: solid 4px #e0e0d0;
58+
background: #e4e4d8;
59+
}
60+
61+
.md .tocHeader {
62+
font-size: 165%;
63+
margin-bottom: -1em;
64+
border-bottom: solid 4px #777;
65+
}
66+
67+
.md h1 {
68+
font-size: 165%;
69+
letter-spacing: -0.05ex;
70+
margin-top: 2em;
71+
padding-top: 0.25em;
72+
border-bottom: solid 4px #777;
73+
text-align: left;
74+
}
75+
76+
.md h1::before {
77+
content: counter(h1) ". ";
78+
}
79+
80+
.md h2::before {
81+
content: counter(h1) "." counter(h2) ". ";
82+
}
83+
84+
85+
/* Code */
86+
87+
.md code {
88+
font-family: Consolas, Menlo, monospace;
89+
color: #000;
90+
}
91+
92+
.md p code {
93+
padding: 0 .4ex;
94+
background: #e4e4e0;
95+
}
96+
97+
.md pre.listing.tilde {
98+
border: solid 3px #d4d4d4;
99+
background: #e4e4e0;
100+
}
101+
102+
.md pre.listing.tilde code {
103+
font-size: 86%;
104+
}
105+
106+
.md .hljs-meta {
107+
color: #d60;
108+
}
109+
110+
.md .hljs-title {
111+
font-weight: bold;
112+
}
113+
114+
.md .hljs-number {
115+
color: #0a0;
116+
}
117+
118+
31119
/* Images and Figures */
32120

33121
.md img {

0 commit comments

Comments
 (0)