Python pygame.display() Examples
The following are 30
code examples of pygame.display().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pygame
, or try the search function
.
Example #1
Source File: display_test.py From fxxkpython with GNU General Public License v3.0 | 6 votes |
def todo_test_flip(self): # __doc__ (as of 2008-08-02) for pygame.display.flip: # pygame.display.flip(): return None # update the full display Surface to the screen # # This will update the contents of the entire display. If your display # mode is using the flags pygame.HWSURFACE and pygame.DOUBLEBUF, this # will wait for a vertical retrace and swap the surfaces. If you are # using a different type of display mode, it will simply update the # entire contents of the surface. # # When using an pygame.OPENGL display mode this will perform a gl buffer swap. self.fail()
Example #2
Source File: env_utils.py From tensorforce with Apache License 2.0 | 6 votes |
def cv2_grayscale(image, is_bgr=True, depth=1): """Convert a RGB or BGR image to grayscale using OpenCV (cv2). :param image: input image, a numpy.ndarray. :param is_bgr: tells whether the image is in BGR format. If False, RGB format is assumed. :param depth: replicates the gray depth channel multiple times. E.g. useful to display grayscale images as rgb. """ assert depth >= 1 if is_bgr: grayscale = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) else: grayscale = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY) if depth > 1: return np.stack((grayscale,) * depth, axis=-1) return grayscale
Example #3
Source File: webcan.py From pose-regression with MIT License | 6 votes |
def thread_grab_frames(queue_frames, queue_poses): win = pygame.Surface(win_size) frame = pygame.Surface(img_size) hmsurf = pygame.Surface(hmsurf_size) screen = pygame.display.set_mode(screen_size) while True: get_frame(frame) x = surface_to_array(win, frame) queue_frames.put(x) screen.blit(frame, (0,0)) pred = queue_poses.get() # Unpack received data x = pred[-1][0] hm = pred[-2][0] v = pred[-3] p = pred[-4] draw_pose(screen, p, v, img_size[0], img_size[1], prob_thr=0.7) draw_heatmaps(screen, hmsurf, hm) pygame.display.update()
Example #4
Source File: env_utils.py From tensorforce with Apache License 2.0 | 6 votes |
def display_image(display, image, window_size=(800, 600), blend=False): """Displays the given image on a pygame window :param blend: whether to blend or not the given image. :param window_size: the size of the pygame's window. Default is (800, 600) :param display: pygame.display :param image: the image (numpy.array) to display/render on. """ # Resize image if necessary if (image.shape[1], image.shape[0]) != window_size: image = resize(image, size=window_size) image_surface = pygame.surfarray.make_surface(image.swapaxes(0, 1)) if blend: image_surface.set_alpha(100) display.blit(image_surface, (0, 0))
Example #5
Source File: render.py From hypatia-engine with MIT License | 6 votes |
def __init__(self, filters=None): """Will init pygame. Args: filters (list): list of functions which takes and returns a surface. """ pygame.init() pygame.mouse.set_visible(False) self.clock = pygame.time.Clock() self.time_elapsed_milliseconds = 0 display_info = pygame.display.Info() self.screen_size = (display_info.current_w, display_info.current_h) self.screen = pygame.display.set_mode(self.screen_size, FULLSCREEN | DOUBLEBUF) self.filters = filters
Example #6
Source File: render.py From hypatia-engine with MIT License | 6 votes |
def update(self, surface): """Update the screen; apply surface to screen, automatically rescaling for fullscreen. """ scaled_surface = pygame.transform.scale(surface, self.screen_size) if self.filters: for filter_function in self.filters: scaled_surface = filter_function(scaled_surface) self.screen.blit(scaled_surface, (0, 0)) pygame.display.flip() self.time_elapsed_milliseconds = self.clock.tick(Screen.FPS) # how much of this is redundant due to pygame Surface.scroll?
Example #7
Source File: renderer.py From coach with Apache License 2.0 | 6 votes |
def render_image(self, image): """ Render the given image to the pygame window :param image: a grayscale or color image in an arbitrary size. assumes that the channels are the last axis :return: None """ if self.is_open: if len(image.shape) == 2: image = np.stack([image] * 3) if len(image.shape) == 3: if image.shape[0] == 3 or image.shape[0] == 1: image = np.transpose(image, (1, 2, 0)) surface = pygame.surfarray.make_surface(image.swapaxes(0, 1)) surface = pygame.transform.scale(surface, self.size) self.screen.blit(surface, (0, 0)) self.display.flip() self.clock.tick() self.get_events()
Example #8
Source File: display_test.py From fxxkpython with GNU General Public License v3.0 | 6 votes |
def todo_test_flip(self): # __doc__ (as of 2008-08-02) for pygame.display.flip: # pygame.display.flip(): return None # update the full display Surface to the screen # # This will update the contents of the entire display. If your display # mode is using the flags pygame.HWSURFACE and pygame.DOUBLEBUF, this # will wait for a vertical retrace and swap the surfaces. If you are # using a different type of display mode, it will simply update the # entire contents of the surface. # # When using an pygame.OPENGL display mode this will perform a gl buffer swap. self.fail()
Example #9
Source File: display_test.py From fxxkpython with GNU General Public License v3.0 | 6 votes |
def test_set_caption(self): # __doc__ (as of 2008-08-02) for pygame.display.set_caption: # pygame.display.set_caption(title, icontitle=None): return None # set the current window caption # # If the display has a window title, this function will change the # name on the window. Some systems support an alternate shorter title # to be used for minimized displays. # TEST_CAPTION = "test" screen = display.set_mode((100, 100)) self.assertIsNone(display.set_caption(TEST_CAPTION)) self.assertEqual(display.get_caption()[0], TEST_CAPTION) self.assertEqual(display.get_caption()[1], TEST_CAPTION)
Example #10
Source File: display_test.py From fxxkpython with GNU General Public License v3.0 | 6 votes |
def todo_test_get_driver(self): # __doc__ (as of 2008-08-02) for pygame.display.get_driver: # pygame.display.get_driver(): return name # get the name of the pygame display backend # # Pygame chooses one of many available display backends when it is # initialized. This returns the internal name used for the display # backend. This can be used to provide limited information about what # display capabilities might be accelerated. See the SDL_VIDEODRIVER # flags in pygame.display.set_mode() to see some of the common # options. # self.fail()
Example #11
Source File: display_test.py From fxxkpython with GNU General Public License v3.0 | 6 votes |
def todo_test_get_wm_info(self): # __doc__ (as of 2008-08-02) for pygame.display.get_wm_info: # pygame.display.get_wm_info(): return dict # Get information about the current windowing system # # Creates a dictionary filled with string keys. The strings and values # are arbitrarily created by the system. Some systems may have no # information and an empty dictionary will be returned. Most platforms # will return a "window" key with the value set to the system id for # the current display. # # New with pygame 1.7.1 self.fail()
Example #12
Source File: display_test.py From fxxkpython with GNU General Public License v3.0 | 6 votes |
def todo_test_gl_set_attribute(self): # __doc__ (as of 2008-08-02) for pygame.display.gl_set_attribute: # pygame.display.gl_set_attribute(flag, value): return None # request an opengl display attribute for the display mode # # When calling pygame.display.set_mode() with the pygame.OPENGL flag, # Pygame automatically handles setting the OpenGL attributes like # color and doublebuffering. OpenGL offers several other attributes # you may want control over. Pass one of these attributes as the flag, # and its appropriate value. This must be called before # pygame.display.set_mode() # # The OPENGL flags are; # GL_ALPHA_SIZE, GL_DEPTH_SIZE, GL_STENCIL_SIZE, GL_ACCUM_RED_SIZE, # GL_ACCUM_GREEN_SIZE, GL_ACCUM_BLUE_SIZE, GL_ACCUM_ALPHA_SIZE, # GL_MULTISAMPLEBUFFERS, GL_MULTISAMPLESAMPLES, GL_STEREO self.fail()
Example #13
Source File: display_test.py From fxxkpython with GNU General Public License v3.0 | 6 votes |
def todo_test_iconify(self): # __doc__ (as of 2008-08-02) for pygame.display.iconify: # pygame.display.iconify(): return bool # iconify the display surface # # Request the window for the display surface be iconified or hidden. # Not all systems and displays support an iconified display. The # function will return True if successfull. # # When the display is iconified pygame.display.get_active() will # return False. The event queue should receive a ACTIVEEVENT event # when the window has been iconified. # self.fail()
Example #14
Source File: display_test.py From fxxkpython with GNU General Public License v3.0 | 6 votes |
def todo_test_set_icon(self): # __doc__ (as of 2008-08-02) for pygame.display.set_icon: # pygame.display.set_icon(Surface): return None # change the system image for the display window # # Sets the runtime icon the system will use to represent the display # window. All windows default to a simple pygame logo for the window # icon. # # You can pass any surface, but most systems want a smaller image # around 32x32. The image can have colorkey transparency which will be # passed to the system. # # Some systems do not allow the window icon to change after it has # been shown. This function can be called before # pygame.display.set_mode() to create the icon before the display mode # is set. # self.fail()
Example #15
Source File: tank.py From Jtyoui with MIT License | 6 votes |
def start_game(self): load_music('start') while True: self.window.fill([0, 0, 0]) self.get_event() len_enemy = len(TankGame.enemy_tank_list) self.window.blit( self.draw_text('敌方坦克*{0},我方生命值*{1},当前{2}关'.format(len_enemy, self.my_tank_lift, self.number)), (10, 10)) if len_enemy == 0: self.creat_enemy_number += 10 self.number += 1 self.my_tank_lift += 1 self.creat_enemy(self.creat_enemy_number) self.wall_list.clear() self.creat_walls() self.show_my_tank() self.show_enemy_tank() self.show_bullet(TankGame.enemy_bullet_list) self.show_bullet(TankGame.my_bullet_list) self.show_walls() self.display.update() time.sleep(0.02)
Example #16
Source File: display_test.py From fxxkpython with GNU General Public License v3.0 | 6 votes |
def todo_test_set_icon(self): # __doc__ (as of 2008-08-02) for pygame.display.set_icon: # pygame.display.set_icon(Surface): return None # change the system image for the display window # # Sets the runtime icon the system will use to represent the display # window. All windows default to a simple pygame logo for the window # icon. # # You can pass any surface, but most systems want a smaller image # around 32x32. The image can have colorkey transparency which will be # passed to the system. # # Some systems do not allow the window icon to change after it has # been shown. This function can be called before # pygame.display.set_mode() to create the icon before the display mode # is set. # self.fail()
Example #17
Source File: display_test.py From fxxkpython with GNU General Public License v3.0 | 6 votes |
def todo_test_set_gamma_ramp(self): # __doc__ (as of 2008-08-02) for pygame.display.set_gamma_ramp: # change the hardware gamma ramps with a custom lookup # pygame.display.set_gamma_ramp(red, green, blue): return bool # set_gamma_ramp(red, green, blue): return bool # # Set the red, green, and blue gamma ramps with an explicit lookup # table. Each argument should be sequence of 256 integers. The # integers should range between 0 and 0xffff. Not all systems and # hardware support gamma ramps, if the function succeeds it will # return True. # self.fail()
Example #18
Source File: display_test.py From fxxkpython with GNU General Public License v3.0 | 6 votes |
def todo_test_set_gamma(self): # __doc__ (as of 2008-08-02) for pygame.display.set_gamma: # pygame.display.set_gamma(red, green=None, blue=None): return bool # change the hardware gamma ramps # # Set the red, green, and blue gamma values on the display hardware. # If the green and blue arguments are not passed, they will both be # the same as red. Not all systems and hardware support gamma ramps, # if the function succeeds it will return True. # # A gamma value of 1.0 creates a linear color table. Lower values will # darken the display and higher values will brighten. # self.fail()
Example #19
Source File: display_test.py From fxxkpython with GNU General Public License v3.0 | 6 votes |
def test_list_modes(self): modes = pygame.display.list_modes( depth=0, flags=pygame.FULLSCREEN, display=0 ) # modes == -1 means any mode is supported. if modes != -1: self.assertEqual(len(modes[0]), 2) self.assertEqual(type(modes[0][0]), int) modes = pygame.display.list_modes() if modes != -1: self.assertEqual(len(modes[0]), 2) self.assertEqual(type(modes[0][0]), int) modes = pygame.display.list_modes( depth=0, flags=0, display=0 ) if modes != -1: self.assertEqual(len(modes[0]), 2) self.assertEqual(type(modes[0][0]), int)
Example #20
Source File: display_test.py From fxxkpython with GNU General Public License v3.0 | 6 votes |
def todo_test_iconify(self): # __doc__ (as of 2008-08-02) for pygame.display.iconify: # pygame.display.iconify(): return bool # iconify the display surface # # Request the window for the display surface be iconified or hidden. # Not all systems and displays support an iconified display. The # function will return True if successfull. # # When the display is iconified pygame.display.get_active() will # return False. The event queue should receive a ACTIVEEVENT event # when the window has been iconified. # self.fail()
Example #21
Source File: display_test.py From fxxkpython with GNU General Public License v3.0 | 6 votes |
def todo_test_gl_set_attribute(self): # __doc__ (as of 2008-08-02) for pygame.display.gl_set_attribute: # pygame.display.gl_set_attribute(flag, value): return None # request an opengl display attribute for the display mode # # When calling pygame.display.set_mode() with the pygame.OPENGL flag, # Pygame automatically handles setting the OpenGL attributes like # color and doublebuffering. OpenGL offers several other attributes # you may want control over. Pass one of these attributes as the flag, # and its appropriate value. This must be called before # pygame.display.set_mode() # # The OPENGL flags are; # GL_ALPHA_SIZE, GL_DEPTH_SIZE, GL_STENCIL_SIZE, GL_ACCUM_RED_SIZE, # GL_ACCUM_GREEN_SIZE, GL_ACCUM_BLUE_SIZE, GL_ACCUM_ALPHA_SIZE, # GL_MULTISAMPLEBUFFERS, GL_MULTISAMPLESAMPLES, GL_STEREO self.fail()
Example #22
Source File: display_test.py From fxxkpython with GNU General Public License v3.0 | 6 votes |
def todo_test_get_wm_info(self): # __doc__ (as of 2008-08-02) for pygame.display.get_wm_info: # pygame.display.get_wm_info(): return dict # Get information about the current windowing system # # Creates a dictionary filled with string keys. The strings and values # are arbitrarily created by the system. Some systems may have no # information and an empty dictionary will be returned. Most platforms # will return a "window" key with the value set to the system id for # the current display. # # New with pygame 1.7.1 self.fail()
Example #23
Source File: display_test.py From fxxkpython with GNU General Public License v3.0 | 6 votes |
def todo_test_get_driver(self): # __doc__ (as of 2008-08-02) for pygame.display.get_driver: # pygame.display.get_driver(): return name # get the name of the pygame display backend # # Pygame chooses one of many available display backends when it is # initialized. This returns the internal name used for the display # backend. This can be used to provide limited information about what # display capabilities might be accelerated. See the SDL_VIDEODRIVER # flags in pygame.display.set_mode() to see some of the common # options. # self.fail()
Example #24
Source File: display_test.py From fxxkpython with GNU General Public License v3.0 | 6 votes |
def todo_test_flip(self): # __doc__ (as of 2008-08-02) for pygame.display.flip: # pygame.display.flip(): return None # update the full display Surface to the screen # # This will update the contents of the entire display. If your display # mode is using the flags pygame.HWSURFACE and pygame.DOUBLEBUF, this # will wait for a vertical retrace and swap the surfaces. If you are # using a different type of display mode, it will simply update the # entire contents of the surface. # # When using an pygame.OPENGL display mode this will perform a gl buffer swap. self.fail()
Example #25
Source File: display_test.py From fxxkpython with GNU General Public License v3.0 | 6 votes |
def todo_test_set_gamma(self): # __doc__ (as of 2008-08-02) for pygame.display.set_gamma: # pygame.display.set_gamma(red, green=None, blue=None): return bool # change the hardware gamma ramps # # Set the red, green, and blue gamma values on the display hardware. # If the green and blue arguments are not passed, they will both be # the same as red. Not all systems and hardware support gamma ramps, # if the function succeeds it will return True. # # A gamma value of 1.0 creates a linear color table. Lower values will # darken the display and higher values will brighten. # self.fail()
Example #26
Source File: env_utils.py From tensorforce with Apache License 2.0 | 5 votes |
def display_text(display, font, text: [str], color=(255, 255, 255), origin=(0, 0), offset=(0, 2)): position = origin for line in text: if isinstance(line, dict): display.blit(font.render(line.get('text'), True, line.get('color', color)), position) else: display.blit(font.render(line, True, color), position) position = (position[0] + offset[0], position[1] + offset[1])
Example #27
Source File: display_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def todo_test_get_init(self): # __doc__ (as of 2008-08-02) for pygame.display.get_init: # pygame.display.get_init(): return bool # true if the display module is initialized # # Returns True if the pygame.display module is currently initialized. self.fail()
Example #28
Source File: display_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def todo_test_get_surface(self): # __doc__ (as of 2008-08-02) for pygame.display.get_surface: # pygame.display.get_surface(): return Surface # get a reference to the currently set display surface # # Return a reference to the currently set display Surface. If no # display mode has been set this will return None. # self.fail()
Example #29
Source File: env_utils.py From tensorforce with Apache License 2.0 | 5 votes |
def pygame_save(display, path: str, name: str = None): if name is None: name = 'image-' + str(datetime.datetime.now()) + '.jpg' thread = threading.Thread(target=lambda: pygame.image.save(display, os.path.join(path, name))) thread.start() # ------------------------------------------------------------------------------------------------- # -- CARLA # -------------------------------------------------------------------------------------------------
Example #30
Source File: display_test.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def todo_test_toggle_fullscreen(self): # __doc__ (as of 2008-08-02) for pygame.display.toggle_fullscreen: # pygame.display.toggle_fullscreen(): return bool # switch between fullscreen and windowed displays # # Switches the display window between windowed and fullscreen modes. # This function only works under the unix x11 video driver. For most # situations it is better to call pygame.display.set_mode() with new # display flags. # self.fail()