Пример #1
0
    def test_render_scene(self):
        """Test we can render a pixel in a simple scene"""


        # Inner sphere size 0.5, centered on the origin
        s1 = shapes.Sphere()
        s1.set_transform(transforms.Scale(0.5,0.5,0.5))

        # Outer sphere centered on the origin, size 1.0
        s2 = shapes.Sphere()
        s2.material = materials.Material(
            color=colors.Color(0.8, 1.0, 0.6), diffuse=0.7, specular=0.2)

        l1 = lights.Light(
            position=points.Point(-10, 10, -10),
            intensity=colors.Color(1, 1, 1)
            )

        scene = scenes.Scene(
            objects = [s1, s2],
            lights = [l1]
        )

        cam = cameras.Camera(11, 11, math.pi/2)

        from_point = points.Point(0, 0, -5)
        to_point = points.Point(0, 0, 0)
        up = vectors.Vector(0, 1, 0)
        cam.transform = transforms.ViewTransform(from_point, to_point, up)

        image = cam.render(scene)
        self.assertEqual(image.get(5, 5),
                         colors.Color(0.3807, 0.4758, 0.2855))
Пример #2
0
    def test_shadows__full_scene(self):
        """Test that we identify a shadow in a full scene"""

        # First sphere is at z=10
        s1 = shapes.Sphere()
        s1.set_transform(transforms.Translate(0, 0, 10))

        # Second sphere is at the origin
        s2 = shapes.Sphere()
        s2.material = materials.Material()

        # Light is at z=-10
        l1 = lights.Light(position=points.Point(0, 0, -10),
                          intensity=colors.Color(1, 1, 1))

        scene = scenes.Scene(objects=[s1, s2], lights=[l1])

        # The ray is at z=5 (i.e. between the spheres), pointing at the further
        # out sphere
        ray = rays.Ray(points.Point(0, 0, 5), vectors.Vector(0, 0, 1))

        isection = intersections.Intersection(s2, 4)
        comps = isection.precompute(ray)

        result, _ = scene.shade_hit(comps)

        self.assertEqual(result, colors.Color(0.1, 0.1, 0.1))
Пример #3
0
    def main(self):
        self.clear_screen()
        print(self.logo)
        input("Press Enter so start the game ...")

        self.game_data.stack.append(self.game_data.current_loc.name, 2)
        self.game_data.stack.append(self.game_data.current_loc.get_desc())

        self.clear_screen()
        intro = scenes.Scene("intro", self.game_data.current_loc)
        intro.play()

        while True:
            print()
            self.game_data.stack.print_stack()
            cmd = input("> ")
            self.game_data.set_current_loc(com.parser(cmd, self.game_data))
Пример #4
0
    def setUp(self):
        """Set up a default scene for quick testing"""

        # Inner sphere size 0.5, centered on the origin
        self.s1 = shapes.Sphere()
        self.s1.set_transform(transforms.Scale(0.5, 0.5, 0.5))

        # Outer sphere centered on the origin, size 1.0
        self.s2 = shapes.Sphere()
        self.s2.material = materials.Material(color=colors.Color(
            0.8, 1.0, 0.6),
                                              diffuse=0.7,
                                              specular=0.2)

        self.l1 = lights.Light(position=points.Point(-10, 10, -10),
                               intensity=colors.Color(1, 1, 1))

        self.default_scene = scenes.Scene(objects=[self.s1, self.s2],
                                          lights=[self.l1])
Пример #5
0
    def test_reflection__infinite_recursion(self):
        """Test that we don't break if there is infinite recursion"""

        # Two parallel planes
        s1 = shapes.Plane(material=materials.Material(reflective=1))
        s1.set_transform(transforms.Translate(0, -1, 0))

        # Second sphere is at the origin
        s2 = shapes.Plane(material=materials.Material(reflective=1))
        s2.set_transform(transforms.Translate(0, 1, 0))

        # Light is at z=-10
        l1 = lights.Light(position=points.Point(0, 0, 0),
                          intensity=colors.Color(1, 1, 1))

        scene = scenes.Scene(objects=[s1, s2], lights=[l1])

        r = rays.Ray(points.Point(0, 0, 0), vectors.Vector(0, 1, 0))

        # If this is working the following will NOT cause a stack trace
        scene.color_at(r)
import scenes

# Create scene

scenery = scenes.Scene()

# Name of person playing the game
username = "******"
n = 1500
quit_flag = 0
score = 0
lives = 100
dragon_lives = 50
tic = 0
enemy_list = []
enemy_dir = []
magnet_list = []
speed = .5
shield = 0
num_shield = 0
activated_shield = 0
Пример #7
0
 def game_start(self,x):
     self.button_list = []
     self.menu = None
     self.scene = scenes.Scene(x)
     self.set_state(GAME_RUNNING)