Exemplo n.º 1
0
 def reset(self, p1=Point(), p2=Point(), p3=Point()):
     self.p[0] = p1
     self.p[1] = p2
     self.p[2] = p3
     self.deformed[0] = p1
     self.deformed[1] = p2
     self.deformed[2] = p3
     self.reset_tail()
Exemplo n.º 2
0
 def __init__(self, displ=0.05):
     self.nodes = []
     self.elements = []
     self.presc = []
     self.fixed = []
     self.displ = displ
     self.filename = ""
     self.min = Point()
     self.max = Point()
Exemplo n.º 3
0
 def __init__(self, p1=Point(), p2=Point(), p3=Point()):
     self.p = []
     self.values = []
     self.deformed = []
     self.p.append(p1)
     self.p.append(p2)
     self.p.append(p3)
     self.deformed.append(p1)
     self.deformed.append(p2)
     self.deformed.append(p3)
Exemplo n.º 4
0
 def init_snake(self):
     # 左上方开始
     snake = Snake()
     head_node = Node(img_path=GameConfig.snake_head_img)
     tail_node = Node(img_path=GameConfig.snake_tail_img)
     head_point = Point(1, 0)
     tail_point = Point(0, 0)
     snake.set_head(node=head_node, point=head_point)
     snake.set_tail(node=tail_node, point=tail_point)
     self.snake = snake
Exemplo n.º 5
0
	def clear_all(self):
		self.size = (300,400) 
		self.points = []
		self.deformed_points = []
		self.edges = []
		self.triangles = []
		self.min = Point()
		self.max = Point()
		self.deformed_min = Point()
		self.deformed_max = Point()
Exemplo n.º 6
0
 def __init__(self, displ=0.05, nodal_yforce=2.0833333, forces=False):
     self.nodes = []
     self.elements = []
     self.presc = []
     self.fixed = []
     self.displ = displ
     self.nodal_yforce = nodal_yforce
     self.use_forces = forces
     self.filename = ""
     self.min = Point()
     self.max = Point()
     self.surface_elements = []
Exemplo n.º 7
0
 def __init__(self, start, board):
     width = 36
     obstacles = []
     obstacles.append(Pipe(start, 6, board))
     obstacles.append(Pipe(start + 30, 6, board))
     obstacles.append(Brick(Point(15, start + 9), Dimension(2, 7), board))
     obstacles.append(Brick(Point(15, start + 19), Dimension(2, 7), board))
     enemy = []
     enemy.append(BossEnemy(FLOOR - 3, start + 9, board))
     coin_row(Point(FLOOR - 1, start + 5), Dimension(1, 25), board)
     Hurdle.__init__(self, start, width, obstacles, enemy, board)
     self.load()
Exemplo n.º 8
0
 def read_nodes(self, nodename):
     self.nodes = []
     lines = read_and_clear_lines(nodename)
     for line in lines:
         line_values = line.split()
         # 1st value is a node indes
         if len(line_values) == 3:  # only x,y coordinates given
             node = Point(float(line_values[1]), float(line_values[2]))
             self.nodes.append(node)
         else:  # x,y,z given
             node = Point(float(line_values[1]), float(line_values[2]),
                          float(line_values[3]))
             self.nodes.append(node)
Exemplo n.º 9
0
def export3dbrick(filename, S, L, H, D, N, M, P, Ux):
    # open a file
    #fil = open(filename,"w+")
    elems = N * M * P  # number of elements
    nods = (N + 1) * (M + 1) * (P + 1)  # number of nodes
    nodes = []
    # algorithm of generating nodes is based on
    # addition node by node in all horisontal layers
    # total number of horisontal layers is P+1
    #
    # Lets count steps - and therefore distances btw nodes
    step_x = 1. * L / P
    step_y = 1. * D / M
    step_z = 1. * H / N
    # loops btw layers and fill nodes array
    for k in range(P + 1):
        x = S + step_x * k
        #print "layer %d" % k
        for i in range(N + 1):
            z = S + step_z * i
            for j in range(M + 1):
                y = S + step_y * j
                #print " node(%d,%d)" % (i,j)
                p = Point(x, y, z)
                nodes.append(p)
    # loops btw layers and fill elements array
    for k in range(P):
        for i in range(N):
            for j in range(M):
                print "element %d %d %d" % (k, i, j)
Exemplo n.º 10
0
 def __init__(self, y, height, board):
     focus = Point(FLOOR - height, y)
     dimensions = Dimension(height, 7)
     pipe = IDENTIFIER['pipe']
     spring = IDENTIFIER['spring']
     shape = [[pipe, pipe, spring, spring, spring, pipe, pipe]] * height
     Obstacle.__init__(self, focus, shape, dimensions, board)
Exemplo n.º 11
0
 def __init__(self, x, y, board):
     shape = [[MARIO_CHAR] * 3] * 3
     People.__init__(self, Point(x, y), 1, shape, Dimension(3, 3), board)
     self.state = 0
     self.air = 0
     self.board.mario = self
     self.update()
Exemplo n.º 12
0
 def update(self):
     '''Logic of update clearing of board and restoring'''
     if self.pre:
         self.board.update(self.pre_point, self.pre, self.dimensions)
     self.pre = self.board.current(self.point, self.shape, self.dimensions)
     self.pre_point = Point(self.point.x, self.point.y)
     self.board.update(self.point, self.shape, self.dimensions)
Exemplo n.º 13
0
def coin_row(point, dimensions, board):
    '''Function to generate a row of coins'''
    for i in range(dimensions.length):
        for j in range(dimensions.breadth):
            Coins(Point(point.x + i, point.y + j), board)
            global totalcoin
            totalcoin += 1
Exemplo n.º 14
0
	def reset_tail(self):
		Triangle3.reset_tail(self)
		p4 = Point()
		p5 = Point()
		p6 = Point()
		p4.x = self.p[0].x+(self.p[1].x-self.p[0].x)/2.0
		p4.y = self.p[0].y+(self.p[1].y-self.p[0].y)/2.0
		p5.x = self.p[1].x+(self.p[2].x-self.p[1].x)/2.0
		p5.y = self.p[1].y+(self.p[2].y-self.p[1].y)/2.0
		p6.x = self.p[2].x+(self.p[0].x-self.p[2].x)/2.0
		p6.y = self.p[2].y+(self.p[0].y-self.p[2].y)/2.0
		self.p.append(p4)
		self.p.append(p5)
		self.p.append(p6)
Exemplo n.º 15
0
 def __init__(self, board):
     slash = IDENTIFIER['cloudSlash']
     backslash = IDENTIFIER['cloudBackSlash']
     space = IDENTIFIER['cloudSpace']
     temp = [space] * 10
     shape = [[slash, backslash] * 6, [backslash, *temp, slash],
              [slash, *temp, backslash], [backslash, slash] * 6]
     focus = Point(randint(0, 7), randint(4, board.breadth - 14))
     Nature.__init__(self, focus, Dimension(4, 12), shape, board)
Exemplo n.º 16
0
 def __init__(self, start, board):
     width = 56
     obstacles = []
     obstacles.append(Brick(Point(19, start), Dimension(2, 5), board))
     obstacles.append(Brick(Point(15, start + 8), Dimension(2, 5), board))
     obstacles.append(Brick(Point(11, start + 16), Dimension(2, 5), board))
     obstacles.append(Brick(Point(5, start + 21), Dimension(2, 11), board))
     obstacles.append(Brick(Point(19, start + 21), Dimension(2, 11), board))
     obstacles.append(Valley(start + 18, 17, board))
     obstacles.append(Brick(Point(11, start + 32), Dimension(2, 5), board))
     obstacles.append(Brick(Point(15, start + 40), Dimension(2, 5), board))
     obstacles.append(Brick(Point(19, start + 48), Dimension(2, 5), board))
     coin_row(Point(4, start + 21), Dimension(1, 11), board)
     Hurdle.__init__(self, start, width, obstacles, [], board)
     self.load()
Exemplo n.º 17
0
 def __init__(self, start, board):
     width = 26
     obstacles = []
     obstacles.append(Spring(start + 3, 6, board))
     coin_row(Point(8, start + 6), Dimension(10, 1), board)
     enemy = []
     enemy.append(SlaveEnemy(FLOOR - 2, start, board))
     enemy.append(SlaveEnemy(FLOOR - 2, start + 13, board))
     Hurdle.__init__(self, start, width, obstacles, enemy, board)
     self.load()
Exemplo n.º 18
0
 def __init__(self, board):
     slash = IDENTIFIER['bushSlash']
     backslash = IDENTIFIER['bushBackSlash']
     space = IDENTIFIER['bushSpace']
     pipe = IDENTIFIER['bushPipe']
     temp = [space] * 10
     shape = [[slash, backslash] * 6, [pipe, *temp, pipe],
              [pipe, *temp, pipe]]
     focus = Point(FLOOR - 3, randint(2, board.breadth - 14))
     Nature.__init__(self, focus, Dimension(3, 12), shape, board)
Exemplo n.º 19
0
 def __init__(self):
     self.display_surf = self.init_window()
     self.snake = None
     self.food = None
     self.running = True
     self.table_cols = GameConfig.win_width // GameConfig.node_width - 1
     self.table_rows = GameConfig.win_height // GameConfig.node_height - 1
     self.points = set([
         Point(px, py) for px in range(self.table_cols + 1)
         for py in range(self.table_rows + 1)
     ])
     self.food_images = self.get_food_imgs()
Exemplo n.º 20
0
 def __init__(
         self,
         classname,  # triangle class name
         A=Point(1, 1),  # upper-left point
         B=Point(4, 7),  # lower-right point
         M=1,  # Vertical bands
         N=1):  # Horizontal bands
     # store template class name
     self.T_ = classname
     #############################
     ### Initial geometry data ###
     #############################
     self.A = A
     self.B = B
     self.M = M
     self.N = N
     # array of unique nodes
     self.points = []
     # index triangle array
     self.triangles_indexed = []
     self.generate()
Exemplo n.º 21
0
def import_file(fname):
    file = open(fname, "r")
    lines = file.readlines()
    file.close()
    count_args = len(lines[0].split(','))
    if count_args != 17:
        wrong_format()
    for line in lines:
        if len(line.split(',')) != 17:
            wrong_format()
    # all ok, file can be processed
    triangles = []
    for line in lines:
        vals = [float(i) for i in line.split(',')]
        triangle = Triangle3(Point(vals[0],vals[1]),Point(vals[2],vals[3]),\
         Point(vals[4],vals[5]))
        g = [[vals[14], vals[14], vals[14]], [vals[15], vals[15], vals[15]],
             [vals[16], vals[16], vals[16]]]
        triangle.set_values_in_nodes(g)
        del triangle.deformed
        triangle.deformed = []
        triangle.deformed.append(Point(vals[6], vals[7]))
        triangle.deformed.append(Point(vals[8], vals[9]))
        triangle.deformed.append(Point(vals[10], vals[11]))
        triangles.append(triangle)
    return triangles
Exemplo n.º 22
0
def lifegame_next(matrix):
    new = {}
    for point, cell in matrix.cells.items():
        sub = matrix.get_area(point, 1)
        for x, line in enumerate(sub):
            for y, cell in enumerate(line):
                abspoint = Point(point.x + x - 1, point.y + y - 1)
                num = area_lifenum(matrix.get_area(abspoint, 1))
                if cell:
                    num -= 1
                if num == 3 or (cell and num == 2):
                    new[abspoint] = Cell(abspoint, True)
    return new
Exemplo n.º 23
0
 def N(self, i, point=Point()):
     if i >= len(self.p):
         print "Triangle6::N:Wrong argument i =", i
         return
     res = 0
     if i == 0 or i == 1 or i == 2:
         res = (2 * self.L(i) - 1) * self.L(i)
     elif i == 3:
         res = 4 * self.L(0) * self.L(1)
     elif i == 4:
         res = 4 * self.L(1) * self.L(2)
     else:  # i == 5
         res = 4 * self.L(2) * self.L(0)
     return res
Exemplo n.º 24
0
def main():
    m = Matrix(lifegame.rule)
    for cells in m:
        os.system("clear")
        width = 10
        height = 10
        for y in range(height):
            for x in range(width):
                if m[Point(x, y)]:
                    put("x")
                else:
                    put("0")
                if x == width - 1:
                    put("\n")
        time.sleep(0.2)
Exemplo n.º 25
0
 def read_nodes(self, nodename):
     self.nodes = []
     lines = read_and_clear_lines(nodename)
     # First line: <# of points> <dimension (must be 3)> <# of attributes>
     # <# of boundary markers (0 or 1)>
     firstline_values = [int(i) for i in lines[0].split()]
     # print firstline_values
     nodes_number = firstline_values[0]
     dof_number = firstline_values[1]
     # next lines:
     # <point #> <x> <y> <z> [attributes] [boundary marker]
     for line_index in range(1, nodes_number + 1):
         line_values = [float(i) for i in lines[line_index].split()]
         self.nodes.append(
             Point(line_values[1], line_values[2], line_values[3]))
Exemplo n.º 26
0
 def L(self, i, point=Point()):
     if i >= len(self.p):
         print "Triangle3::L:wrong argument i =", i
     l = (self.a_coef(i)+self.b_coef(i)*point.x+self.c_coef(i)*point.y)/\
      (2.0*self.S_triangle())
     return l
Exemplo n.º 27
0
 def N(self, i, point=Point()):
     if i >= len(self.p):
         print "Triangle3::N:wrong argument i =", i
         return
     return self.L(i, point)
Exemplo n.º 28
0
 def sample(self):
     r = self.radius * uniform()
     x = normal(size=self.dimension)
     return Point(r * x / np.linalg.norm(x))
Exemplo n.º 29
0
 def sample(self):
     low, high = self.ranges.T
     return Point(low + uniform(size=self.dimension) * (high - low))
Exemplo n.º 30
0
 def __init__(self, start, breadth, board):
     dimensions = Dimension(5, breadth)
     shape = [list([IDENTIFIER['valley']] * dimensions.breadth)
              ] * dimensions.length
     Obstacle.__init__(self, Point(FLOOR, start), shape, dimensions, board)
Exemplo n.º 31
0
 def __init__(self, y, height, board):
     focus = Point(FLOOR - height, y)
     dimensions = Dimension(height, 5)
     shape = [list([IDENTIFIER['pipe']] * 5)] * height
     Obstacle.__init__(self, focus, shape, dimensions, board)