コード例 #1
0
ファイル: mapvisuallarge.py プロジェクト: Chiru/chiru-extras
def create_route(source,destination):
    a = mesh_grid5.find_node(source)
    b = mesh_grid5.find_node(destination)
    route = mesh_grid5.search_path(a,b)
    edges = mesh_grid5.search_portals(a,b)
    funnelpoints = string_pull(route,edges)
    return funnelpoints
コード例 #2
0
def create_route(source, destination):
    a = mesh_grid5.find_node(source)
    b = mesh_grid5.find_node(destination)
    route = mesh_grid5.search_path(a, b)
    edges = mesh_grid5.search_portals(a, b)
    funnelpoints = string_pull(route, edges)
    return funnelpoints
コード例 #3
0
ファイル: Pedestrian.py プロジェクト: Chiru/chiru-extras
 def set_path(self):
     location = mesh_grid5.find_node(self.x,self.y)
     if location == None: location = find_closest([self.x,self.y])
     # Jos joutuu tyhjalle niin nakojaan osaa itse kavella lahimpaan
     #print "Location: ",location
     route = mesh_grid5.search_path(location,self.goal)
     if route == None:
         #pdb.set_trace() 
         #print "No route, what happens?"
         self.destnumber = 0
         return None
     self.routenodes = [r[1] for r in route]
     edges = mesh_grid5.search_portals(location,self.goal)
     self.path = string_pull([r[0] for r in route],edges)
     self.destnumber = 0
コード例 #4
0
 def set_path(self):
     location = mesh_grid5.find_node(self.x, self.y)
     if location == None: location = find_closest([self.x, self.y])
     # Jos joutuu tyhjalle niin nakojaan osaa itse kavella lahimpaan
     #print "Location: ",location
     route = mesh_grid5.search_path(location, self.goal)
     if route == None:
         #pdb.set_trace()
         #print "No route, what happens?"
         self.destnumber = 0
         return None
     self.routenodes = [r[1] for r in route]
     edges = mesh_grid5.search_portals(location, self.goal)
     self.path = string_pull([r[0] for r in route], edges)
     self.destnumber = 0
コード例 #5
0
ファイル: mapvisuallarge.py プロジェクト: Chiru/chiru-extras
def draw_route():
    tlist = gps_raw(gpslist)
    #a = 231
    a = mesh_grid5.random_target()
    b = mesh_grid5.random_target()
    #b = 1044
    anode = xynodes[a]
    bnode = xynodes[b]
    acoord = findCentroid2D(anode[0],anode[1],anode[2])
    bcoord = findCentroid2D(bnode[0],bnode[1],bnode[2])
    nuclear = gpsToTundra(nuke[0],nuke[1])
    sm = gpsToTundra(stmichaels[0],stmichaels[1])
    #print acoord,bcoord
    pygame.draw.circle(screen, (255, 0, 0), (int(acoord[0])*ZOOM+ORIGINX, int(acoord[1])*ZOOM+ORIGINY), 4)
    pygame.draw.circle(screen, (0, 255, 100), (int(bcoord[0])*ZOOM+ORIGINX, int(bcoord[1])*ZOOM+ORIGINY), 4)
    pygame.draw.circle(screen, (255, 255, 255), (int(sm[0])*ZOOM+ORIGINX, int(sm[1])*ZOOM+ORIGINY), 4)
    pygame.draw.circle(screen, (255, 255, 255), (int(nuclear[0])*ZOOM+ORIGINX, int(nuclear[1])*ZOOM+ORIGINY), 4)
    route = mesh_grid5.search_path(a,b)
    edges = mesh_grid5.search_portals(a,b)
    pygame.display.flip()
    if route:
        path = []
        funnelpoints = string_pull(route,edges)
        #print funnelpoints
        for f in funnelpoints:
            px = f[0]*ZOOM+ORIGINX
            py = f[1]*ZOOM+ORIGINY
            path.append([px,py])
        pygame.draw.lines(screen, (0, 255, 0), False, path, 2)
        for f in funnelpoints:
            pygame.draw.circle(screen, (0, 255, 100), (int(f[0])*ZOOM+ORIGINX, int(f[1])*ZOOM+ORIGINY), 4)
           
        #for r in route:
            #pygame.draw.circle(screen, (0, 255, 100), (int(r[0])*ZOOM+ORIGINX, int(r[1])*ZOOM+ORIGINY), 3)
    if tlist:
        for t in tlist:
            if not check_node(t):
                b = [0,0]
                b[0], b[1] = t[1], t[0]
                #print "What happens: ",t
                c = mesh_grid5.coords[find_closest(b)]
                pygame.draw.circle(screen, (255, 255, 255), (int(c[0])*ZOOM+ORIGINX, int(c[1])*ZOOM+ORIGINY), 3)
                pygame.draw.circle(screen, (100, 100, 100), (int(t[0])*ZOOM+ORIGINX, int(t[1])*ZOOM+ORIGINY), 3)
            #print "wat"
            #print t[0],t[1]
            else:
                pygame.draw.circle(screen, (50, 255, 50), (int(t[0])*ZOOM+ORIGINX, int(t[1])*ZOOM+ORIGINY), 3)
    if edges:
        for e in edges:
            e1 = e[0]
            e2 = e[1]
            c = route[edges.index(e)]
            isleft = corner_side(e1,e2,c)
            if isleft:
                left = e1
                right = e2
            else:
                left = e2
                right = e1

            pygame.draw.circle(screen, (255, 255, 255), (int(left[0])*ZOOM+ORIGINX, int(left[1])*ZOOM+ORIGINY), 2)
            pygame.draw.circle(screen, (100, 100, 255), (int(right[0])*ZOOM+ORIGINX, int(right[1])*ZOOM+ORIGINY), 2)     
            #pygame.draw.circle(screen, (255, 255, 255), (int(e[0][0])*ZOOM+ORIGINX, int(e[0][1])*ZOOM+ORIGINY), 2)
            #pygame.draw.circle(screen, (100, 100, 255), (int(e[1][0])*ZOOM+ORIGINX, int(e[1][1])*ZOOM+ORIGINY), 2)
            #pygame.draw.line(screen, (255,255,255), (int(e[0][0])*ZOOM+ORIGINX, int(e[0][1])*ZOOM+ORIGINY), (int(e[1][0])*ZOOM+ORIGINX, int(e[1][1])*ZOOM+ORIGINY), 2)

    pygame.display.flip()
コード例 #6
0
def draw_route():
    tlist = gps_raw(gpslist)
    #a = 231
    a = mesh_grid5.random_target()
    b = mesh_grid5.random_target()
    #b = 1044
    anode = xynodes[a]
    bnode = xynodes[b]
    acoord = findCentroid2D(anode[0], anode[1], anode[2])
    bcoord = findCentroid2D(bnode[0], bnode[1], bnode[2])
    nuclear = gpsToTundra(nuke[0], nuke[1])
    sm = gpsToTundra(stmichaels[0], stmichaels[1])
    #print acoord,bcoord
    pygame.draw.circle(
        screen, (255, 0, 0),
        (int(acoord[0]) * ZOOM + ORIGINX, int(acoord[1]) * ZOOM + ORIGINY), 4)
    pygame.draw.circle(
        screen, (0, 255, 100),
        (int(bcoord[0]) * ZOOM + ORIGINX, int(bcoord[1]) * ZOOM + ORIGINY), 4)
    pygame.draw.circle(
        screen, (255, 255, 255),
        (int(sm[0]) * ZOOM + ORIGINX, int(sm[1]) * ZOOM + ORIGINY), 4)
    pygame.draw.circle(
        screen, (255, 255, 255),
        (int(nuclear[0]) * ZOOM + ORIGINX, int(nuclear[1]) * ZOOM + ORIGINY),
        4)
    route = mesh_grid5.search_path(a, b)
    edges = mesh_grid5.search_portals(a, b)
    pygame.display.flip()
    if route:
        path = []
        funnelpoints = string_pull(route, edges)
        #print funnelpoints
        for f in funnelpoints:
            px = f[0] * ZOOM + ORIGINX
            py = f[1] * ZOOM + ORIGINY
            path.append([px, py])
        pygame.draw.lines(screen, (0, 255, 0), False, path, 2)
        for f in funnelpoints:
            pygame.draw.circle(
                screen, (0, 255, 100),
                (int(f[0]) * ZOOM + ORIGINX, int(f[1]) * ZOOM + ORIGINY), 4)

        #for r in route:
        #pygame.draw.circle(screen, (0, 255, 100), (int(r[0])*ZOOM+ORIGINX, int(r[1])*ZOOM+ORIGINY), 3)
    if tlist:
        for t in tlist:
            if not check_node(t):
                b = [0, 0]
                b[0], b[1] = t[1], t[0]
                #print "What happens: ",t
                c = mesh_grid5.coords[find_closest(b)]
                pygame.draw.circle(
                    screen, (255, 255, 255),
                    (int(c[0]) * ZOOM + ORIGINX, int(c[1]) * ZOOM + ORIGINY),
                    3)
                pygame.draw.circle(
                    screen, (100, 100, 100),
                    (int(t[0]) * ZOOM + ORIGINX, int(t[1]) * ZOOM + ORIGINY),
                    3)
            #print "wat"
            #print t[0],t[1]
            else:
                pygame.draw.circle(
                    screen, (50, 255, 50),
                    (int(t[0]) * ZOOM + ORIGINX, int(t[1]) * ZOOM + ORIGINY),
                    3)
    if edges:
        for e in edges:
            e1 = e[0]
            e2 = e[1]
            c = route[edges.index(e)]
            isleft = corner_side(e1, e2, c)
            if isleft:
                left = e1
                right = e2
            else:
                left = e2
                right = e1

            pygame.draw.circle(
                screen, (255, 255, 255),
                (int(left[0]) * ZOOM + ORIGINX, int(left[1]) * ZOOM + ORIGINY),
                2)
            pygame.draw.circle(screen, (100, 100, 255),
                               (int(right[0]) * ZOOM + ORIGINX,
                                int(right[1]) * ZOOM + ORIGINY), 2)
            #pygame.draw.circle(screen, (255, 255, 255), (int(e[0][0])*ZOOM+ORIGINX, int(e[0][1])*ZOOM+ORIGINY), 2)
            #pygame.draw.circle(screen, (100, 100, 255), (int(e[1][0])*ZOOM+ORIGINX, int(e[1][1])*ZOOM+ORIGINY), 2)
            #pygame.draw.line(screen, (255,255,255), (int(e[0][0])*ZOOM+ORIGINX, int(e[0][1])*ZOOM+ORIGINY), (int(e[1][0])*ZOOM+ORIGINX, int(e[1][1])*ZOOM+ORIGINY), 2)

    pygame.display.flip()