Thorpy

darken(color, factor=0.8, also_alpha=False)
Returns a darkened version of the color.
Mandatory arguments
color : 3-tuple or 4-tuple color.
Optionnal arguments
factor : (float) how much of the color we want to keep. E.g. 0.8 means we want to keep only 80% of the original color. also_alpha : (bool) specify whether you also want alpha to be affected.

enlighten(color, factor=1.2, min_value=20, also_alpha=False)
Returns a enlightened version of the color.
Mandatory arguments
color : 3-tuple or 4-tuple color.
Optionnal arguments
factor : (float) how much of the color we want to increase. E.g. 1.2 means we want to get 120% of the original color.
min_value : minimum value of color components in 255 bytes format. also_alpha : (bool) specify whether you also want alpha to be affected.

interpolate_2colors(c1, c2, k)
Returns a color that is in between c1 and c2, with a factor k. For instance, if k = 0.75, then the color will be made of 75% of c1 and 25% of c2. Note that c1 and c2 must be of the same length in RGB or RGBA format.
c1 : first color (3-tuple) or (4-tuple).
c2 : second color (3-tuple) or (4-tuple).
k : a float between 0. and 1.

interpolate_ncolors(colors, k)
Returns a color that is in between two colors among the colors passed, with a factor k. For instance, if k = 0.75, then the color will be an interpolation of the two surrounding colors (see interpolate_colors) at 75% of the list of colors.
colors : a list of RGB colors (3-tuple) or (4-tuple), but same length for each.
k : a float between 0. and 1.

opposite_color(c)
Return the conjugate of a color. For instance, if (255,0,127) is passed, then (0,255,127) is returned.

color_rect(gradient_color, size)
Return a colored rect.
gradient_color : an gradient color (see below).
size : 2-tuple beeing the size of the rect.
---
gradient color can be:
*3-tuple or 4-tuple specifying the RGB or RGBA value of the color (in this case, this is a simple color);
*Tuple or list of 3-tuples or 4-tuples, plus an optional string at the end indicating the orientation of the gradient : either 'h', 'v', 'r'(radial) or 'q'(square). In this case, a gradient of colors is defined. Alpha component is ignored for gradients.
When the orientation is 'q' (square), colors are on the form (topleft, topright, bottomleft, bottomright).
All examples below are valid:
(255,0,0) #red with alpha = 255
(255,0,0,90) #red with alpha = 90
( (255,0,0), (0,255,0) ) # gradient from red to green, with default orientation (vertical)
( (255,0,0), (0,0,255), (0,255,0), "h" ) #horizontal gradient from red to blue to green
( (255,0,0), (0,0,255), "h" ) #red to blue, horizontal
( (0,0,0), (0,255,0), "r") #black to green, radial
Tagged examples: color_gradient

get_black_white(surf, black=128, color_format="RGBA", convert=True)
Returns a monochrome version of the image, using PIL.
Mandatory arguments
surf : the image you want to blur (pygame.Surface).
Optionnal arguments
black : the gray level that is considered as black.
color_format : an accepted color format by PIL.

get_blurred(surf, radius=2, color_format="RGBA")
Returns a blurred version of the image, using PIL.
Mandatory arguments
surf : the image you want to blur (pygame.Surface).
Optionnal arguments
radius : radius of the blurry zone.
color_format : an accepted color format by PIL.

draw_gradient_along_path(surface, path, gradient)
Draw a 1 D color gradient along a path.
Mandatory arguments
surface : pygame Surface on which to draw.
path : sequence of (x,y) coordinates.
gradient : Thorpy gradient_color value.

draw_gradient_line(surface, col1, col2, p1, p2)
Draw a line between two points using a color gradient. CAUTION ! This is a very slow function to use only in initialization phases.
Mandatory arguments
surface : pygame Surface on which to draw.
col1 : from RGB color tuple.
col2 : to RGB color tuple.
p1 : from coordinate tuple.
p2 : to coordinate tuple.

change_color_on_img(img, color_source, color_target, colorkey=None)
Return a copy of the image where all color_source pixels have been converted to color_target pixels.
Mandatory arguments
img : the image you want to blur (pygame.Surface).
color_source : a color accepted by pygame.
color_target : a color accepted by pygame.
Optionnal arguments
colorkey : pixels color that must be transparent (can be None)
Tagged examples: imagebutton

change_color_on_img_ip(img, color_source, color_target, colorkey=None)
Modify the image so that all color_source pixels have been converted to color_target pixels.
Mandatory arguments
img : the image you want to blur (pygame.Surface).
color_source : a color accepted by pygame.
color_target : a color accepted by pygame.
Optionnal arguments
colorkey : pixels color that must be transparent (can be None)

extract_frames(src, out_folder=None, size_factor=(1., 1.))
Extract the frames of a GIF animation. Needs PIL.
Mandatory arguments
src : filename of the gif.
Optionnal arguments
out_folder : location where the frames are written to the disk. If None, frames are only kept in memory.
size_factor : (2-tuple of floats) relative size increase of each frame compared to the original.

spritesheet_frames(src, nx, ny, line_number, colorkey=None)
Return a list of pygame surfaces corresponding to a given line of the spritesheet.
Mandatory arguments
src : filename of the spritesheet.
nx : number of sprites along x-axis.
ny : number of sprites along y-axis.
line_number : line at which the frames are picked.

draw_arrow(screen, start_coord, end_coord, arrow_color, arrowhead_length=13, arrowhead_angle=math.pi/6)
Draws an arrow on the screen from start_coord to end_coord, pointing towards end_coord.

generate_oscillating_lights(surface, n, inflation=8, radius_amplitude=3, alpha_factor_base=0.1, alpha_factor_amplitude=0.3, color=(255,255,255), base_radius=1)
Prepares the frames of lights animation. This is a complex function that should be used as described in the tagged examples.

generate_static_light(surface, inflation=8,alpha=0.1,color=(255,255,255),radius=1)
Return an image that can be used as the light halo around an object. See the tagged examples for detailed use.

round_rect_aa(color, size, radius, force_radius=False, n_smooth=1.5)
Returns a round rectangle.
Mandatory arguments
color : an gradient color (see below).
size : (2-tuple) size of the rect.
radius : radius of the rounded corners in pixels. If the radius is in ]0;1[, then it is interpreted as the relative size of the radius as compared to the smallest side of the rect.
Optionnal arguments
force_radius : forces the radius value even if it is not compatible with the size of the rect.
n_smooth : number of times the frame is smoothed. Has an impact on performances.
---
gradient color can be:
*3-tuple or 4-tuple specifying the RGB or RGBA value of the color (in this case, this is a simple color);
*Tuple or list of 3-tuples or 4-tuples, plus an optional string at the end indicating the orientation of the gradient : either 'h', 'v' 'h' 'v', 'r'(radial) or 'q'(square). In this case, a gradient of colors is defined. Alpha component is ignored for gradients.
All examples below are valid:
(255,0,0) #red with alpha = 255
(255,0,0,90) #red with alpha = 90
( (255,0,0), (0,255,0) ) # gradient from red to green, with default orientation (vertical)
( (255,0,0), (0,0,255), (0,255,0), "h" ) #horizontal gradient from red to blue to green
( (255,0,0), (0,0,255), "h" ) #red to blue, horizontal
( (0,0,0), (0,255,0), "r") #black to green, radial

draw_pixel_border_ip(surface, border_color, color_empty=None)
This function is very slow and intended to be used once and for all before any loop, most suitably on small sprites. The function uses the defined colorkey as
color_empty by default.

extract_pixel_border(surface, border_color, color_empty=None)
This function is very slow and intended to be used once and for all before any loop, most suitably on small sprites. The function uses the defined colorkey as
color_empty by default.

illuminate_border_ip(surface, light_color, orientation, depth, intensity=0.5, color_empty=None)
This function is very slow and intended to be used once and for all before any loop, most suitably on small sprites. The function uses the defined colorkey as
color_empty by default.

scale_image_with_constraint(img, w, h, mode, smooth=True)
Return an image that is scaled so that it fits or fill, without deformation nor cropping, inside a rect of a given size.
Mandatory arguments
img : a Pygame Surface
w: final width
h: final height
Optionnal arguments
mode : (str) either 'fill' or 'fit'.
smooth : (bool) if True, uses pygame's smoothscale, otherwise uses pygame's scale function.

darken_every_color_ip(surface, factor=0.5, color_empty=None)
This function is very slow and intended to be used once and for all before any loop, most suitably on small sprites. If
color_empty is None, then it detects the default colorkey of the surface.