예제 #1
0
파일: clock.py 프로젝트: BrianTheArcane/RTC
def run() -> None:
    STEPS = 180
    SIZE = 600
    MIDDLE = SIZE // 2

    canvas = Canvas(SIZE, SIZE)
    color = Color(1, 0, 0)
    color_increment = Color(0, 0, 1.0 / STEPS)

    position = point(0, 1, 0)

    rotate = rotation_z(-2 * math.pi / STEPS)
    translate = translation(MIDDLE, MIDDLE, 0)
    scale = scaling(SIZE // 3, SIZE // 3, 1)

    for i in range(STEPS):
        canvas_position = translate * scale * position
        assert isinstance(canvas_position, Point)
        canvas.write_pixel(
            int(round(canvas_position.x)),
            SIZE - int(round(canvas_position.y)),
            color,
        )
        position = rotate * position
        color += color_increment

    ppm = PPM(canvas)

    file_name = "clocks.ppm"
    ppm.save_to_file(file_name)
    print(f"Output stored to {file_name}")
예제 #2
0
파일: scene.py 프로젝트: BrianTheArcane/RTC
def run() -> None:
    room = create_room()
    objects = create_objects()
    world = World()
    world.light = PointLight(point(-10, 10, -10), Color(1, 1, 1))
    world.objects.extend(room)
    world.objects.extend(objects)
    camera = Camera(400, 200, math.pi / 3)
    camera.transform = view_transform(point(0, 1.5, -5), point(0, 1, 0),
                                      vector(0, 1, 0))
    canvas = camera.render(world)
    PPM(canvas).save_to_file("scene.ppm")
예제 #3
0
def run() -> None:
    # Eye is at (0,0, 5)
    origin = point(0, 0, 5)

    shape = Sphere()
    # shape.set_transform(scaling(0.5, 1, 1))
    shape.material.color = Color(0.9, 0.2, 1)

    light = PointLight(point(-10, 10, 10), Color(1, 1, 1))
    canvas = Canvas(CANVAS_SIZE, CANVAS_SIZE)

    for i in range(CANVAS_SIZE):
        for j in range(CANVAS_SIZE):
            target = canvas_to_world(point(i, j, 0))
            ray = Ray(origin, normalize(target - origin))
            hit = find_hit(shape.intersect(ray))
            if hit is not None:
                hit_point = position(ray, hit.t)
                normal = hit.shape.normal_at(hit_point)
                pixel_color = lighting(hit.shape.material, light, hit_point,
                                       -ray.direction, normal)
                canvas.write_pixel(i, j, pixel_color)

    PPM(canvas).save_to_file("sphere.ppm")
예제 #4
0
            # Compare this with the hard-coded reflection in 6_matterial.
            return scattering.attenuation * color(scattering.scattering, world,
                                                  depth + 1)
        else:
            return Vec3(0, 0, 0)
    else:
        unit_direction: Vec3 = ray.direction.unit_vector()
        t: float = 0.5 * (unit_direction.y + 1)
        return ((1.0 - t) * UNIT_VEC3) + (t * Vec3(0.5, 0.7, 1.0))


if __name__ == "__main__":
    width: int = 1200
    height: int = 800
    sampling_size: int = 10
    ppm: PPM = PPM(width, height)
    spam: List[Hittable] = random_scene(-11, 11, -11, 11)
    world = HittableList(spam)
    print(spam)

    lookfrom: Vec3 = Vec3(9, -2, -1)
    lookat: Vec3 = Vec3(-4, 1, 0)
    focus_distance: float = 10.0
    aperture: float = 0.1

    camera: Camera = PositionableCamera(lookfrom, lookat, Vec3(0, 1, 0), 20,
                                        width / height, aperture,
                                        focus_distance)

    for j in range(height - 1, -1, -1):
        for i in range(width):
예제 #5
0
from src.ppm import PPM
from src.utils import _derive_ppm_filename
from src.vec3 import Vec3

if __name__ == "__main__":
    hello_world = PPM(300, 200)
    for ri in range(hello_world.height):
        for ci in range(hello_world.width):
            v = Vec3(ri / hello_world.width, ci / hello_world.height, 0.2)
            color = v * 255.99
            color.map(int)
            hello_world.set_pixel(ri, ci, color)
    hello_world.write(_derive_ppm_filename())
예제 #6
0
def assign_ppm(context, ppm_var, canvas_var):
    canvas = context.variables[canvas_var]
    ppm = PPM(canvas)
    context.variables[ppm_var] = ppm.to_string()