Beispiel #1
0
from matrix import Matrix
from canvas import Canvas
from point import Point
from color import Color
from ray import Ray
from sphere import Sphere

if __name__ == '__main__':
    pixel_size = 100
    WIDTH = 100
    HEIGHT = 100
    c = Canvas(WIDTH, HEIGHT, Color(0.5, 0.5, 0.5))
    sphere = Sphere(Point(0, 0, 0), radius=1)
    sphere.set_transform(
        rotate_z(pi / 6) * scale(1, 0.5, 1) * shear(1, 0, 0, 0, 0, 0))
    camera = Point(0, 0, -5)
    wall_z = 10
    wall_size = 7
    canvas_pixels = 100
    pixel_size = wall_size / canvas_pixels
    half = wall_size / 2
    for j in range(HEIGHT):
        print(j)
        y = half - pixel_size * j
        for i in range(WIDTH):
            x = -half + pixel_size * i
            target = Point(x, y, wall_z)

            ray = Ray(camera, (target - camera).normalize())
            intersections = sphere.intersect(ray)
 def test_shear5(self):
     p = Point(2, 3, 4)
     s = shear(0, 0, 0, 0, 1, 0)
     self.assertTrue(Point(2, 3, 6).equals(s * p))
 def test_shear6(self):
     p = Point(2, 3, 4)
     s = shear(0, 0, 0, 0, 0, 1)
     self.assertTrue(Point(2, 3, 7).equals(s * p))
 def test_shear1(self):
     p = Point(2, 3, 4)
     s = shear(1, 0, 0, 0, 0, 0)
     self.assertTrue(Point(5, 3, 4).equals(s * p))