コード例 #1
0
ファイル: test_sphere.py プロジェクト: miliardt/ray-tracer
    def test_computing_normal_on_scaled_sphere(self):
        s = Sphere()
        s.set_transform(scaling(1, 0.5, 1))

        n = s.normal_at(point(0, math.sqrt(2) / 2, -math.sqrt(2) / 2))

        self.assert_tuple_equals(vector(0, 0.97014, -0.24254), n, 0.001)
コード例 #2
0
    def test_default_world(self):
        light = PointLight(point(-10, 10, -10), color(1, 1, 1))

        s1 = Sphere()
        s2 = Sphere()

        s1.material.color = color(0.8, 1.0, 0.6)
        s1.material.diffuse = 0.7
        s1.material.specular = 0.2

        s2.set_transform(scaling(0.5, 0.5, 0.5))

        world = default_world()

        self.assertEqual(light.position, world.light.position)
        self.assertEqual(light.intensity, world.light.intensity)

        self.assertEqual(s1.material.color, world.objects[0].material.color)
        self.assertEqual(s1.material.diffuse,
                         world.objects[0].material.diffuse)
        self.assertEqual(s1.material.specular,
                         world.objects[0].material.specular)

        self.assertEqual(s2.material.color, world.objects[1].material.color)
        self.assertEqual(s2.material.diffuse,
                         world.objects[1].material.diffuse)
        self.assertEqual(s2.material.specular,
                         world.objects[1].material.specular)
コード例 #3
0
ファイル: test_sphere.py プロジェクト: miliardt/ray-tracer
    def test_computing_normal_on_translated_sphere(self):
        s = Sphere()
        s.set_transform(translation(0, 1, 0))

        n = s.normal_at(point(0, 1.70711, -0.70711))

        self.assert_tuple_equals(vector(0, 0.70711, -0.70711), n, 0.001)
コード例 #4
0
ファイル: test_sphere.py プロジェクト: miliardt/ray-tracer
    def test_intersecting_translated_sphere_with_ray(self):
        r = Ray(point(0, 0, -5), vector(0, 0, 1))
        s = Sphere()

        s.set_transform(translation(5, 0, 0))
        xs = s.intersect(r)

        self.assertEqual(0, len(xs))
コード例 #5
0
ファイル: test_sphere.py プロジェクト: miliardt/ray-tracer
    def test_intersecting_scaled_sphere_with_ray(self):
        r = Ray(point(0, 0, -5), vector(0, 0, 1))
        s = Sphere()

        s.set_transform(scaling(2, 2, 2))
        xs = s.intersect(r)

        self.assertEqual(2, len(xs))
        self.assertEqual(3, xs[0].t)
        self.assertEqual(7, xs[1].t)
コード例 #6
0
def default_world():
    light = PointLight(point(-10, 10, -10), color(1, 1, 1))

    s1 = Sphere()
    s2 = Sphere()

    s1.material.color = color(0.8, 1.0, 0.6)
    s1.material.diffuse = 0.7
    s1.material.specular = 0.2

    s2.set_transform(scaling(0.5, 0.5, 0.5))

    return World(light=light, objects=[s1, s2])
コード例 #7
0
import time

from renderer.canvas import Canvas
from renderer.intersections import hit
from renderer.lights import PointLight
from renderer.rays import Ray
from renderer.sphere import Sphere
from renderer.transformations import scaling
from renderer.tuples import point, color

s = Sphere()
s.set_transform(scaling(0.5, 1, 1))
s.material.color = color(1, 0.2, 1)
light_position = point(-10, 10, -10)
light_color = color(1, 1, 1)
light = PointLight(light_position, light_color)
ray_origin = point(0, 0, -5)
wall_z = 10
wall_size = 7.0
canvas_pixels = 1000
pixel_size = wall_size / canvas_pixels
half = wall_size / 2

c = Canvas(canvas_pixels, canvas_pixels)
col = color(1, 0, 0)

start_time = time.time()
for y in range(canvas_pixels):
    elapsed_time = time.time() - start_time
    if elapsed_time > 0 and y > 0:
        print("time_to_finish: " + str(1.0 * (canvas_pixels - y) /
コード例 #8
0
ファイル: test_sphere.py プロジェクト: miliardt/ray-tracer
 def test_set_transform(self):
     s = Sphere()
     t = translation(2, 3, 4)
     s.set_transform(t)
     self.assertEqual(t, s.transform)