示例#1
0
文件: pairs.py 项目: wweng3/PyLogo
 def distance_to(self, other, wrap):
     # Try all ways to get there including wrapping around.
     # wrap = not World.THE_WORLD.get_gui_value('bounce')
     # Can't do this directly since importing World would be circular
     end_pts = [(self, other)]
     if wrap:
         screen_width = gui.SCREEN_PIXEL_WIDTH()
         screen_height = gui.SCREEN_PIXEL_HEIGHT()
         wrapped_end_pts = [((self+a+b).wrap3(screen_width, screen_height),
                             (other+a+b).wrap3(screen_width, screen_height))
                            for a in [Pixel_xy.pixel_xy_00, Pixel_xy((screen_width/2, 0))]
                            for b in [Pixel_xy.pixel_xy_00, Pixel_xy((0, screen_height/2))]
                            ]
         end_pts += wrapped_end_pts
     dist = min(sqrt((start.x - end.x)**2 + (start.y - end.y)**2) for (start, end) in end_pts)
     return dist
示例#2
0
    def distance_to(self, other):
        # Try all ways to get there possibly including wrapping around.
        bounce = gui_get('Bounce?')
        wrap = bounce is not None and not bounce

        # Can't do this directly since importing World would be circular
        end_pts = [(self, other)]
        if wrap:
            screen_width = gui.SCREEN_PIXEL_WIDTH()
            screen_height = gui.SCREEN_PIXEL_HEIGHT()
            wrapped_end_pts = [
                ((self + a + b).wrap3(screen_width, screen_height),
                 (other + a + b).wrap3(screen_width, screen_height)) for a in
                [Pixel_xy.pixel_xy_00,
                 Pixel_xy((screen_width / 2, 0))] for b in
                [Pixel_xy.pixel_xy_00,
                 Pixel_xy((0, screen_height / 2))]
            ]
            end_pts += wrapped_end_pts
        dist = min(
            hypot(start.x - end.x, start.y - end.y)
            for (start, end) in end_pts)
        return dist
示例#3
0
 def random_pixel():
     x_random = randint(1, gui.SCREEN_PIXEL_WIDTH() - 1)
     y_random = randint(1, gui.SCREEN_PIXEL_HEIGHT() - 1)
     return Pixel_xy((x_random, y_random))