Exemplo n.º 1
0
def rainbow_effect_on_water(screen: pygame.surface.Surface,
                            water_tile: pygame.surface.Surface) -> None:
    orig_screen = screen.copy()
    water_color = pygame.transform.average_color(water_tile,
                                                 water_tile.get_rect())

    # Cycle through the rainbow colors
    clock = pygame.time.Clock()
    for i in range(4):
        for rainbow_color in rainbow_colors:
            try:
                pygame.transform.threshold(screen,
                                           orig_screen,
                                           search_color=water_color,
                                           threshold=pygame.Color(50, 50, 50),
                                           set_color=rainbow_color,
                                           inverse_set=True)
                clock.tick(5)
                pygame.display.flip()
            except:
                print('Color not found: ', rainbow_color, flush=True)

    # Restore original screen
    screen.blit(orig_screen, (0, 0))
    pygame.display.flip()
Exemplo n.º 2
0
def fade_to_color_and_back(screen: pygame.surface.Surface,
                           fade_color: pygame.Color) -> None:
    background_surface = screen.copy()
    fade_surface = pygame.surface.Surface(screen.get_size())
    fade_surface.fill(fade_color)
    fade_out(screen, background_surface, fade_surface)
    fade_out(screen, fade_surface, background_surface)
Exemplo n.º 3
0
    def add_surface_to_cache(self, surface: pygame.surface.Surface, string_id: str):
        """
        Adds a surface to the cache. There are two levels to the cache, the short term level
        just keeps hold of the surface until we have time to add it to the long term level.

        :param surface: The surface to add to the cache.
        :param string_id: An ID to store the surface under to make it easy to recall later.
        """
        self.cache_short_term_lookup[string_id] = [surface.copy(), 1]
Exemplo n.º 4
0
def flickering(screen: pygame.surface.Surface) -> None:
    background_surface = screen.copy()
    flicker_surface = pygame.surface.Surface(screen.get_size())
    flicker_surface.fill('white')
    flicker_surface.set_alpha(128)

    clock = pygame.time.Clock()
    for flicker_times in range(10):
        screen.blit(flicker_surface, (0, 0))
        clock.tick(30)
        pygame.display.flip()

        screen.blit(background_surface, (0, 0))
        clock.tick(30)
        pygame.display.flip()
Exemplo n.º 5
0
def premul_alpha_surface(
        surface: pygame.surface.Surface) -> pygame.surface.Surface:
    """
    Perform a pre-multiply alpha operation on a pygame surface's colours.
    """
    surf_copy = surface.copy()
    surf_copy.fill(pygame.Color('#FFFFFF00'),
                   special_flags=pygame.BLEND_RGB_MAX)
    manipulate_surf = pygame.surface.Surface(surf_copy.get_size(),
                                             flags=pygame.SRCALPHA,
                                             depth=32)
    # Can't be exactly transparent black or we trigger SDL1 'bug'
    manipulate_surf.fill(pygame.Color('#00000001'))
    manipulate_surf.blit(surf_copy, (0, 0))
    surface.blit(manipulate_surf, (0, 0), special_flags=pygame.BLEND_RGB_MULT)
    return surface