示例#1
0
def main(script, n='5', *args):

    # create n Vertices
    n = int(n)
    #labels = string.ascii_lowercase + string.ascii_uppercase
    #vs = [Vertex(c) for c in labels[:n]]

    v = Vertex('v')
    v.pos = (1110,-100)

    w = Vertex('w')
    w.pos = (20000,40)

    x = Vertex('x')
    x.pos = (100,-2000)

    y = Vertex('y')
    y.pos = (-15,15000)

    # create a graph and a layout
    g = Graph([v, w, x, y])
    g.add_all_edges()
    # layout = CircleLayout(g)
    # layout = RandomLayout(g)
    layout = CartesianLayout(g)

    # draw the graph
    gw = GraphWorld()
    gw.show_graph(g, layout)
    gw.mainloop()
示例#2
0
def main(script, n='5', *args):

    # create n Vertices
    n = int(n)
    #labels = string.ascii_lowercase + string.ascii_uppercase
    #vs = [Vertex(c) for c in labels[:n]]

    v = Vertex('v')
    v.pos = (1110,-100)

    w = Vertex('w')
    w.pos = (20000,40)

    x = Vertex('x')
    x.pos = (100,-2000)

    y = Vertex('y')
    y.pos = (-15,15000)

    # create a graph and a layout
    g = Graph([v, w, x, y])
    g.add_all_edges()
    # layout = CircleLayout(g)
    # layout = RandomLayout(g)
    layout = CartesianLayout(g)

    # draw the graph
    gw = GraphWorld()
    gw.show_graph(g, layout)
    gw.mainloop()
示例#3
0
 def read_file(self, filename):
     '''
     Pre: An ASCII file where each line will be the vertex number, x-coordinate, and y-coordinate separated by spaces
     Post: Updates self.labels and self.coordinates by extracting the labels from the ASCII file
     '''
     f = open(filename, 'r')
     for i in range(6):
         self.header.append(f.readline())    # reads and stores the header section of the file
     line = f.readline()
     while line != 'EOF':
         sp_line = line.split()
         label = sp_line[0]
         coordinate = (int(sp_line[1]),int(sp_line[2]))
         vertex = Vertex(label)
         vertex.pos = coordinate
         self.coordinates.append(vertex)  # forms tuples with the x and y coordinates at each line and appends to self.coordinates
         line = f.readline()
     self.filename = filename    # updates the filename