def main():
    floor = plane()
    floor.material = material()
    floor.material.color = color(0.9, 0.35, 0.25)
    floor.material.specular = 0
    
    
    middle = sphere(sphere_material=material(material_color=color(0.05, 0.5, 0.25), diffuse=0.25, specular=0.8,
                                                                  transparency=0.97, refractive_index=1.5,
                                                                  shininess=300,
                                                                  pattern=stripe_pattern(color(0.05, 0.5, 0.25),
                                                                                         color(0.5, 0.25, 0.05), transform=scaling(0.25, 0.25, 0.25))),
                    sphere_transform=translation(-0.5, 1, 0.5))
        
    right  = sphere(sphere_material=material(material_color=color(0.15, 0, 0),
                                                                  diffuse=0.15, specular=0.95, transparency = 0.95,
                                                                  reflective=0.98, ambient=0.01, refractive_index=1.5,
                                                                  shininess=300),
                    sphere_transform=np.matmul(translation(1.5, 0.5, -0.5), scaling(0.65, 0.65, 0.65)))
        
    left  = cube(cube_material=material(material_color=color(0.2, 0.2, 0.4), diffuse=0.2, specular=0.9, transparency=0.9, shininess=250, refractive_index=1.25),
                    cube_transform=np.matmul(translation(-1.5, 0.33, -0.75), scaling(0.4, 0.4, 0.4)))
        
    light_source = point_light(point(-10, 10, -10), color(1, 1, 1))
    
    this_world = world()
    this_world.objects=[floor, middle, left, right]
    this_world.light = [light_source]
    
    this_camera = camera(1600, 800, np.pi/3)
    this_camera.set_transform(view_transform(point(0, 1.5, -5), point(0, 1, 0), vector(0, 1, 0)))
    
    c = render(this_camera, this_world)
    c.write_image("second_render_cubeC.png")
def step_impl_ray_intersect_list_count(context, item, element, red, green,
                                       blue):
    assert (item in context.dict.keys())
    local_object_str = "context.dict['" + str(item) + "']." + str(element)
    local_object = eval(local_object_str)
    value = color(np.float32(red), np.float32(green), np.float32(blue))
    assert (equal(local_object, value))
def step_impl_point_light_for_materials(context, item, px, py, pz, red, green,
                                        blue):
    ensure_context_has_dict(context)

    real_position = point(float(px), float(py), float(pz))
    real_intensity = color(float(red), float(green), float(blue))
    context.dict[item] = point_light(real_position, real_intensity)
def step_impl_point_light_for_world(context, item, px, py, pz, red, green,
                                    blue):
    ensure_context_has_dict(context)

    real_position = point(np.float32(px), np.float32(py), np.float32(pz))
    real_intensity = color(np.float32(red), np.float32(green),
                           np.float32(blue))
    context.dict[item].light = [point_light(real_position, real_intensity)]
def step_impl_sphere_with_material(context, item, red, green, blue, d, sp):
    the_material_color = color(np.float32(red), np.float32(green),
                               np.float32(blue))
    new_material = material(material_color=the_material_color,
                            diffuse=float(d),
                            specular=float(sp))
    new_sphere = sphere(sphere_material=new_material)
    ensure_context_has_dict(context)
    context.dict[str(item)] = new_sphere
def __main__():
    floor = sphere(sphere_transform=scaling(10, 0.01, 10))
    floor.material = material()
    floor.material.color = color(1, 0.9, 0.9)
    floor.material.specular = 0

    left_wall = sphere()
    left_wall.set_transform(
        np.matmul(np.matmul(translation(0, 0, 5), rotation_y(-np.pi / 4)),
                  np.matmul(rotation_x(np.pi / 2), scaling(10, 0.01, 10))))

    left_wall.material = material()
    left_wall.material.color = color(0.3, 0.3, 0.9)
    left_wall.material.specular = 0

    right_wall = sphere()
    right_wall.set_transform(
        np.matmul(np.matmul(translation(0, 0, 5), rotation_y(np.pi / 4)),
                  np.matmul(rotation_x(np.pi / 2), scaling(10, 0.01, 10))))
    right_wall.material = floor.material

    middle = sphere(sphere_material=material(material_color=color(0.1, 1, 0.5),
                                             diffuse=0.7,
                                             specular=0.3),
                    sphere_transform=translation(-0.5, 1, 0.5))

    right = sphere(sphere_material=material(material_color=color(0.5, 1, 0.1),
                                            diffuse=0.7,
                                            specular=0.3),
                   sphere_transform=np.matmul(translation(1.5, 0.5, -0.5),
                                              scaling(0.5, 0.5, 0.5)))

    left = sphere(sphere_material=material(material_color=color(1, 0.8, 0.1),
                                           diffuse=0.7,
                                           specular=0.3),
                  sphere_transform=np.matmul(translation(-1.5, 0.33, -0.75),
                                             scaling(0.33, 0.33, 0.33)))

    light_source = point_light(point(-10, 10, -10), color(1, 1, 1))

    this_world = world()
    this_world.objects = [floor, left_wall, right_wall, middle, left, right]
    this_world.light = [light_source]

    this_camera = camera(100, 50, np.pi / 3)
    this_camera.set_transform(
        view_transform(point(0, 1.5, -5), point(0, 1, 0), vector(0, 1, 0)))

    c = render(this_camera, this_world)
    c.write_image("first_sphere_render_q.png")
def step_ray_element_has_value(context, x, y, red, green, blue):
    assert("image" in context.dict.keys())
    test_value = base.pixel_at(context.dict["image"], int(x), int(y))
    test_color = base.color(float(red), float(green), float(blue))
    assert(base.equal(test_value, test_color))
def step_lighting_color_test(context, item, red, green, blue):
    assert (item in context.tuple.keys())
    local_object_str = "context.tuple['" + str(item) + "']"
    local_object = eval(local_object_str)
    value = color(np.float32(red), np.float32(green), np.float32(blue))
    assert (equal(local_object, value))
def step_impl_color_assign(context, item, r, g, b):
    ensure_context_has_tuple(context)
    context.tuple[item] = color(float(r), float(g), float(b))
def step_set_background_color(context, item, r1, g1, b1, r2, g2, b2):
    assert (item in context.dict.keys())
    context.dict[str(item)].pattern = stripe_pattern(
        color(float(r1), float(g1), float(b1)),
        color(float(r2), float(g2), float(b2)))