Example #1
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()
Example #2
0
 def set_random_goal(self):
     #Fiksaa jos tulee paikka johon ei paase
     self.goal = mesh_grid5.random_target()
Example #3
0
 def set_random_location(self):
     location = mesh_grid5.random_target()
     self.node = location
     self.x = mesh_grid5.coords[location][0]
     self.y = mesh_grid5.coords[location][1]
Example #4
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()
Example #5
0
 def set_random_goal(self):
     #Fiksaa jos tulee paikka johon ei paase
     self.goal = mesh_grid5.random_target()
Example #6
0
 def set_random_location(self):
     location = mesh_grid5.random_target()
     self.node = location
     self.x = mesh_grid5.coords[location][0]
     self.y = mesh_grid5.coords[location][1]