Beispiel #1
0
def drawGame(shooting, dt):
    #draws background
    screen.fill(COLOR_BG)
    #draws all the spheres
    Sphere.drawAll()
    #draws crosshair
    drawCrossHair(shooting)
    #draws player score
    screen.blit(
        FONT.render(
            'Score: ' + str(player.score) + " (Highest: " +
            str(player.highScore) + ")", False, COLOR_TEXT), (10, 0))
    if (player.mode == "timed"):
        #updates timer
        player.timePassed += dt
        #draws time left text
        screen.blit(
            FONT.render(
                'Time left: ' + str(TIME_LIMIT - player.timePassed // 1000) +
                "s", False, COLOR_TEXT), (10, 50))
        #game mechanics: if time goes beyond time limit sets screen to gameover
        if (TIME_LIMIT - player.timePassed // 1000 < 0):
            player.screenType = ScreenType.GAMEOVER
            SOUND_GAMEOVER.play()
    elif (player.mode == "hardcore"):
        #draws # of spheres text
        screen.blit(
            FONT.render(
                '# of Spheres: ' + str(len(Sphere.getSpheres())) +
                " (Max: 35)", False, COLOR_TEXT), (10, 50))
        #game mechanics: if spheres goes beyond limit set screen to gaveover
        if (len(Sphere.getSpheres()) > SPHERES_LIMIT):
            player.screenType = ScreenType.GAMEOVER
            SOUND_GAMEOVER.play()
Beispiel #2
0
def main():
    randy = Renderer()

    polyCube = Cube()
    polyCube.build_polygon_mesh()
    randy.render(polyCube.mesh, 512, "polyCube.jpg")

    triangleCube = Cube()
    triangleCube.build_triangle_mesh(4000)
    randy.render(triangleCube.mesh, 1080, "HDcube.jpg")

    polyCylinder = Cylinder()
    polyCylinder.build_polygon_mesh()
    randy.render(polyCylinder.mesh, 512, "polyCylinder.jpg")

    triangleCylinder = Cylinder()
    triangleCylinder.build_triangle_mesh(4000)
    randy.render(triangleCylinder.mesh, 1080, "HDcylinder.jpg")

    polySphere = Sphere()
    polySphere.build_polygon_mesh()
    randy.render(polySphere.mesh, 512, "polySphere")

    triangleSphere = Sphere()
    triangleSphere.build_triangle_mesh(4000)
    randy.render(triangleSphere.mesh, 1080, "HDSphere")
Beispiel #3
0
def create_spheres(physics, n_spheres, radius, max_vel, cube_length):#cria esferas com posições e velocidades aleatórias, sem que coincidam
    list_spheres = []

    for i in range(n_spheres):
        #gera as coordenadas e velocidades aleatórias
        pos = sample(list(arange(-(cube_length - radius), (cube_length - radius), 0.1)), 3)
        vel = sample(list(arange(-5, 5, 0.1)), 3)
        list_spheres.append(Sphere(radius, Vector(pos[0], pos[1], pos[2]), Vector(vel[0], vel[1], vel[2])))

    #evita bolas surgirem num mesmo lugar
    for i in range(n_spheres):
        for j in range(i + 1, n_spheres):
            direcX = list_spheres[i].position[0] - list_spheres[j].position[0]
            direcY = list_spheres[i].position[1] - list_spheres[j].position[1]
            direcZ = list_spheres[i].position[2] - list_spheres[j].position[2]

            distance_squared = direcX ** 2 + direcY ** 2 + direcZ ** 2

            if distance_squared <= (radius ** 2) * 4:
                #gera as coordenadas aleatórias novamente
                pos = sample(list(arange(-(cube_length - radius), (cube_length - radius), 0.1)), 3)
                list_spheres[i].position = Vector(pos[0], pos[1], pos[2])

                #reinicia a verificação
                i = 0
                j = 1

    for i in range(n_spheres):
        physics.add_ball(list_spheres[i])

    return list_spheres
Beispiel #4
0
def DefaultWorld():
    w = World()
    w.lights.append(
        Light.PointLight(Tuple4.Point(-10, 10, -10), Tuple4.Colour(1, 1, 1)))

    s1 = Sphere.Sphere()
    s1.material.colour = Tuple4.Colour(0.8, 1.0, 0.6)
    s1.material.diffuse = 0.7
    s1.material.specular = 0.2
    w.objects.append(s1)

    s2 = Sphere.Sphere()
    s2.transform = Transformation.Scaling(0.5, 0.5, 0.5)
    w.objects.append(s2)

    return w
Beispiel #5
0
def drawCrossHair(shooting):
    #to make the code easier to read, I've created center_x and y variables
    center_x = SIZE[0] / 2
    center_y = SIZE[0] / 2
    #sets image variable to crosshair image
    image = crosshair
    #fetches data from sphere to see if center of screen/crosshair is in a sphere
    insideData = Sphere.isInAnySphere(center_x, center_y)
    #sets default cross hair color to green
    color = GREEN
    #if crosshair is inside a sphere: successful target
    if (insideData[0]):
        #sets image to targeted crosshair
        image = tcrosshair
        #sets color to red
        color = RED
        #if player is shooting/press spacebbar
        if (shooting):
            #deletes the sphere from array
            insideData[1].delete()
            #increment player score
            player.score += 1
            #play successful point sound
            SOUND_POINT.play()
            #updates highscore & writes it to file
            if (player.highScore < player.score):
                player.highScore = player.score
                player.saveHighScore()

    #draws the crosshair: self-explanatory
    pygame.draw.line(screen, color, [center_x - 30, center_y - 3],
                     [center_x + 30, center_y - 3], 3)
    pygame.draw.line(screen, color, [center_x - 3, center_y - 30],
                     [center_x - 3, center_y + 30], 3)
    screen.blit(image, (SIZE[0] / 2 - 160, SIZE[0] / 2 - 120))
Beispiel #6
0
    def Sphere_Clicked(self):

        self.SphereRunning(True)
        self.top.ActiveWizard = Sphere.Sphere(self, self.queue, self.Vars.BindingSite.Sphere, self.SphereDisplay, self.SphereSize, '')
        cmd.set_wizard(self.top.ActiveWizard)
        cmd.refresh()

        self.top.ActiveWizard.Start()
    def set_outer_sphere(self, center_coordinate):
        self_id = None
        radius = 500
        neighbor_ids = []
        gl_flag = False

        outer_id = len(self.sphere_outer_lists) + 1
        outer_sphere = Sphere.Sphere(self_id, gl_flag, center_coordinate, radius, neighbor_ids, outer_id)
        self.sphere_outer_lists.append(outer_sphere)
Beispiel #8
0
def test():
    # set up tests
    cubeFactory = Cube()
    sphereFactory = Sphere()
    cylinderFactory = Cylinder()

    cube = cubeFactory.build_triangle_mesh(256)
    sphere = sphereFactory.build_triangle_mesh(256)
    cylinder = cylinderFactory.build_triangle_mesh(256)

    # do tests
    print("#### CUBE ####")
    cube.test_integrity()
    print("\n")

    print("#### CYLINDER ####")
    cylinder.test_integrity()
    print("\n")

    print("#### SPHERE ####")
    sphere.test_integrity()
    print("\n")
Beispiel #9
0
    def Step2_Add(self):

        if self.top.ActiveWizard is None:
                
            self.SphereID = self.Get_SphereID()
            
            self.Sphere = SphereObj.SphereObj(self.Width/1.5, self.Width, self.Center)
            
            self.SphereRunning(True)
            
            self.top.ActiveWizard = Sphere.Sphere(self, self.queue, self.Sphere, self.SphereID, self.SphereSize,
                                                  "The grayed volume of the cleft is the volume that will be conserved.")
            cmd.set_wizard(self.top.ActiveWizard)
            cmd.refresh()
            
            self.top.ActiveWizard.Start()

        else:
            self.top.DisplayMessage("Could not execute task: A Wizard is active")
Beispiel #10
0
def ConstructBoundingSphere(v, tri):
    M = tri.shape[0]
    sphere = [Sphere() for _ in range(M)]
    Center = np.zeros((M, 3))
    Radius = np.zeros((M, 1))
    Object = np.zeros((3, 3, M))
    for i in range(M):
        p = v[tri[i][0]]
        q = v[tri[i][1]]
        r = v[tri[i][2]]
        pq = np.linalg.norm(p - q)
        pr = np.linalg.norm(p - r)
        qr = np.linalg.norm(q - r)
        ind = np.argmax([pq, pr, qr])
        if ind == 0:
            a = p
            b = q
            c = r
        elif ind == 1:
            a = p
            b = r
            c = q
        else:
            a = q
            b = r
            c = p
        f = (a + b) / 2
        u = a - f
        vv = c - f
        d = np.cross(np.cross(u, vv), u)
        gamma = (np.matmul(vv, vv) - np.matmul(u, u)) / \
            np.matmul((2 * d), (vv - u))
        if gamma <= 0:
            lamb = 0
        else:
            lamb = gamma
        Center[i] = f + lamb * d
        Radius[i] = np.linalg.norm(Center[i] - a)
        Object[:, :, i] = np.array([p, q, r])
        sphere[i].Center = Center[i]
        sphere[i].Radius = Radius[i]
        sphere[i].Object = Object[:, :, i]
    return sphere
Beispiel #11
0
    def Step2_Edit(self):

        if self.top.ActiveWizard is None and self.Sphere is not None:
            
            if not self.dictSpheres.get(self.Step2Selection.get()):
                return
            
            self.SphereID = self.Step2Selection.get()

            self.SphereRunning(True)
            
            self.top.ActiveWizard = Sphere.Sphere(self, self.queue, self.Sphere, self.Step2Selection.get(), self.SphereSize,
                                                  "The grayed volume of the cleft is the volume that will be conserved.")
            cmd.set_wizard(self.top.ActiveWizard)
            cmd.refresh()
            
            self.top.ActiveWizard.Start()

        else:
            self.top.DisplayMessage("Could not execute task: A Wizard is active")
Beispiel #12
0
def initGame():
    #resets player score, position, aim, and rotations
    player.score = 0
    player.x = 0
    player.y = 0
    player.z = 0
    player.yaw = 0
    player.pitch = 0
    player.roll = 0
    player.fromScreenD = 3.5
    #resets timer
    if (player.mode == "timed"):
        player.timePassed = 0
    #resets spheres array
    Sphere.spheres = []
    #Generate 30 spheres in the beginning of the game
    for i in range(0, INITIAL_SPHERES):
        Sphere.Sphere(
            [randint(-MAX, MAX),
             randint(-MAX, MAX),
             randint(-MAX, MAX)])
Beispiel #13
0
def main():
    cubeFactory = Cube()
    cube = cubeFactory.build_triangle_mesh(2000)
    cube.add_transformation(TransformationFactory.scale(2.0, 2.0, 2.0))
    cube.add_transformation(TransformationFactory.z_rotation(45))
    cube.add_transformation(TransformationFactory.x_rotation(45))

    cylinderFactory = Cylinder()
    cylndr = cylinderFactory.build_triangle_mesh(1350)
    cylndr.add_transformation(TransformationFactory.scale(4.0, 4.0, 4.0))
    cylndr.add_transformation(TransformationFactory.x_rotation(30))
    cylndr.add_transformation(TransformationFactory.z_rotation(-25))

    sphereFactory = Sphere()
    sphere = sphereFactory.build_triangle_mesh(4000)
    sphere.add_transformation(TransformationFactory.scale(2.0, 2.0, 5.0))
    sphere.add_transformation(TransformationFactory.y_rotation(35))

    scene0 = Scene()
    scene0.add_mesh(cylndr, (0.0, 0.0, -3.0))
    scene0.add_mesh(cube, (-2.0, 0.0, 1.0))
    scene0.add_mesh(sphere, (5.0, 5.0, 1.0))

    # cubeFactory.build_triangle_mesh(300)
    # floor_mesh = cubeFactory.mesh
    # floor_mesh.add_transformation(TransformationFactory.scale(10.0, 10.0, 0.5))

    # myScene.add_mesh(floor_mesh, (0.0, 0.0, -1.0))

    camera = ViewSystem(scene0)
    camera.build_camera(0.0, 20.0, 150.0)
    camera.build_view_volume(23.0, 200.0, 5.0)
    # camera.render_scene(1080, "renders/scene0")
    camera.scene.reset()

    sphere1 = sphereFactory.build_triangle_mesh(4000)
    sphere1.add_transformation(TransformationFactory.scale(2.0, 2.0, 5.0))
    sphere1.add_transformation(TransformationFactory.y_rotation(35))

    camera.scene.add_mesh(sphere1, (0.0, 0.0, 0.0))
    camera.build_camera(90.0, 0.0, 40.0)
    camera.build_view_volume(20.0, 500.0, 10.0)
    #camera.render_scene(2160, "renders/scene1")

    basicAssCube = cubeFactory.build_triangle_mesh(128)
    basicAssCube.add_transformation(TransformationFactory.y_rotation(30))
    basicAssCube.add_transformation(TransformationFactory.x_rotation(30))
    basicAssCube.add_transformation(TransformationFactory.z_rotation(30))

    camera.scene.reset()
    camera.build_camera(0.0, 0.0, 10)
    camera.build_view_volume(3.0, 25.0, 2.0)
    camera.scene.add_mesh(basicAssCube, (0.0, 0.0, 0.0))
    # camera.render_scene(900, "renders/cube")

    basicAssCylndr = cylinderFactory.build_triangle_mesh(4000)
    basicAssCylndr.add_transformation(TransformationFactory.y_rotation(30))
    basicAssCylndr.add_transformation(TransformationFactory.x_rotation(30))
    basicAssCylndr.add_transformation(TransformationFactory.z_rotation(30))
    basicAssCylndr.add_transformation(
        TransformationFactory.scale(4.0, 4.0, 4.0))

    camera.scene.reset()
    camera.build_camera(25.0, 25.0, 8.0)
    camera.build_view_volume(3.0, 25.0, 2.0)
    camera.scene.add_mesh(basicAssCylndr, (0.0, 0.0, 0.0))
    camera.render_scene(2000, "renders/cylinder")

    basicAssSphere = sphereFactory.build_polygon_mesh()
    basicAssSphere.add_transformation(TransformationFactory.y_rotation(30))
    basicAssSphere.add_transformation(TransformationFactory.x_rotation(30))
    basicAssSphere.add_transformation(TransformationFactory.z_rotation(30))

    camera.scene.reset()
    camera.build_camera(20.0, 50.0, 10.0)
    camera.build_view_volume(3.0, 25.0, 2.0)
    camera.scene.add_mesh(basicAssSphere, (0.0, 0.0, 0.0))
    camera.render_scene(900, "renders/sphere")
Beispiel #14
0
    def create_spatial_domain_by_sphere(self):
        """自空間の領域を構成する球体の母点を生成、周辺に外部空間(外部とのつながり)の母点を生成"""
        global coordinate

        # 自空間がGLに設置するか否かを判定
        gl_flag = False
        gl_value = rs.GetInteger('Input 1(from GL) or 2(not from GL)')

        if gl_value == 1:
            gl_flag = True
        elif gl_value == 2:
            pass
        else:
            raise Exception('not intended num selected, please retry')

        # 自空間の隣接関係(球体の数)を決定 --> 意味ある?
        neighbor_num = rs.GetInteger(
            'Input the numbers of neighbor sphere')  # 近接数(球体)
        neighbor_ids = []
        for _ in range(neighbor_num):
            neighbor_id = rs.GetInteger(
                'Input the neighbor sphere ID(int)')  # IDを割り当て?
            neighbor_ids.append(neighbor_id)

        # 自空間の大まかな領域を構成する球体の半径を決定
        radius = rs.GetInteger(
            'Enter the radius of sphere to create space')  # sphere of radius

        # ユーザによる空間領域の位置を母点(球体)の取得によって決定 --> 重要
        sphere_center_coordinate = rs.GetPointCoordinates(
        )  # TODO ゆくゆくは自動生成にしたい
        coordinate = sphere_center_coordinate[0]  # [int, int ,int]の値を取得。あとで改善

        # 自身のID番号
        self_id = 111

        # 空間領域を決定するための球体を生成(インスタンス)
        self.spatial_domain_sphere = Sphere.Sphere(self_id, gl_flag,
                                                   sphere_center_coordinate[0],
                                                   radius, neighbor_ids, None)

        # 他の空間領域との相互関係を決定するための外部球体を生成
        temp_coordinate_list = []
        coordinate_1 = Rhino.Geometry.Point3d(coordinate[0] + 90,
                                              coordinate[1] + 20,
                                              coordinate[2])
        coordinate_2 = Rhino.Geometry.Point3d(coordinate[0] - 100,
                                              coordinate[1] - 5, coordinate[2])
        coordinate_3 = Rhino.Geometry.Point3d(coordinate[0] + 1,
                                              coordinate[1] + 90,
                                              coordinate[2])
        coordinate_4 = Rhino.Geometry.Point3d(coordinate[0] - 1,
                                              coordinate[1] - 100,
                                              coordinate[2])
        coordinate_5 = Rhino.Geometry.Point3d(coordinate[0] - 2,
                                              coordinate[1] - 1,
                                              coordinate[2] + 100)
        coordinate_6 = Rhino.Geometry.Point3d(coordinate[0] + 3,
                                              coordinate[1] + 10,
                                              coordinate[2] - 100)
        coordinate_7 = Rhino.Geometry.Point3d(coordinate[0] + 50,
                                              coordinate[1] + 10,
                                              coordinate[2] + 50)
        temp_coordinate_list.append(coordinate_1)
        temp_coordinate_list.append(coordinate_2)
        temp_coordinate_list.append(coordinate_3)
        temp_coordinate_list.append(coordinate_4)
        temp_coordinate_list.append(coordinate_5)
        temp_coordinate_list.append(coordinate_6)
        temp_coordinate_list.append(coordinate_7)

        for i in range(7):
            outer_id = i
            radius = 500
            neighbor_ids = []
            gl_flag = False

            outer_sphere = Sphere.Sphere(self_id, gl_flag,
                                         temp_coordinate_list[i], radius,
                                         neighbor_ids, outer_id)
            self.sphere_outer_lists.append(outer_sphere)

        # 不必要なオブジェクトを削除
        del temp_coordinate_list
Beispiel #15
0
def misorientationStats(misorient, *wts):
    '''
    MisorientationStats - Misorientation correlation statistics.

      USAGE:

      stats = MisorientationStats(misorient, locations)
      stats = MisorientationStats(misorient, locations, wts)

      INPUT:

      misorient is 4 x n, 
                a list of misorientation quaternions,
                assumed to have been derived from properly clustered 
                orientation data
      wts       is 1 x n, (optional)
                a list of weights; if not specified, uniform weights are used

      OUTPUT:

      stats is a structure with five components:

            W     is a 3 x 3 matrix (A in Barton paper)
            Winv  is a 3 x 3 matrix (A^-1 in Barton paper)
            wi    is 3 x n, the unnormalized axial vectors

      REFERENCE:  

      "A Methodology for Determining Average Lattice Orientation and 
      Its Application to the  Characterization of Grain Substructure",

      Nathan R. Barton and Paul R. Dawson,

      Metallurgical and Materials Transactions A,
      Volume 32A, August 2001, pp. 1967--1975
  

    '''
    misorient = utl.mat2d_row_order(misorient)
    d, n = misorient.shape
    if len(wts) == 0:
        wts = np.tile(1.0 / n, (3, n))
    else:
        wts = np.tile(wts, (3, 1))

    wts1 = np.tile(wts[0, :], (4, 1))
    misOriCen = sph.SphereAverage(misorient, **{'wts': wts1})
    misorient = misorient - np.tile(misOriCen, (1, n))

    ang = utl.mat2d_row_order(2 * np.arccos(misorient[0, :]))
    wsc = np.zeros(ang.shape)

    limit = (ang < np.finfo(float).eps)
    nlimit = (ang > np.finfo(float).eps)

    angn = ang[nlimit]

    wsc[nlimit] = angn / np.sin(angn / 2)
    wsc[limit] = 2

    wi = misorient[1:4, :] * np.tile(wsc.T, (3, 1))

    angax = np.zeros((4, n))
    angax[0, :] = np.linalg.norm(wi, axis=0)
    angax[1:4, :] = normalize(wi, axis=0)

    Winv = np.sum(utl.RankOneMatrix(wi * wts, wi), axis=2)

    #We needed to scale this up if it was close to being ill-conditioned
    if (np.abs(np.linalg.det(Winv)) < 1e-6):
        if (np.abs(np.linalg.det(Winv)) < 1e-16):
            W = np.zeros((3, 3))
        else:
            Wtemp = np.multiply(1e9, Winv)
            W = np.multiply(1e9, np.linalg.inv(Wtemp))
    else:
        W = np.linalg.inv(Winv)

    stat = {'W': W, 'Winv': Winv, 'wi': wi, 'angaxis': angax}

    return stat
Beispiel #16
0
def bartonStats(misorient, locations, *wts):
    '''
    MisorientationStats - Misorientation correlation statistics.

      USAGE:

      stats = MisorientationStats(misorient, locations)
      stats = MisorientationStats(misorient, locations, wts)

      INPUT:

      misorient is 4 x n, 
                a list of misorientation quaternions,
                assumed to have been derived from properly clustered 
                orientation data
      locations is d x n, (d <= 3) 
                a list of spatial locations corresponding to the 
                misorientations
      wts       is 1 x n, (optional)
                a list of weights; if not specified, uniform weights are used

      OUTPUT:

      stats is a structure with five components:

            W     is a 3 x 3 matrix (A in Barton paper)
            X     is a d x d matrix (M in Barton paper)
            WX    is a 3 x d matrix (cross-correlation
                       of normalized variables; X in
                       Barton paper)
            wi    is 3 x n, the unnormalized axial vectors
            xi    is d x n, the unnormalized spatial directions
                            from the centroid

      REFERENCE:  

      "A Methodology for Determining Average Lattice Orientation and 
      Its Application to the  Characterization of Grain Substructure",

      Nathan R. Barton and Paul R. Dawson,

      Metallurgical and Materials Transactions A,
      Volume 32A, August 2001, pp. 1967--1975
  

    '''
    locations = utl.mat2d_row_order(locations)
    misorient = utl.mat2d_row_order(misorient)
    d, n = misorient.shape
    if len(wts) == 0:
        wts = np.tile(1.0 / n, (3, n))
    else:
        wts = np.tile(wts, (3, 1))

    wts1 = np.tile(wts[0, :], (4, 1))
    misOriCen = sph.SphereAverage(misorient, **{'wts': wts1})
    misorient = misorient - np.tile(misOriCen, (1, n))

    ang = utl.mat2d_row_order(2 * np.arccos(misorient[0, :]))
    wsc = np.zeros(ang.shape)

    limit = (ang < np.finfo(float).eps)
    nlimit = (ang > np.finfo(float).eps)

    angn = ang[nlimit]

    wsc[nlimit] = angn / np.sin(angn / 2)
    wsc[limit] = 2

    wi = misorient[1:4, :] * np.tile(wsc.T, (3, 1))

    wi = wi * np.tile(ang.T, (3, 1))

    cen = utl.mat2d_row_order(np.sum(locations * wts, axis=1))

    xi = locations - np.tile(cen, (1, n))

    Winv = np.sum(utl.RankOneMatrix(wi * wts, wi), axis=2)
    Xinv = np.sum(utl.RankOneMatrix(xi * wts, xi), axis=2)
    #We needed to scale this up if it was close to being ill-conditioned
    if (np.abs(np.linalg.det(Winv)) < 1e-6):
        if (np.abs(np.linalg.det(Winv)) < 1e-16):
            W = np.zeros((3, 3))
        else:
            Wtemp = np.multiply(1e9, Winv)
            W = np.multiply(1e9, np.linalg.inv(Wtemp))
    else:
        W = np.linalg.inv(Winv)
    Whalf = sci.linalg.sqrtm(W)

    if (np.abs(np.linalg.det(Xinv)) < 1e-6):
        Xtemp = np.multiply(1e9, Xinv)
        X = np.multiply(1e9, np.linalg.inv(Xtemp))
    else:
        X = np.linalg.inv(Xinv)
    Xhalf = sci.linalg.sqrtm(X)

    wibar = np.dot(Whalf, wi)
    xibar = np.dot(Xhalf, xi)

    WX = np.sum(utl.RankOneMatrix(wibar * wts, xibar), axis=2)

    stat = {
        'W': W,
        'Winv': Winv,
        'Xinv': Xinv,
        'X': X,
        'WX': WX,
        'wi': wi,
        'xi': xi
    }

    return stat
Beispiel #17
0
import Pyramid, Sphere, Box

m1 = input(
    "If you would like to test for a rectangular prism, enter B.  If you would like to test for a rectangular pyramid, enter P.  If you would like to test for an ellipsoid, enter S."
)
#m1 = upper(m1)

l = float(input("Enter the length of your object:"))
w = float(input("Enter the width of your object:"))
h = float(input("Enter the height of your object:"))

if m1 == "B":
    myShape = Box.Box(l, w, h)
elif m1 == "P":
    myShape = Pyramid.Pyramid(l, w, h)
elif m1 == "S":
    myShape = Sphere.Sphere(l, w, h)
else:
    print("Invalid mode.")
print("Volume: ", str(myShape.getVolume()))
print("Surface area: ", str(myShape.getSurfaceArea()))
Beispiel #18
0
import StdOut_StdErr
import Stage
import Sphere
import Camera
import Comm_Status
import Analysis
import Lakeshore_335
import BK_Precision_9184
import DewarFill

#************** START OF MAIN PROGRAM ****************** 
master = Tk() # Main GUI Window
master.title("Simulator Control UI")
stage = Stage.Stage(master)
lakeshore = Lakeshore_335.Lakeshore(master)
sphere = Sphere.Sphere(master)
bk = BK_Precision_9184.BK_Precision_9184(master)
camera = Camera.Camera(master,stage, sphere, lakeshore, bk)
dewarfill = DewarFill.DewarFill(master)
comm_status = Comm_Status.Comm_Status(master,stage, sphere, camera, lakeshore, bk, dewarfill)
analysis = Analysis.Analysis(master,camera)
stdout_stderr = StdOut_StdErr.StdOut_StdErr(master)

stage.Define_Frame()
sphere.Define_Frame()
camera.Define_Frame()
dewarfill.Define_Frame()
analysis.Define_Frame()
stdout_stderr.Define_Frame()
comm_status.Define_Frame()
master.mainloop() 
Beispiel #19
0
    #if len(sys.argv) < 2:
     #   print 'Sorry you need to enter more arguments!\n The format is: Python raytrace [# of sp'
    
    numSphere = int(sys.argv[1])
    depth = int(sys.argv[2])
    
    #lay the frame work for my image file
    image = Image(500,400,'raytrace.ppm')

    #initialize the world
    world = World(depth)

    #create all spheres with a random color
    for offset in range(numSphere):
        sphere = Sphere(Point(-6 + (offset* 4), 3.4+ (offset%2), -5+(offset * 5)), 2)
        sphereColor = (
            1/float(random.randrange(1,5+1)),
            1/float(random.randrange(1,5+1)),
            1/float(random.randrange(1,5+1))
            )
        mat = Material(sphereColor)
        world.add(sphere, mat)

    #add plane
    world.add(Plane(), Material((0.1,0.3,0.4)))

    #print welcome message
    startingIntro(numSphere,depth, image.height, image.width, image.name, world.lightPoint)
    
    gaze = reverseRay(world.position, world.eyeDirection - world.position)
Beispiel #20
0
    def __init__(self):
        # base class constructor
        viz.EventClass.__init__(self)

        # set up keyboard and timer callback methods
        self.callback(viz.KEYDOWN_EVENT, self.onKeyDown)

        self.listAlien = []
        self.points = 0
        # avatar's x,z location in maze and its rotation angle
        self.theta = 0
        self.x = 2
        self.z = 2
        self.y = 1
        self.monX = 2
        self.monY = 1
        self.monZ = 27
        self.first = False
        self.bird = True
        self.birdX = 20
        self.birdY = 15
        self.birdZ = 5
        self.EndGame = False
        # The 2D array below stores the representation of a maze.
        # Array entries containing a 2 represent 1 x 2 x 1 wall blocks.
        # Array entries containing a 0 represent 1 x 0.1 x 1 floor blocks.
        self.maze = []
        #bottom left
        self.maze = [[
            4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
            4, 4, 4, 4, 4, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 0, 2, 0, 0, 2, 0, 1, 0, 0, 2, 0, 0, 2, 1, 1, 0, 0, 2, 0, 0,
            2, 0, 0, 2, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 2, 0, 0, 2, 0, 2, 0, 1, 0, 2, 0, 0, 2, 0, 1, 1, 0, 2, 0, 0, 2,
            0, 0, 2, 0, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 2, 4, 4, 2, 0, 4, 4, 0, 0, 4, 4, 0, 2, 4, 4, 2, 0, 4, 4, 0,
            0, 4, 4, 2, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 1, 1, 4, 4, 0, 0, 4, 4, 2, 0, 4, 4, 1, 1, 4, 4, 0, 2, 4, 4, 2,
            0, 4, 4, 1, 1, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 2, 4, 4, 0, 0, 4, 4, 0, 0, 4, 4, 2, 0, 4, 4, 2, 0, 4, 4, 0,
            2, 4, 4, 2, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2,
            0, 0, 2, 0, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 2, 0, 0, 2, 0, 0, 2, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0,
            2, 0, 0, 2, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 2, 0, 4, 4, 4, 2, 0, 4, 2, 0, 4, 4, 4, 4, 4, 4, 0, 2, 0, 4, 2,
            0, 0, 4, 0, 2, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 2, 4, 4, 4, 0, 2, 4, 0, 2, 4, 4, 4, 4, 4, 4, 2, 0, 0, 4, 0,
            2, 4, 4, 2, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 2, 0, 4, 4, 4, 2, 0, 4, 2, 0, 4, 4, 4, 4, 4, 4, 0, 0, 0, 4, 2,
            0, 4, 4, 0, 2, 4
        ]] + self.maze
        self.maze = [[
            4, 1, 1, 4, 4, 4, 0, 2, 4, 1, 1, 4, 4, 4, 4, 4, 4, 0, 0, 4, 4, 1,
            1, 1, 4, 2, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 2, 4, 4, 0, 2, 0, 0, 2, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 4, 0,
            2, 0, 0, 2, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 4, 2,
            0, 2, 0, 0, 2, 4
        ]] + self.maze
        self.maze = [[
            4, 2, 0, 0, 2, 0, 0, 4, 4, 2, 0, 4, 4, 0, 2, 4, 4, 4, 0, 2, 4, 0,
            0, 4, 4, 1, 1, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 2, 4, 4, 0, 2, 4, 4, 0, 0, 4, 4, 2, 0, 4, 4, 0, 2, 0, 4, 0,
            2, 4, 4, 0, 2, 4
        ]] + self.maze
        self.maze = [[
            4, 2, 0, 0, 4, 2, 0, 1, 0, 2, 0, 2, 0, 0, 2, 4, 4, 0, 2, 0, 0, 2,
            0, 1, 0, 2, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 0, 2, 0, 0, 2, 1, 2, 0, 0, 2, 0, 2, 0, 1, 0, 0, 2, 0, 0, 2,
            0, 1, 2, 0, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 2, 0, 2, 0, 0, 1, 2, 0, 2, 0, 0, 0, 2, 1, 0, 2, 0, 0, 2, 0,
            0, 1, 0, 2, 0, 4
        ]] + self.maze
        ##################################################################################
        self.maze = [[
            4, 0, 2, 0, 2, 0, 0, 1, 2, 0, 2, 0, 0, 0, 2, 1, 0, 2, 0, 0, 2, 0,
            0, 1, 0, 2, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 0, 2, 0, 0, 2, 1, 2, 0, 0, 2, 0, 2, 0, 1, 0, 0, 2, 0, 0, 2,
            0, 1, 2, 0, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 2, 0, 0, 4, 2, 0, 1, 0, 2, 0, 2, 0, 0, 2, 4, 4, 0, 2, 0, 0, 2,
            0, 1, 0, 2, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 2, 4, 4, 0, 2, 4, 4, 0, 0, 4, 4, 2, 0, 4, 4, 0, 2, 0, 4, 0,
            2, 4, 4, 0, 2, 4
        ]] + self.maze
        self.maze = [[
            4, 2, 0, 0, 2, 0, 0, 4, 4, 2, 0, 4, 4, 0, 2, 4, 4, 4, 0, 2, 4, 0,
            0, 4, 4, 1, 1, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 4, 2,
            0, 2, 0, 0, 2, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 2, 4, 4, 0, 2, 0, 0, 2, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 4, 0,
            2, 0, 0, 2, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 1, 1, 4, 4, 4, 0, 2, 4, 1, 1, 4, 4, 4, 4, 4, 4, 0, 0, 4, 4, 1,
            1, 1, 4, 2, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 2, 0, 4, 4, 4, 2, 0, 4, 2, 0, 4, 4, 4, 4, 4, 4, 0, 0, 0, 4, 2,
            0, 4, 4, 0, 2, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 2, 4, 4, 4, 0, 2, 4, 0, 2, 4, 4, 4, 4, 4, 4, 2, 0, 0, 4, 0,
            2, 4, 4, 2, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 2, 0, 4, 4, 4, 2, 0, 4, 2, 0, 4, 4, 4, 4, 4, 4, 0, 2, 0, 4, 2,
            0, 0, 4, 0, 2, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 2, 0, 0, 2, 0, 0, 2, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0,
            2, 0, 0, 2, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2,
            0, 0, 2, 0, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 2, 4, 4, 0, 0, 4, 4, 0, 0, 4, 4, 2, 0, 4, 4, 2, 0, 4, 4, 0,
            2, 4, 4, 2, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 1, 1, 4, 4, 0, 0, 4, 4, 2, 0, 4, 4, 1, 1, 4, 4, 0, 2, 4, 4, 2,
            0, 4, 4, 1, 1, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 2, 4, 4, 2, 0, 4, 4, 0, 0, 4, 4, 0, 2, 4, 4, 2, 0, 4, 4, 0,
            0, 4, 4, 2, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 2, 0, 0, 2, 0, 2, 0, 1, 0, 2, 0, 0, 2, 0, 1, 1, 0, 2, 0, 0, 2,
            0, 0, 2, 0, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 0, 2, 0, 0, 2, 0, 1, 0, 0, 2, 0, 0, 2, 1, 1, 0, 0, 2, 0, 0,
            2, 0, 0, 2, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
            4, 4, 4, 4, 4, 4
        ]] + self.maze

        view = viz.MainView
        mat = viz.Matrix()
        mat.postAxisAngle(0, 1, 0, 270)
        mat.postAxisAngle(0, 0, 1, 40)
        mat.postTrans(self.birdX, self.birdY, self.birdZ)
        view.setMatrix(mat)

        self.blocks = []
        # Code to create blocks forming the maze goes here
        for row in range(0, len(self.maze)):
            for i in range(0, len(self.maze[row])):
                #* self.maze[i]
                if (self.maze[row][i] == 4):
                    block = vizshape.addCube(size=1.0, color=viz.RED)
                elif (self.maze[row][i] == 1):
                    block = vizshape.addCube(size=1.0, color=viz.BLUE)
                else:
                    block = vizshape.addCube(size=1.0, color=viz.BLACK)
                m = viz.Matrix()
                xx = 1
                yy = .5
                zz = 1
                if (row != 0):
                    xx = xx + (row * 1)
                if (i != 0):
                    zz = zz + (i * 1)
                m.postTrans(xx, yy, zz)

                if (self.maze[row][i] == 4):
                    m.postScale(1, 4.0, 1)
                elif (self.maze[row][i] == 1):
                    m.postScale(1, 1.5, 1)
                else:
                    m.postScale(1, 1, 1)
                self.blocks = [[xx, zz]] + self.blocks
                block.setMatrix(m)

        for row in range(0, len(self.maze)):
            for i in range(0, len(self.maze[row])):
                if (self.maze[row][i] == 2):
                    #self.sphere = vizshape.addSphere(.125,10,10)
                    self.sphere = Sphere()

                    m = viz.Matrix()
                    xx = 1
                    yy = 1.5
                    zz = 1
                    if (row != 0):
                        xx = xx + (row * 1)
                    if (i != 0):
                        zz = zz + (i * 1)
                    m.postTrans(xx, yy, zz)
                    self.sphere.setXZ(xx, zz)
                    self.listAlien.append(self.sphere)
                    self.sphere.vertices.setMatrix(m)

        self.avatar = viz.add('vcc_female.cfg')
        m = viz.Matrix()
        m.postTrans(self.x, self.y, self.z)
        m.postAxisAngle(0, 1, 0, self.theta)
        self.avatar.setMatrix(m)

        self.monster = viz.add('vcc_female.cfg')
        m = viz.Matrix()
        m.postTrans(self.monX, self.monY, self.monZ)
        m.postAxisAngle(0, 1, 0, self.theta)
        self.monster.setMatrix(m)
Beispiel #21
0
class Maze(viz.EventClass):

    # Constructor
    def __init__(self):
        # base class constructor
        viz.EventClass.__init__(self)

        # set up keyboard and timer callback methods
        self.callback(viz.KEYDOWN_EVENT, self.onKeyDown)

        self.listAlien = []
        self.points = 0
        # avatar's x,z location in maze and its rotation angle
        self.theta = 0
        self.x = 2
        self.z = 2
        self.y = 1
        self.monX = 2
        self.monY = 1
        self.monZ = 27
        self.first = False
        self.bird = True
        self.birdX = 20
        self.birdY = 15
        self.birdZ = 5
        self.EndGame = False
        # The 2D array below stores the representation of a maze.
        # Array entries containing a 2 represent 1 x 2 x 1 wall blocks.
        # Array entries containing a 0 represent 1 x 0.1 x 1 floor blocks.
        self.maze = []
        #bottom left
        self.maze = [[
            4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
            4, 4, 4, 4, 4, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 0, 2, 0, 0, 2, 0, 1, 0, 0, 2, 0, 0, 2, 1, 1, 0, 0, 2, 0, 0,
            2, 0, 0, 2, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 2, 0, 0, 2, 0, 2, 0, 1, 0, 2, 0, 0, 2, 0, 1, 1, 0, 2, 0, 0, 2,
            0, 0, 2, 0, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 2, 4, 4, 2, 0, 4, 4, 0, 0, 4, 4, 0, 2, 4, 4, 2, 0, 4, 4, 0,
            0, 4, 4, 2, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 1, 1, 4, 4, 0, 0, 4, 4, 2, 0, 4, 4, 1, 1, 4, 4, 0, 2, 4, 4, 2,
            0, 4, 4, 1, 1, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 2, 4, 4, 0, 0, 4, 4, 0, 0, 4, 4, 2, 0, 4, 4, 2, 0, 4, 4, 0,
            2, 4, 4, 2, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2,
            0, 0, 2, 0, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 2, 0, 0, 2, 0, 0, 2, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0,
            2, 0, 0, 2, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 2, 0, 4, 4, 4, 2, 0, 4, 2, 0, 4, 4, 4, 4, 4, 4, 0, 2, 0, 4, 2,
            0, 0, 4, 0, 2, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 2, 4, 4, 4, 0, 2, 4, 0, 2, 4, 4, 4, 4, 4, 4, 2, 0, 0, 4, 0,
            2, 4, 4, 2, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 2, 0, 4, 4, 4, 2, 0, 4, 2, 0, 4, 4, 4, 4, 4, 4, 0, 0, 0, 4, 2,
            0, 4, 4, 0, 2, 4
        ]] + self.maze
        self.maze = [[
            4, 1, 1, 4, 4, 4, 0, 2, 4, 1, 1, 4, 4, 4, 4, 4, 4, 0, 0, 4, 4, 1,
            1, 1, 4, 2, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 2, 4, 4, 0, 2, 0, 0, 2, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 4, 0,
            2, 0, 0, 2, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 4, 2,
            0, 2, 0, 0, 2, 4
        ]] + self.maze
        self.maze = [[
            4, 2, 0, 0, 2, 0, 0, 4, 4, 2, 0, 4, 4, 0, 2, 4, 4, 4, 0, 2, 4, 0,
            0, 4, 4, 1, 1, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 2, 4, 4, 0, 2, 4, 4, 0, 0, 4, 4, 2, 0, 4, 4, 0, 2, 0, 4, 0,
            2, 4, 4, 0, 2, 4
        ]] + self.maze
        self.maze = [[
            4, 2, 0, 0, 4, 2, 0, 1, 0, 2, 0, 2, 0, 0, 2, 4, 4, 0, 2, 0, 0, 2,
            0, 1, 0, 2, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 0, 2, 0, 0, 2, 1, 2, 0, 0, 2, 0, 2, 0, 1, 0, 0, 2, 0, 0, 2,
            0, 1, 2, 0, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 2, 0, 2, 0, 0, 1, 2, 0, 2, 0, 0, 0, 2, 1, 0, 2, 0, 0, 2, 0,
            0, 1, 0, 2, 0, 4
        ]] + self.maze
        ##################################################################################
        self.maze = [[
            4, 0, 2, 0, 2, 0, 0, 1, 2, 0, 2, 0, 0, 0, 2, 1, 0, 2, 0, 0, 2, 0,
            0, 1, 0, 2, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 0, 2, 0, 0, 2, 1, 2, 0, 0, 2, 0, 2, 0, 1, 0, 0, 2, 0, 0, 2,
            0, 1, 2, 0, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 2, 0, 0, 4, 2, 0, 1, 0, 2, 0, 2, 0, 0, 2, 4, 4, 0, 2, 0, 0, 2,
            0, 1, 0, 2, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 2, 4, 4, 0, 2, 4, 4, 0, 0, 4, 4, 2, 0, 4, 4, 0, 2, 0, 4, 0,
            2, 4, 4, 0, 2, 4
        ]] + self.maze
        self.maze = [[
            4, 2, 0, 0, 2, 0, 0, 4, 4, 2, 0, 4, 4, 0, 2, 4, 4, 4, 0, 2, 4, 0,
            0, 4, 4, 1, 1, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 4, 2,
            0, 2, 0, 0, 2, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 2, 4, 4, 0, 2, 0, 0, 2, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 4, 0,
            2, 0, 0, 2, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 1, 1, 4, 4, 4, 0, 2, 4, 1, 1, 4, 4, 4, 4, 4, 4, 0, 0, 4, 4, 1,
            1, 1, 4, 2, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 2, 0, 4, 4, 4, 2, 0, 4, 2, 0, 4, 4, 4, 4, 4, 4, 0, 0, 0, 4, 2,
            0, 4, 4, 0, 2, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 2, 4, 4, 4, 0, 2, 4, 0, 2, 4, 4, 4, 4, 4, 4, 2, 0, 0, 4, 0,
            2, 4, 4, 2, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 2, 0, 4, 4, 4, 2, 0, 4, 2, 0, 4, 4, 4, 4, 4, 4, 0, 2, 0, 4, 2,
            0, 0, 4, 0, 2, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 2, 0, 0, 2, 0, 0, 2, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0,
            2, 0, 0, 2, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2,
            0, 0, 2, 0, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 2, 4, 4, 0, 0, 4, 4, 0, 0, 4, 4, 2, 0, 4, 4, 2, 0, 4, 4, 0,
            2, 4, 4, 2, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 1, 1, 4, 4, 0, 0, 4, 4, 2, 0, 4, 4, 1, 1, 4, 4, 0, 2, 4, 4, 2,
            0, 4, 4, 1, 1, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 2, 4, 4, 2, 0, 4, 4, 0, 0, 4, 4, 0, 2, 4, 4, 2, 0, 4, 4, 0,
            0, 4, 4, 2, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 2, 0, 0, 2, 0, 2, 0, 1, 0, 2, 0, 0, 2, 0, 1, 1, 0, 2, 0, 0, 2,
            0, 0, 2, 0, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 0, 0, 2, 0, 0, 2, 0, 1, 0, 0, 2, 0, 0, 2, 1, 1, 0, 0, 2, 0, 0,
            2, 0, 0, 2, 0, 4
        ]] + self.maze
        self.maze = [[
            4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
            4, 4, 4, 4, 4, 4
        ]] + self.maze

        view = viz.MainView
        mat = viz.Matrix()
        mat.postAxisAngle(0, 1, 0, 270)
        mat.postAxisAngle(0, 0, 1, 40)
        mat.postTrans(self.birdX, self.birdY, self.birdZ)
        view.setMatrix(mat)

        self.blocks = []
        # Code to create blocks forming the maze goes here
        for row in range(0, len(self.maze)):
            for i in range(0, len(self.maze[row])):
                #* self.maze[i]
                if (self.maze[row][i] == 4):
                    block = vizshape.addCube(size=1.0, color=viz.RED)
                elif (self.maze[row][i] == 1):
                    block = vizshape.addCube(size=1.0, color=viz.BLUE)
                else:
                    block = vizshape.addCube(size=1.0, color=viz.BLACK)
                m = viz.Matrix()
                xx = 1
                yy = .5
                zz = 1
                if (row != 0):
                    xx = xx + (row * 1)
                if (i != 0):
                    zz = zz + (i * 1)
                m.postTrans(xx, yy, zz)

                if (self.maze[row][i] == 4):
                    m.postScale(1, 4.0, 1)
                elif (self.maze[row][i] == 1):
                    m.postScale(1, 1.5, 1)
                else:
                    m.postScale(1, 1, 1)
                self.blocks = [[xx, zz]] + self.blocks
                block.setMatrix(m)

        for row in range(0, len(self.maze)):
            for i in range(0, len(self.maze[row])):
                if (self.maze[row][i] == 2):
                    #self.sphere = vizshape.addSphere(.125,10,10)
                    self.sphere = Sphere()

                    m = viz.Matrix()
                    xx = 1
                    yy = 1.5
                    zz = 1
                    if (row != 0):
                        xx = xx + (row * 1)
                    if (i != 0):
                        zz = zz + (i * 1)
                    m.postTrans(xx, yy, zz)
                    self.sphere.setXZ(xx, zz)
                    self.listAlien.append(self.sphere)
                    self.sphere.vertices.setMatrix(m)

        self.avatar = viz.add('vcc_female.cfg')
        m = viz.Matrix()
        m.postTrans(self.x, self.y, self.z)
        m.postAxisAngle(0, 1, 0, self.theta)
        self.avatar.setMatrix(m)

        self.monster = viz.add('vcc_female.cfg')
        m = viz.Matrix()
        m.postTrans(self.monX, self.monY, self.monZ)
        m.postAxisAngle(0, 1, 0, self.theta)
        self.monster.setMatrix(m)

    # Key pressed down event code.

    def onKeyDown(self, key):
        if (key == viz.KEY_RIGHT):
            self.theta = self.theta + 90
            m = viz.Matrix()
            m.postAxisAngle(0, 1, 0, self.theta)
            m.postTrans(self.x, self.y, self.z)
            self.avatar.setMatrix(m)
            if (self.theta == 360):
                self.theta = 0

        if (key == viz.KEY_LEFT):
            self.theta = self.theta - 90
            m = viz.Matrix()
            m.postAxisAngle(0, 1, 0, self.theta)
            m.postTrans(self.x, self.y, self.z)
            self.avatar.setMatrix(m)
            if (self.theta == -360):
                self.theta = 0

        if (key == ' '):
            self.isValid = False
            if (self.theta == 90 or self.theta == -270):
                if (self.maze[int(self.x)][int(self.z - 1)] == 1):
                    self.isValid = True
            elif (self.theta == 0):
                if (self.maze[int(self.x - 1)][int(self.z)] == 1):
                    self.isValid = True
            elif (self.theta == 270 or self.theta == -90):
                if (self.maze[int(self.x - 2)][int(self.z - 1)] == 1):
                    self.isValid = True
            elif (self.theta == 180 or self.theta == -180):
                if (self.maze[int(self.x - 1)][int(self.z - 2)] == 1):
                    self.isValid = True
            if (self.isValid and self.EndGame == False):
                if (self.theta == 90 or self.theta == -270):
                    self.x = self.x + 2
                elif (self.theta == 0):
                    self.z = self.z + 2
                elif (self.theta == 270 or self.theta == -90):
                    self.x = self.x - 2
                elif (self.theta == 180 or self.theta == -180):
                    self.z = self.z - 2
                m = viz.Matrix()
                m.postAxisAngle(0, 1, 0, self.theta)
                m.postTrans(self.x, self.y, self.z)
                self.avatar.setMatrix(m)

        if (key == viz.KEY_DOWN):
            self.isValid = False
            if (self.theta == 270 or self.theta == -90):
                if (self.maze[int(self.x)][int(self.z - 1)] == 0
                        or self.maze[int(self.x)][int(self.z - 1)] == 2):
                    self.isValid = True
            elif (self.theta == 180 or self.theta == -180):
                if (self.maze[int(self.x - 1)][int(self.z)] == 0
                        or self.maze[int(self.x - 1)][int(self.z)] == 2):
                    self.isValid = True
            elif (self.theta == 90 or self.theta == -270):
                if (self.maze[int(self.x - 2)][int(self.z - 1)] == 0
                        or self.maze[int(self.x - 2)][int(self.z - 1)] == 2):
                    self.isValid = True
            elif (self.theta == 0):
                if (self.maze[int(self.x - 1)][int(self.z - 2)] == 0
                        or self.maze[int(self.x - 1)][int(self.z - 2)] == 2):
                    self.isValid = True
            if (self.isValid and self.EndGame == False):
                m = viz.Matrix()
                self.moveZ = math.cos(math.radians(self.theta))
                self.moveX = math.sin(math.radians(self.theta))
                self.x = self.x - self.moveX
                self.z = self.z - self.moveZ
                m.postAxisAngle(0, 1, 0, self.theta)
                m.postTrans(self.x, self.y, self.z)
                self.avatar.setMatrix(m)

        if (key == viz.KEY_UP):
            self.isValid = False
            if (self.theta == 90 or self.theta == -270):
                if (self.maze[int(self.x)][int(self.z - 1)] == 0
                        or self.maze[int(self.x)][int(self.z - 1)] == 2):
                    self.isValid = True

            elif (self.theta == 0):
                if (self.maze[int(self.x - 1)][int(self.z)] == 0
                        or self.maze[int(self.x - 1)][int(self.z)] == 2):
                    self.isValid = True
            elif (self.theta == 270 or self.theta == -90):
                if (self.maze[int(self.x - 2)][int(self.z - 1)] == 0
                        or self.maze[int(self.x - 2)][int(self.z - 1)] == 2):
                    self.isValid = True
            elif (self.theta == 180 or self.theta == -180):
                if (self.maze[int(self.x - 1)][int(self.z - 2)] == 0
                        or self.maze[int(self.x - 1)][int(self.z - 2)] == 2):
                    self.isValid = True
            if (self.isValid and self.EndGame == False):
                m = viz.Matrix()
                self.moveZ = math.cos(math.radians(self.theta))
                self.moveX = math.sin(math.radians(self.theta))
                self.x = self.x + self.moveX
                self.z = self.z + self.moveZ
                m.postAxisAngle(0, 1, 0, self.theta)
                m.postTrans(self.x, self.y, self.z)
                self.avatar.setMatrix(m)
        for spheres in self.listAlien:
            if (spheres.getX() == self.x and spheres.getZ() == self.z):
                spheres.setXZ(0, 1000)
                self.points = self.points + 1
                print(self.points)
        if (key == '1'):
            view = viz.MainView
            mat = viz.Matrix()
            mat.postAxisAngle(1, 0, 0, 90)
            mat.postTrans(0, 20, 0)
            view.setMatrix(mat)
            self.first = False
            self.bird = False

        if (key == '2'):
            view = viz.MainView
            mat = viz.Matrix()
            mat.postAxisAngle(0, 1, 0, 270)
            mat.postAxisAngle(0, 0, 1, 40)
            mat.postTrans(self.birdX, self.birdY, self.birdZ)
            view.setMatrix(mat)
            self.first = False
            self.bird = True

        if (key == '3' or self.first):
            view = viz.MainView
            mat = viz.Matrix()
            mat.postAxisAngle(0, 1, 0, self.theta)
            mat.postTrans(self.x, self.y + 1.0, self.z)
            view.setMatrix(mat)
            self.first = True
            self.bird = False
        self.monsterMove()

        if (self.bird == True):
            if (key == 'a'):
                self.birdZ = self.birdZ - 1
                view = viz.MainView
                mat = viz.Matrix()
                mat.postAxisAngle(0, 1, 0, 270)
                mat.postAxisAngle(0, 0, 1, 40)
                mat.postTrans(self.birdX, self.birdY, self.birdZ)
                view.setMatrix(mat)

            elif (key == 'd'):
                view = viz.MainView
                self.birdZ = self.birdZ + 1
                mat = viz.Matrix()
                mat.postAxisAngle(0, 1, 0, 270)
                mat.postAxisAngle(0, 0, 1, 40)
                mat.postTrans(self.birdX, self.birdY, self.birdZ)
                view.setMatrix(mat)

            elif (key == 'w'):
                view = viz.MainView
                self.birdX = self.birdX - 1
                mat = viz.Matrix()
                mat.postAxisAngle(0, 1, 0, 270)
                mat.postAxisAngle(0, 0, 1, 40)
                mat.postTrans(self.birdX, self.birdY, self.birdZ)
                view.setMatrix(mat)

            elif (key == 's'):
                view = viz.MainView
                self.birdX = self.birdX + 1
                mat = viz.Matrix()
                mat.postAxisAngle(0, 1, 0, 270)
                mat.postAxisAngle(0, 0, 1, 40)
                mat.postTrans(self.birdX, self.birdY, self.birdZ)
                view.setMatrix(mat)

    def monsterMove(self):
        self.shortest = 9999
        self.decidedX = -1
        self.decidedZ = -1
        if (self.monX == self.x and self.monZ == self.z):
            self.EndGame = True
            t = viz.addText("Total Points: " + str(self.points),
                            viz.SCREEN,
                            pos=[0, 0, 0])
            p = viz.addText(str(self.points), viz.SCREEN, pos=[5, 0, 0])

        if (self.EndGame == False):

            if (self.x > self.monX
                    and self.maze[int(self.monX + 1)][int(self.monZ)] != 4):
                self.monX = self.monX + 1
            elif (self.x < self.monX
                  and self.maze[int(self.monX - 1)][int(self.monZ)] != 4):
                self.monX = self.monX - 1
            elif (self.z > self.monZ
                  and self.maze[int(self.monX)][int(self.monZ + 1)] != 4):
                self.monX = self.monX + 1
            elif (self.z < self.monZ
                  and self.maze[int(self.monX)][int(self.monZ - 1)] != 4):
                self.monZ = self.monZ - 1
            elif (self.monX == self.x and self.monZ == self.z):
                self.EndGame = True

            m = viz.Matrix()
            m.postTrans(int(self.monX), self.monY, int(self.monZ))

            self.monster.setMatrix(m)
Beispiel #22
0
            #aim harder/decrease FOV
            elif key == "[+]":
                player.fromScreenD += 0.005
            #aim less/increase FOV
            elif key == "[-]":
                #FIXED ERROR: screen cannot be behind player
                if (player.fromScreenD > 0.01):
                    player.fromScreenD -= 0.005
        #finds the difference to the previous call in ms
        dt = CLOCK.tick()
        #adds difference to time_elapsed(timer)
        time_elasped += dt
        #Sphere Generation(2 new spheres every second)
        if time_elasped > 2000:
            Sphere(
                [randint(-MAX, MAX),
                 randint(-MAX, MAX),
                 randint(-MAX, MAX)])
            time_elasped = 0
        #draws game screen
        RenderUtils.drawGame(shooting, dt)
    #Here's where all the code for the GAMEOVER screen lies
    elif (player.screenType == ScreenType.GAMEOVER):
        #draws gameover screen
        RenderUtils.drawGameOver(clicking)
        #FIXED BUG: sometimes the rocket sound would play after the game is over, this is to prevent that
        SOUND_ROCKET.stop()

        #FIXED BUG: resets keyPressed because sometimes pygame never calls the keyUp event,
        #leading the program to think the key is pressed when it isn't.
        keyPressed = []
    #Here's where all the code for the RULES screen lies
Beispiel #23
0
import Box
import Pyramid
import Sphere
shape = input("Enter which shape you would like to calculate (b = box, s = sphere, or p = pyramid) : ")

if shape == "b":
    b1 = Box.Box()
    b1.length = int(input("Enter box length: "))
    b1.width = int(input("Enter box width: "))
    b1.length = int(input("Enter box length: "))
    b1.volume()
    b1.surfArea()
elif shape == "p":
    p1 = Pyramid.Pyramid()
    p1.length = int(input("Enter pyramid length: "))
    p1.width = int(input("Enter pyramid width: "))
    p1.height = int(input("Enter pyramid height: "))
    p1.volume()
elif shape == "s":
    s1 = Sphere.Sphere()
    s1.radius = int(input("Enter sphere radius: "))
    s1.volume()
    
    
#!/usr/bin/python3
import Box, Pyramid, Sphere

shape = input("Enter a shape (Box, Pyramid, Sphere): ")

if (shape == "Box" or shape == "B" or shape == "box" or shape == "b"):
    b1 = Box.Cube()
    b1.bw = int(input("Box width: "))
    b1.bl = int(input("Box length: "))
    b1.bh = int(input("Box height: "))
    b1.volume()
    b1.surfaceArea()

elif (shape == "Pyramid" or shape == "P" or shape == "pyramid"
      or shape == "p"):
    p1 = Pyramid.Cypher()
    p1.pw = int(input("Pyramid width: "))
    p1.pl = int(input("Pyramid length: "))
    p1.ph = int(input("Pyramid height: "))
    p1.volume()
    p1.surfaceArea()

elif (shape == "Sphere" or shape == "S" or shape == "sphere" or shape == "s"):
    s1 = Sphere.Orb()
    s1.r = int(input("Radius: "))
    s1.volume()
    s1.surfaceArea()
Beispiel #25
0
#Box
if selection == 'box':
    length = int(input("What is the length of your box: "))
    width = int(input("What is the width of your box: "))
    height = int(input("What is the height of your box: "))
    box = Box.Box(length, width, height)
    box.volume()
    box.surArea()

#Pyramid
elif selection == 'pyramid':
    length = int(input("What is the length of your pyramid: "))
    width = int(input("What is the width of your pyramid: "))
    height = int(input("What is the height of your pyramid: "))
    pyramid = Pyramid.Pyramid(length, width, height)
    pyramid.volume()
    pyramid.surArea()

#Sphere
elif selection == 'sphere':
    length = int(input("What is the length of your sphere: "))
    width = int(input("What is the width of your sphere: "))
    height = int(input("What is the height of your sphere: "))
    sphere = Sphere.Sphere(length, width, height)
    sphere.volume()
    sphere.surArea()

#They Goofed
else:
    print("Oops something went wrong, try again")
Beispiel #26
0
import Ray
import random
from PIL import Image
import Camera

spheres = []
xDIM = 500
yDIM = 500
zDim = 500
camera = Camera.Camera(xDIM,yDIM)



for i in range(10):
    x = (random.randint(1,xDIM))
    y = (random.randint(1,yDIM))
    z = (random.randint(1,zDim))

    r = (random.randint(1,100))
    s = Sphere.Sphere((x,y,z),r)
    spheres.append(s)

img = Image.new('RGB', (xDIM, xDIM), color = 'red')
print(img.getpixel((20,20)))
for x in range(xDIM):
    for y in range(yDIM):
        img.putpixel((x,y), camera.getPixel(x,y, spheres))
img.save('pil_red.png')


Beispiel #27
0
import Box
import Pyramid
import Sphere

shape = input(
    "What kind of shape do you want?  Answer B for box, S for sphere, P for pyramid: "
)

if (shape == "B"):
    box1 = Box.Cube()
    box1.w = int(input("Box width: "))
    box1.l = int(input("Box length: "))
    box1.h = int(input("Box height: "))

    box1.volume()
    box1.SA()

elif (shape == "S"):
    sphere1 = Sphere.Pokeball()
    sphere1.r = int(input("Sphere radius: "))
    sphere1.volume()
    sphere1.SA()

elif (shape == "P"):
    pyramid1 = Pyramid.FidgetSpinner()
    pyramid1.pW = int(input("Pyramid width: "))
    pyramid1.pL = int(input("Pyramid length: "))
    pyramid1.pH = int(input("Pyramid height: "))
    pyramid1.volume()
    pyramid1.SA()
Beispiel #28
0
 def makeSphere(self, i, a, d, s):
     v = self.vertices[i]
     return Sphere(v.pos, v.dir.magnitude(), a, d, s)
Beispiel #29
0
import Box
import Pyramid
import Sphere

shape = input(
    "Choose which shape you want to calculate: Box, Sphere, or Pyramid ")

if shape == 'Box':
    l = int(input("Type the Length of your Box "))
    w = int(input("Type the Width of your Box "))
    h = int(input("Type the Height of your Box "))
    b = Box.Box(l, w, h)
    print('This is the Surface Area of your Box | ', b.getSurfaceArea())
    print('This is the Volume of your Box | ', b.getVolume())
elif shape == 'Pyramid':
    l = int(input("Type the Length of your Pyramid "))
    w = int(input("Type the Width of your Pyramid "))
    h = int(input("Type the Height of your Pyramid "))
    p = Pyramid.Pyramid(l, w, h)
    print('This is the Surface Area of your Pyramid | ', p.getSurfaceArea())
    print('This is the Volume of your Pyramid | ', p.getVolume())
elif shape == 'Sphere':
    r = int(input("Type the Radius of your Sphere "))
    s = Sphere.Sphere(r)
    print('This is the Surface Area of your Sphere | ', s.getSurfaceArea())
    print('This is the Volume of your Sphere | ', s.getVolume())
Beispiel #30
0
frames = 1
width = 600
height = 600
samples = 2
pic = Picture(width, height * frames)

check = Checker(Vector3(0.0, 0.0, 0.3), Vector3(0.9, 0.9, 0.8))
gold = Colour(Vector3(0.8, 0.6, 0.4))
blue = Colour(Vector3(0.8, 0.3, 0.3))

roster = Roster()
brick = Lambert(blue)
grass = Lambert(check)
mirror = Metal(gold)

roster.add(Sphere(brick, Vector3(0.0, 0.0, 0.0), 0.5))
roster.add(Sphere(grass, Vector3(0.0, -100.5, 0.0), 100.0))
roster.add(Sphere(mirror, Vector3(1.0, 0.0, 0.0), 0.5))
roster.add(Sphere(mirror, Vector3(-1.0, 0.0, 0.0), 0.5))

for f in range(frames):
    eye = Eye(Vector3(2.0, 0.0 + float(f) * 0.5, 10.0),
              Vector3(0.0, 0.0, -1.0), Vector3(0.0, 1.0, 0.0), math.pi / 2,
              float(width) / float(height))
    for x in range(width):
        for y in range(height):
            col = Vector3()
            for s in range(samples):
                u = (x + random.random()) / float(width)
                v = (y + random.random()) / float(height)
                ray = eye.getRay(u, v)