|
1 | 1 | extern crate vec3D;
|
2 | 2 |
|
| 3 | +mod ray; |
| 4 | + |
3 | 5 | use vec3D::Vec3D;
|
| 6 | +use ray::Ray; |
| 7 | + |
| 8 | +fn color(ray: Ray) -> Vec3D { |
| 9 | + let unit_direction = ray.direction.unit(); |
| 10 | + let t = 0.5 * (unit_direction.y + 1.0); |
| 11 | + (Vec3D::new(1.0, 1.0, 1.0) * (1.0 - t)) + (Vec3D::new(0.5, 0.7, 1.0) * t) |
| 12 | +} |
4 | 13 |
|
5 | 14 | fn main() {
|
6 |
| - let max_i = 200; |
7 |
| - let max_j = 200; |
| 15 | + let nx = 200; |
| 16 | + let ny = 100; |
| 17 | + |
| 18 | + println!("P3\n{} {} 255", nx, ny); |
8 | 19 |
|
9 |
| - println!("P3\n{} {} 255", max_i, max_j); |
10 |
| - for i in 0..max_i { |
11 |
| - for j in 0..max_j { |
| 20 | + let lower_left_corner = Vec3D::new(-2.0, -1.0, -1.0); |
| 21 | + let horizontal = Vec3D::new(4.0, 0.0, 0.0); |
| 22 | + let vertical = Vec3D::new(0.0, 2.0, 0.0); |
| 23 | + let origin = Vec3D::new(0.0, 0.0, 0.0); |
12 | 24 |
|
13 |
| - let col = Vec3D::new(i as f64 / max_i as f64, j as f64 / max_j as f64, 0.2); |
| 25 | + for j in (0..ny).rev() { |
| 26 | + for i in 0..nx { |
| 27 | + let u = i as f64 / nx as f64; |
| 28 | + let v = j as f64 / ny as f64; |
| 29 | + let r = Ray::new(origin, lower_left_corner + (horizontal * u) + (vertical * v)); |
| 30 | + let col = color(r); |
| 31 | + // println!("{}, t", col); |
14 | 32 | let r = (255.00 * col.x).round();
|
15 | 33 | let g = (255.00 * col.y).round();
|
16 | 34 | let b = (255.00 * col.z).round();
|
|
0 commit comments