How to use the pygame.display.flip function in pygame

To help you get started, we’ve selected a few pygame examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alex-petrenko / microtbs-rl / microtbs_rl / envs / micro_tbs.py View on Github external
ui_size = max(100, self.render_resolution // 3)
            screen_w = self.screen_size_world + ui_size
            screen_h = self.screen_size_world
            self.rendering_surface = pygame.Surface((screen_w, screen_h))
            self.font = pygame.font.SysFont(None, self.render_resolution // 32)
            self.ui_surface = pygame.Surface((ui_size, screen_h))
            if mode == 'human':
                self.screen = pygame.display.set_mode((screen_w, screen_h))

        self._render_game_world(self.rendering_surface, self.screen_scale)
        self._render_ui(self.rendering_surface, analytics)
        self._render_layout(self.rendering_surface)

        if mode == 'human':
            self.screen.blit(self.rendering_surface, (0, 0))
            pygame.display.flip()
        elif mode == 'rgb_array':
            return np.transpose(pygame.surfarray.array3d(self.rendering_surface), axes=[1, 0, 2])
        else:
            raise Exception('Unsupported rendering mode')
github PhotoFilmStrip / PFS / photofilmstrip / core / renderer / PyGameRenderer.py View on Github external
def ProcessFinalize(self, pilImg):
        if pilImg:
            pygameImg = self._PilToPyGame(pilImg)
#            self._screen.fill(self._black)
            self._screen.blit(pygameImg, (0, 0))
            pygame.display.flip()
        self._mainClock.tick(self._framerate)
        print self._mainClock.get_fps()
github McuMirror / WebSecurityEverywhere / script / unjailpi / data.py View on Github external
def show_popup(screen, text):
	font = pygame.font.Font(filepath(POPUP_FONT), POPUP_FONTSIZE)
	label = font.render(text, 1, (POPUP_FONTCOLOR))
	pygame.draw.rect(screen, POPUP_BGCOLOR, (LCD_WIDTH/2-label.get_width()/2-popup_border, LCD_HEIGHT/2-font.get_height()/2-popup_border, label.get_width()+popup_border*2,font.get_height()+popup_border*2,), 0)
	screen.blit(label, (LCD_WIDTH/2-label.get_width()/2, LCD_HEIGHT/2-font.get_height()/2))
	pygame.display.flip()
github venthur / pyff / src / FeedbackBase / VisualP300.py View on Github external
# Wait flash time
            self.current_tick += 1
            if self.current_tick == self.flash_duration:
                self.stim_state = self.STIM_END_FLASH
        elif state == self.STIM_START_FLASH:
            # Flash ON
            self.groups[self.flash_sequence[self.current_flash]].update()      # change state
            self.current_tick = 0
            if self.flash_duration > 1:
                self.stim_state = self.STIM_IN_FLASH
            else: self.stim_state = self.STIM_END_FLASH
            # We only need to paint if smth changes
            self.screen.blit(self.background,self.background_rect)
            self.all_elements_group.draw(self.screen)
            if len(self.deco)>0: self.deco_group.draw(self.screen)
            pygame.display.flip()
        elif state == self.STIM_END_FLASH:
            # Flash OFF
            self.groups[self.flash_sequence[self.current_flash]].update(-1)      # change state back
            self.current_tick += 1
            if self.current_tick+1 < self.soa:
                self.stim_state = self.STIM_BETWEEN_FLASHES
            else:
                self.stim_state = self.STIM_START_FLASH
            self.current_flash += 1
            if self.current_flash == self.nr_flashes:
                self.state_finished = True      # All flashes have been shown
                self.current_tick = 0           # Reset current tick
            self.screen.blit(self.background,self.background_rect)
            self.all_elements_group.draw(self.screen)
            if len(self.deco)>0: self.deco_group.draw(self.screen)
            pygame.display.flip()
github DrGFreeman / rps-cv / rpscv / gui.py View on Github external
if self.plScore > self.coScore:
            winner = 'PLAYER'
            color = self.GREEN
        else:
            winner = 'COMPUTER'
            color = self.RED

        winnerText = font.render('{} WINS!'.format(winner), color)
        self.blitTextAlignCenter(goZone, winnerText, (200, 110))

        # Blit goZone to main surface
        pos = (self.sWidth / 2 - 200, 175)
        self.surf.blit(goZone, pos)

        pg.display.flip()

        pg.time.wait(delay)

        if self.loop:
            self.reset()
        else:
            self.quit()
github cleebp / rta / src / draw / window.py View on Github external
def _draw_fps(self):
        self.clock.tick(24)
        fps = self.font.render(str(int(self.clock.get_fps())), True, WHITE)
        self.screen.blit(fps, (self.width - 50, 25))  # 25px down, 50px from right edge
        display.flip()
github Zulko / moviepy / moviepy / VideoClip.py View on Github external
def imdisplay(imarray, screen=None):
    """ splashes the given image array on the given pygame screen """
    a = pg.surfarray.make_surface(imarray.swapaxes(0, 1))
    if screen == None:
        screen = pg.display.set_mode(imarray.shape[:2][::-1])
    screen.blit(a, (0, 0))
    pg.display.flip()
github mbchang / dynamics / src / lua / convert_data.py View on Github external
Rect(obstacle[0][0], obstacle[0][1], \
                      abs(obstacle[1][0]-obstacle[0][0]), abs(obstacle[1][1]-obstacle[0][1])))

        # Drawing handled with exec since we don't know the number of particles in advance:
        for i in range(numberOfParticles):
            if (eval('particle' + str(i) + '.frame >=' + str(maxPath-1))):
                exec('particle' + str(i) + '.frame = ' + str(maxPath-1))
            if (eval('particle' + str(i) + ".fieldcolor == THECOLORS['green']") or eval('particle' + str(i) + ".fieldcolor == THECOLORS['hotpink1']")):
                exec('particle' + str(i) + '.draw(True)')
            else:
                exec('particle' + str(i) + '.draw(False)')

        pygame.draw.rect(screen, THECOLORS["black"], (3,1,width-1,height+1), 45)  # draw border

        # Drawing finished this iteration?  Update the screen
        pygame.display.flip()

        # make movie
        if movieFrame <= (len(observed_path)-1):
            imageName = basicString[0:len(basicString) - \
                            len(str(movieFrame+start_frame))] + \
                            str(movieFrame+start_frame)
            imagefile = movie_folder + "/" + movieName + '-' + imageName + ".png"
            pygame.image.save(screen, imagefile)
            movieFrame += 1
            if movieFrame == len(observed_path): done = True
        elif movieFrame > (len(observed_path)-1):
            done = True
github DanielSlater / PyGamePlayer / pygame_player.py View on Github external
def start(self):
        """
        Start playing the game. We will now start listening for screen updates calling our play and reward functions
        and returning our intercepted key presses
        """
        if self._playing:
            raise Exception("Already playing")

        pygame.display.flip = function_intercept(pygame.display.flip, self._on_screen_update)
        pygame.display.update = function_intercept(pygame.display.update, self._on_screen_update)
        pygame.event.get = function_intercept(pygame.event.get, self._on_event_get)
        pygame.time.Clock = function_intercept(pygame.time.Clock, self._on_time_clock)
        pygame.time.get_ticks = function_intercept(pygame.time.get_ticks, self.get_game_time_ms)
        # TODO: handle pygame.time.set_timer...

        self._playing = True
github uthcode / learntosolveit / games / pygame / pygame_tut_10.py View on Github external
width = 320
height = 200

screen = pygame.display.set_mode((width, height))

while running:
    event = pygame.event.poll()
    if event.type == pygame.QUIT:
        running  = 0
    elif event.type == pygame.MOUSEBUTTONDOWN and event.button == LEFT:
        print "You pressed the mouse button at (%d, %d)" % event.pos
    elif event.type == pygame.MOUSEBUTTONUP and event.button == LEFT:
        print "You release the mouse button at (%d, %d)" % event.pos

    screen.fill((0,0,0))
    pygame.display.flip()