-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path101ray.cc
43 lines (31 loc) · 956 Bytes
/
101ray.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include "ray.h"
vec3 colour (const ray& r) {
vec3 unit_direction = unit_vector(r.direction());
double t = 0.5 * (unit_direction.y() + 1.0);
return (1.0 - t) * vec3(1.0, 1.0, 1.0) + t * vec3(0.5, 0.7, 1.0);
}
int main () {
freopen("101ray.ppm", "w", stdout);
int nx = 2000;
int ny = 1000;
std::cout << "P3\n" << nx << " " << ny << "\n255\n";
vec3 lower_left_corner (-2.0, -1.0, -1.0);
vec3 horizontal (4.0, 0.0, 0.0);
vec3 vertical (0.0, 2.0, 0.0);
vec3 origin (0.0, 0.0, 0.0);
for (int j = ny - 1; j >= 0; j--) {
for (int i = 0; i < nx; i++) {
double u = double(i) / double(nx);
double v = double(j) / double(ny);
ray r (origin, lower_left_corner + u * horizontal + v * vertical);
vec3 col = colour(r);
int ir = int(255.99 * col[0]);
int ig = int(255.99 * col[1]);
int ib = int(255.99 * col[2]);
std::cout << ir << " " << ig << " " << ib << "\n";
}
}
fclose(stdout);
return 0;
}