11extern crate raylib;
22
3+ use rand:: prelude:: * ;
34use raylib:: {
45 camera:: Camera , file:: File , hittable:: Hittables , lambertian:: Lambertian , random,
5- random_unit_vector , sphere:: Sphere , vec:: Vec3 , write_color,
6+ sphere:: Sphere , vec:: Vec3 , write_color,
67} ;
78
89fn main ( ) {
10+ let mut rng = thread_rng ( ) ;
11+
912 // image
1013 let aspect_ratio = 16.0 / 9.0 ;
1114 let width = 400 ;
@@ -15,15 +18,11 @@ fn main() {
1518 println ! ( "image h {} w {}" , height, width) ;
1619
1720 // camera
18- let camera = Camera :: with_vfov ( 90.0 , aspect_ratio) ;
21+ let camera = Camera :: new11_1 ( 90.0 , aspect_ratio) ;
1922
2023 // world
21- let left = Lambertian {
22- albedo : Vec3 :: new ( 0.0 , 0.0 , 1.0 ) ,
23- } ;
24- let right = Lambertian {
25- albedo : Vec3 :: new ( 1.0 , 0.0 , 0.0 ) ,
26- } ;
24+ let left = Lambertian :: new ( Vec3 :: new ( 0.0 , 0.0 , 1.0 ) ) ;
25+ let right = Lambertian :: new ( Vec3 :: new ( 1.0 , 0.0 , 0.0 ) ) ;
2726
2827 let mut world: Hittables = Hittables {
2928 list : std:: vec:: Vec :: new ( ) ,
@@ -49,19 +48,12 @@ fn main() {
4948 for w in 0 ..width {
5049 let mut pixel_color = Vec3 :: new ( 0.0 , 0.0 , 0.0 ) ;
5150 for _ in 0 ..samples_per_pixel {
52- let u: f64 = ( w as f64 + random ( ) ) / ( width as f64 - 1.0 ) ;
53- let v: f64 = ( h as f64 + random ( ) ) / ( height as f64 - 1.0 ) ;
51+ let u: f64 = ( w as f64 + random ( & mut rng ) ) / ( width as f64 - 1.0 ) ;
52+ let v: f64 = ( h as f64 + random ( & mut rng ) ) / ( height as f64 - 1.0 ) ;
5453 let ray = camera. ray ( u, v) ;
55- let world_hit_t_min = 0.001 ;
56- pixel_color = pixel_color
57- + ray. diffused_world_color (
58- & world,
59- max_depth,
60- world_hit_t_min,
61- random_unit_vector,
62- ) ;
54+ pixel_color = pixel_color + ray. color_09_4 ( & world, max_depth, & mut rng) ;
6355 }
64- write_color ( & output, pixel_color, samples_per_pixel, false ) ;
56+ write_color ( & output, pixel_color, samples_per_pixel, true ) ;
6557 }
6658 }
6759 println ! ( "DONE" )
0 commit comments