fn random_scene() -> Arc<dyn Hittable + Sync + Send> {
    let mut world = HittableList::new();

    let ground_material = Arc::new(Lambertian::new(Color::new(0.5, 0.5, 0.5)));
    world.add(Arc::new(Sphere::new(
        Point3::new(0.0, -1000.0, 0.0),
        1000.0,
        ground_material,
    )));

    for a in -11..11 {
        for b in -11..11 {
            let choose_mat = canonical_random();
            let center = Point3::new(
                a as f64 + 0.9 * canonical_random(),
                0.2,
                b as f64 + 0.9 * canonical_random(),
            );

            if (center - Point3::new(4.0, 0.2, 0.0)).length() > 0.9 {
                if choose_mat < 0.8 {
                    // Diffuse
                    let albedo = Color::random() * Color::random();
                    let sphere_material = Arc::new(Lambertian::new(albedo));
                    world.add(Arc::new(Sphere::new(center, 0.2, sphere_material)));
                } else if choose_mat < 0.95 {
                    // Metal
                    let albedo = Color::random_range(0.5, 1.0);
                    let fuzz = random_range(0.0, 0.5);
                    let sphere_material = Arc::new(Metal::new(albedo, fuzz));
                    world.add(Arc::new(Sphere::new(center, 0.2, sphere_material)));
                } else {
                    // Glass
                    let sphere_material = Arc::new(Dielectric::new(1.5));
                    world.add(Arc::new(Sphere::new(center, 0.2, sphere_material)));
                }
            }
        }
    }

    let material1 = Arc::new(Dielectric::new(1.5));
    world.add(Arc::new(Sphere::new(
        Point3::new(0.0, 1.0, 0.0),
        1.0,
        material1,
    )));

    let material2 = Arc::new(Lambertian::new(Color::new(0.4, 0.2, 0.1)));
    world.add(Arc::new(Sphere::new(
        Point3::new(-4.0, 1.0, 0.0),
        1.0,
        material2,
    )));

    let material3 = Arc::new(Metal::new(Color::new(0.7, 0.6, 0.5), 0.0));
    world.add(Arc::new(Sphere::new(
        Point3::new(4.0, 1.0, 0.0),
        1.0,
        material3,
    )));

    Arc::new(world)
}
/// Generate a scene with random small spheres and three big spheres
Generate a scene with random small spheres and three big spheres
Generate a scene with random small spheres and three big spheres
fn random_scene() -> Arc<dyn Hittable + Sync + Send> {
    let mut world = HittableList::new();
    let ground_material = Arc::new(Lambertian::new(Color::new(0.5, 0.5, 0.5)));
    world.add(Arc::new(Sphere::new(
        Point3::new(0.0, -1000.0, 0.0),
        1000.0,
        ground_material,
    )));
    for a in -11..11 {
        for b in -11..11 {
            let choose_mat = canonical_random();
            let center = Point3::new(
                a as f64 + 0.9 * canonical_random(),
                0.2,
                b as f64 + 0.9 * canonical_random(),
            );
            if (center - Point3::new(4.0, 0.2, 0.0)).length() > 0.9 {
                if choose_mat < 0.8 {
                    // Diffuse
                    let albedo = Color::random() * Color::random();
                    let sphere_material = Arc::new(Lambertian::new(albedo));
                    world.add(Arc::new(Sphere::new(center, 0.2, sphere_material)));
                } else if choose_mat < 0.95 {
                    // Metal
                    let albedo = Color::random_range(0.5, 1.0);
                    let fuzz = random_range(0.0, 0.5);
                    let sphere_material = Arc::new(Metal::new(albedo, fuzz));
                    world.add(Arc::new(Sphere::new(center, 0.2, sphere_material)));
                } else {
                    // Glass
                    let sphere_material = Arc::new(Dielectric::new(1.5));
                    world.add(Arc::new(Sphere::new(center, 0.2, sphere_material)));
                }
            }
        }
    }
    let material1 = Arc::new(Dielectric::new(1.5));
    world.add(Arc::new(Sphere::new(
        Point3::new(0.0, 1.0, 0.0),
        1.0,
        material1,
    )));
    let material2 = Arc::new(Lambertian::new(Color::new(0.4, 0.2, 0.1)));
    world.add(Arc::new(Sphere::new(
        Point3::new(-4.0, 1.0, 0.0),
        1.0,
        material2,
    )));
    let material3 = Arc::new(Metal::new(Color::new(0.7, 0.6, 0.5), 0.0));
    world.add(Arc::new(Sphere::new(
        Point3::new(4.0, 1.0, 0.0),
        1.0,
        material3,
    )));
    Arc::new(world)
}
fn random_scene ( ) -> Arc < dyn Hittable + Sync + Send > { let mut world = HittableList :: new ( ) ; let ground_material = Arc :: new ( Lambertian :: new ( Color :: new ( 0.5 , 0.5 , 0.5 ) ) ) ; world . add ( Arc :: new ( Sphere :: new ( Point3 :: new ( 0.0 , - 1000.0 , 0.0 ) , 1000.0 , ground_material , ) ) ) ; for a in - 11 .. 11 { for b in - 11 .. 11 { let choose_mat = canonical_random ( ) ; let center = Point3 :: new ( a as f64 + 0.9 * canonical_random ( ) , 0.2 , b as f64 + 0.9 * canonical_random ( ) , ) ; if ( center - Point3 :: new ( 4.0 , 0.2 , 0.0 ) ) . length ( ) > 0.9 { if choose_mat < 0.8 { // Diffuse let albedo = Color :: random ( ) * Color :: random ( ) ; let sphere_material = Arc :: new ( Lambertian :: new ( albedo ) ) ; world . add ( Arc :: new ( Sphere :: new ( center , 0.2 , sphere_material ) ) ) ; } else if choose_mat < 0.95 { // Metal let albedo = Color :: random_range ( 0.5 , 1.0 ) ; let fuzz = random_range ( 0.0 , 0.5 ) ; let sphere_material = Arc :: new ( Metal :: new ( albedo , fuzz ) ) ; world . add ( Arc :: new ( Sphere :: new ( center , 0.2 , sphere_material ) ) ) ; } else { // Glass let sphere_material = Arc :: new ( Dielectric :: new ( 1.5 ) ) ; world . add ( Arc :: new ( Sphere :: new ( center , 0.2 , sphere_material ) ) ) ; } } } } let material1 = Arc :: new ( Dielectric :: new ( 1.5 ) ) ; world . add ( Arc :: new ( Sphere :: new ( Point3 :: new ( 0.0 , 1.0 , 0.0 ) , 1.0 , material1 , ) ) ) ; let material2 = Arc :: new ( Lambertian :: new ( Color :: new ( 0.4 , 0.2 , 0.1 ) ) ) ; world . add ( Arc :: new ( Sphere :: new ( Point3 :: new ( - 4.0 , 1.0 , 0.0 ) , 1.0 , material2 , ) ) ) ; let material3 = Arc :: new ( Metal :: new ( Color :: new ( 0.7 , 0.6 , 0.5 ) , 0.0 ) ) ; world . add ( Arc :: new ( Sphere :: new ( Point3 :: new ( 4.0 , 1.0 , 0.0 ) , 1.0 , material3 , ) ) ) ; Arc :: new ( world ) }
Generate a scene with random small spheres and three big spheres
Generate a scene with random small spheres and three big spheres