示例#1
0
def do_live_demo(filename='demodata.npy',
                 sealevel=7.0,
                 steps=42,
                 fps=30,
                 save_fig=False):
    import string
    fps_clock = pygame.time.Clock()
    screen = pygame.display.set_mode(RESOLUTION, pygame.DOUBLEBUF)

    scene = m.Map(filename, sealevel, True)
    look_at = np.array([31, 33, 21])
    cam = c.Camera(position=np.array([
        scene.positions[:, 0].mean(),
        -2 * np.ceil(scene.positions[:, 2].max()) - 9.0,
        2 * np.ceil(scene.positions[:, 2].max()) + 6.0
    ]),
                   screen=c.Screen(resolution=np.array(RESOLUTION)))

    shader = s.Shader(cam)

    angles = np.linspace(0, 2 * np.pi, steps + 1)
    R = np.linalg.norm(cam.position[:2] - look_at[:2])

    for N, a in enumerate(angles):
        screen.fill((0, 0, 0))
        cam.position = np.array([np.sin(a) * R + 31, np.cos(a) * R + 33, 42])
        cam.look_at_point(look_at)

        # pixels = cam.get_screen_coordinates(scene.positions)
        colours = shader.apply_lighting(scene.positions, scene.normals,
                                        scene.colours.copy())
        patches, depth = cam.get_screen_coordinates(scene.patches)

        order = np.argsort(-((scene.positions - cam.position)**2).mean(-1))

        for n in order:
            # Use this to render point cloud in uniform colour:
            # screen.set_at(np.round(pixels[n]).astype(np.int), (204, 0, 0))

            # Use this to render point cloud in shaded colours (not pretty):
            # screen.set_at(np.round(pixels[n]).astype(np.int), colours[n, :])

            # Use this to render patches:
            pygame.draw.polygon(screen, colours[n], patches[n])

        pygame.display.flip()

        if save_fig:
            pygame.image.save(screen,
                              'out/{0}.png'.format(string.zfill(str(N), 2)))

        fps_clock.tick(fps)
示例#2
0
def main():
    screen = pygame.display.set_mode([500, 500])
    m = mapper.Map(1785852800490497919)
    m.set_name("Diamond Seed")
    m.set_coordiantes(237, 64, 113)

    running = True
    while running:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False

        screen.fill((255, 255, 255))
        pygame.draw.circle(screen, (0, 0, 255),
                           (m.coordinates.x, m.coordinates.z), 5)
        pygame.display.flip()
示例#3
0
    def __init__(self, Map):
        self.canvas = Canvas(Map, bg="#4c94a1")
        self.canvas.pack(expand=1, fill=BOTH, padx=3, pady=3)
        self.map = mapper.Map(self.canvas, 30, 30, 30)

        #events initialisations

        self.canvas.bind('<Motion>', self.canvas_hover)
        self.canvas.bind('<B3-Motion>', self.map.right_motion)
        self.canvas.bind('<Button-3>', self.map.right_start)
        self.delta = (0, 0)
        self.start_right_click = (0, 0)
        #painter initialisation

        self.painter = self.canvas.create_oval(5, 5, 10, 10, fill="black")
        self.painter_size = IntVar()
        self.painter_type = 0
        self.tree = 1

        #map initialisation

        self.map.init_map()
        self.map.create_map()
示例#4
0
def do_demo(filename='demodata.npy', cam=None, look_at=None, sealevel=0):
    screen = pygame.display.set_mode(RESOLUTION, pygame.DOUBLEBUF)
    scene = m.Map(filename, sealevel)

    if cam is None:
        cam = c.Camera(position=np.array([
            scene.positions[:, 0].mean(),
            -2 * np.ceil(scene.positions[:, 2].max()) - 9.0,
            2 * np.ceil(scene.positions[:, 2].max()) + 6.0
        ]),
                       screen=c.Screen(resolution=np.array(RESOLUTION)))

    shader = s.Shader(cam)

    if look_at is not None:
        cam.look_at_point(look_at)

    # pixels = cam.get_screen_coordinates(scene.positions)
    colours = shader.apply_lighting(scene.positions, scene.normals,
                                    scene.colours.copy())
    patches, depth = cam.get_screen_coordinates(scene.patches)

    order = np.argsort(-((scene.positions - cam.position)**2).mean(-1))

    for n in order:
        # Use this to render point cloud in uniform colour:
        # screen.set_at(np.round(pixels[n]).astype(np.int), (204, 0, 0))

        # Use this to render point cloud in shaded colours (not pretty):
        # screen.set_at(np.round(pixels[n]).astype(np.int), colours[n, :])

        # Use this to render patches:
        pygame.draw.polygon(screen, colours[n], patches[n])

    pygame.display.flip()

    return scene, cam
示例#5
0
def do_brand_demo(filename='zdata.npy',
                  sealevel=0.0,
                  steps=42,
                  fps=30,
                  save_fig=False,
                  frames=None):
    import string
    fps_clock = pygame.time.Clock()
    screen = pygame.display.set_mode(RESOLUTION, pygame.DOUBLEBUF)

    scene = m.Map(filename, sealevel, True)

    look_at = np.array([63.5, 63.5, 6.0])

    cam = c.Camera(position=np.array([54.5, 63.5, 6.0]),
                   screen=c.Screen(resolution=np.array(RESOLUTION)))

    shader = s.Shader(cam)

    fighter = o.FireFighter()

    fighter.position = np.array([63.5, 63.5, 6.0])

    house = o.House()

    house.position = np.array([58.5, 67, 2.23])

    house.yaw = np.pi / 8

    angles = np.linspace(0, 2 * np.pi, steps + 1)
    R = np.linalg.norm(cam.position[:2] - look_at[:2])

    for N, a in enumerate(angles):
        screen.fill((0, 0, 0))

        cam.position = np.array(
            [np.sin(a) * R + 63.5,
             np.cos(a) * R + 63.5, 6.0])

        cam.look_at_point(look_at)

        colours = shader.apply_lighting(scene.positions, scene.normals,
                                        scene.colours.copy())

        patches, depth = cam.get_screen_coordinates(scene.patches)

        order = np.argsort(-((scene.positions - cam.position)**2).mean(-1))

        for n in order:
            if ((depth[n].mean() > 0 and patches[n] >= 0).any()
                    and (patches[n, :, 0] < RESOLUTION[0]).any()
                    and (patches[n, :, 1] < RESOLUTION[1]).any()):

                pygame.draw.polygon(screen, colours[n], patches[n])

        fighter.yaw = a

        fighter.pitch = a

        fighter.roll = a

        colours = shader.apply_lighting(fighter.positions, fighter.normals,
                                        fighter.colours.copy())

        patches, depth = cam.get_screen_coordinates(fighter.patches)

        order = np.argsort(-((fighter.positions - cam.position)**2).mean(-1))

        for n in order:
            if (colours[n, 3] and depth[n].mean() > 0
                    and (patches[n] >= 0).any()
                    and (patches[n, :, 0] < RESOLUTION[0]).any()
                    and (patches[n, :, 1] < RESOLUTION[1]).any()):
                pygame.draw.polygon(screen, colours[n], patches[n])

        colours = shader.apply_lighting(house.positions, house.normals,
                                        house.colours.copy())

        patches, depth = cam.get_screen_coordinates(house.patches)

        order = np.argsort(-((house.positions - cam.position)**2).mean(-1))

        for n in order:
            if (colours[n, 3] and depth[n].mean() > 0
                    and (patches[n] >= 0).any()
                    and (patches[n, :, 0] < RESOLUTION[0]).any()
                    and (patches[n, :, 1] < RESOLUTION[1]).any()):
                pygame.draw.polygon(screen, colours[n], patches[n])

        pygame.display.flip()

        if save_fig:
            pygame.image.save(screen,
                              'out/{0}.png'.format(string.zfill(str(N), 2)))

        the_tick = fps_clock.tick(fps)
        print "Frame update time: {0} ms".format(the_tick)

        if frames is not None:
            frames.append(the_tick / 1000.0)