Пример #1
0
def _get_pattern_at_shape(self, colour, pattern, object, px, py, pz):
    pw = Point(float(px), float(py), float(pz))
    # Point is in world space, first transform to object space
    po = getattr(world, object).inverse_transform * pw
    # Pattern will handle the transform from object to pattern space
    c = getattr(world, pattern).pattern_at(po)
    setattr(world, colour, c)
Пример #2
0
def _ray_origin_equals_point(self, name, x, y, z):
    test_point = Point(float(x), float(y), float(z))
    print("\nExpected:")
    print(test_point)
    print("\nGot:")
    print(getattr(world, name).origin)
    assert getattr(world, name).origin == test_point
Пример #3
0
def _position_equals_point(self, name, t, px, py, pz):
    test_point = Point(float(px), float(py), float(pz))
    print("\nExpected:")
    print(test_point)
    print("\nGot:")
    print(getattr(world, name).position(float(t)))
    assert getattr(world, name).position(float(t)) == test_point
Пример #4
0
def _check_saved_ray_origin(self, name, px, py, pz):
    test_point = Point(float(px), float(py), float(pz))
    point = getattr(world, name).saved_ray.origin
    print("\nExpected:")
    print(test_point)
    print("\nGot:")
    print(point)
    assert point == test_point
Пример #5
0
def _compare_point_by_value(self, name, x, y, z):
    test_value = Point(float(x), float(y), float(z))
    value = getattr(world, name).point
    print("\nExpected:")
    print(test_value)
    print("\nGot:")
    print(value)
    assert value == test_value
Пример #6
0
def __mupltiply_matrix_point(self, name1, name2, x, y, z):
    test_point = Point(float(x), float(y), float(z))
    print("\nTransformation matrix is:")
    print(getattr(world, name1))
    print("\nExpected:")
    print(test_point)
    print("\nGot:")
    print(getattr(world, name1) * getattr(world, name2))
    assert getattr(world, name1) * getattr(world, name2) == test_point
Пример #7
0
def _check_pattern_by_colour(self, pattern, px, py, pz, r, g, b):
    pat = getattr(world, pattern)
    pos = Point(float(px), float(py), float(pz))
    tc = Colour(float(r), float(g), float(b))
    c = pat.pattern(pos)
    print("\nExpected:")
    print(tc)
    print("\nGot:")
    print(c)
    assert c == tc
Пример #8
0
def _check_pattern_by_name(self, pattern, px, py, pz, col):
    pat = getattr(world, pattern)
    pos = Point(float(px), float(py), float(pz))
    tc = getattr(world, col)
    c = pat.pattern(pos)
    print("\nExpected:")
    print(tc)
    print("\nGot:")
    print(c)
    assert c == tc
Пример #9
0
def _check_stripe_at(self, name, px, py, pz, colour):
    p = Point(float(px), float(py), float(pz))
    c = getattr(world, colour)
    pat = getattr(world, name)
    col = pat.pattern_at(p)
    print("\nExpected:")
    print(c)
    print("\nGot:")
    print(col)
    assert col == c
Пример #10
0
 def pattern(self, point):
     # Incoming point has already been transformed into pattern space
     # by the parent Pattern class
     # Shift x, y and z by an amount of noise before passing to the
     # inner pattern.
     x = point.x
     y = point.y
     z = point.z
     dx = self.noise.eval2d(y, z) * self.size
     dy = self.noise.eval2d(x, z) * self.size
     dz = self.noise.eval2d(x, y) * self.size
     pp = Point(x + dx, y + dy, z + dz)
     # Return the simple average of colour returned by the two inner
     # patterns
     return self.a.pattern_at(pp)
Пример #11
0
def _local_normal_at(self, name1, name2, px, py, pz):
    p = Point(float(px), float(py), float(pz))
    o = getattr(world, name2)
    setattr(world, name1, o.local_normal_at(p))
Пример #12
0
#!/usr/bin/env python
from Tuple4 import Point, Colour
import Canvas
import math


def plot(canvas, point, colour):
    x = int((canvas.width / 2) + round(point.x))
    y = int((canvas.height / 2) - round(point.y))
    c.write_pixel(x, y, colour)


def plot_cross(canvas, point, colour):
    x = int((canvas.width / 2) + round(point.x))
    y = int((canvas.height / 2) - round(point.y))
    c.write_pixel(x, y, colour)
    c.write_pixel(x + 1, y, colour)
    c.write_pixel(x - 1, y, colour)
    c.write_pixel(x, y + 1, colour)
    c.write_pixel(x, y - 1, colour)


white = Colour(0.8, 0.8, 0.8)
c = Canvas.Canvas(600, 600)
p = Point(0, 250, 0)

for r in range(0, 12):
    p2 = p.rotate_z(-r * math.pi / 6)
    plot_cross(c, p2, white)
c.to_ppm_file("clock.ppm")
Пример #13
0
def _normal_at_point(self, name1, name2, x, y, z):
    p = Point(float(x), float(y), float(z))
    n = getattr(world, name2).normal_at(p)
    setattr(world, name1, n)
Пример #14
0
def _point_light_by_number(self, name, x, y, z, r, g, b):
    setattr(
        world, name,
        PointLight(Point(float(x), float(y), float(z)),
                   Colour(float(r), float(g), float(b))))
Пример #15
0
def _ray_from_values(self, name, px, py, pz, vx, vy, vz):
    setattr(
        world, name,
        Ray(Point(float(px), float(py), float(pz)),
            Vector(float(vx), float(vy), float(vz))))