Skip to content

(Invert, HSL, blur, swirl)

Yoann Berenguer edited this page Apr 17, 2022 · 1 revision

INVERT

invert(object surface_) -> void

    """
    SHADER INVERT PIXELS
    
    :param surface_: pygame.surface; compatible 24 - 32 bit surfaces
    :return: void
   
    """

Invert all pixels of the display or a given texture
Compatible 24 - 32 bit with or without alpha layer

e.g:

invert(surface)

alt text alt text


HSL EFFECT

hsl_effect(surface_, shift_) -> void
    """
    ROTATE THE HUE OF THE GAME DISPLAY OR GIVEN TEXTURE
    
    :param surface_: pygame.Surface; Compatible 24 - 32 bit surfaces
    :param shift_: float; float value in range [-1.0 ... 1.0]
    :return: void 

    """

Compatible 24 - 32 bit with or without alpha layer

e.g:

hsl_effect(surface, 0.2)

alt text alt text alt text


BLUR

blur(object surface_, t_=1) -> void
    """
    APPLY A GAUSSIAN BLUR EFFECT TO THE GAME DISPLAY OR TO A GIVEN TEXTURE (KERNEL 5x5)

    :param surface_: pygame.Surface; compatible 24 - 32 bit surfaces
    :param t_      : integer; number of passes. must be > 0 (default is 1)
    :return: void 

    """

Gaussian kernel 5x5

|1   4   6   4  1|
|4  16  24  16  4|
|6  24  36  24  6|  x 1/256
|4  16  24  16  4|
|1  4    6   4  1|

This method is using convolution property and process the image in two passes. First the horizontal convolution and vertical convolution. Pixels convoluted outside the image edges will be set to adjacent edge value

Argument t_ is a new feature in version 1.0.3

Compatible 24 - 32 bit with or without alpha layer

e.g:

blur(surface)

blur(surface, t_=4)

alt text alt text alt text


WAVE EFFECT

wave(surface_, rad, size)
    """
    CREATE A WAVE EFFECT TO THE GAME DISPLAY OR TO A GIVEN SURFACE  
    
    :param surface_: pygame.Surface; pygame surface compatible 24 - 32 bit  
    :param rad     : float; angle in rad to rotate over time
    :param size    : int; Number of sub-surfaces
    :return        : void
    """

e.g:

wave(surface, 8 * math.pi/180.0 + frame_number, 5)

C:\>python demo_wave.py 

demo https://www.youtube.com/watch?v=XgLF2BWP0Rs#t=3m28 --> at 3 min 28 secs


SWIRL EFFECT

swirl(surface_, degrees)

    """
    SWIRL AN IMAGE (ANGLE APPROXIMATION METHOD)

    :param surface_: pygame.Surface, compatible 24 - 32 bit 
    :param degrees : float; angle in degrees 
    :return        : void 
    """

swirl2(surface_, degrees) 

    """
 
    SWIRL AN IMAGE (NO APPROXIMATION)
    :param surface_: pygame.Surface, compatible 24 - 32 bit 
    :param degrees : float; angle in degrees 
    :return        : void 
    """

Swirl algorithm is using a pre-defined table of cos and sin for the calculation to improve the performances

This effect can be used for scene transition

e.g:

swirl(surface, 1) swirl2(surface, frame)

alt text alt text alt text

demo https://www.youtube.com/watch?v=XgLF2BWP0Rs#t=3m12s --> at 3 min 12 secs