ipygame.transform
pygame-compatible transform module.
def flip(surface: Surface, flip_x: bool, flip_y: bool) -> SurfaceFlip a Surface horizontally, vertically, or both.
def scale(surface: Surface, size, dest_surface: Surface | None = None) -> SurfaceResize to size (w, h) using nearest-neighbor.
scale_by
Section titled “scale_by”def scale_by(surface: Surface, factor, dest_surface: Surface | None = None) -> SurfaceResize by a scalar factor or (fx, fy) tuple.
rotate
Section titled “rotate”def rotate(surface: Surface, angle: float) -> SurfaceRotate the Surface counterclockwise by angle degrees.
rotozoom
Section titled “rotozoom”def rotozoom(surface: Surface, angle: float, scale_factor: float) -> SurfaceFiltered rotate and scale.
scale2x
Section titled “scale2x”def scale2x(surface: Surface, dest_surface: Surface | None = None) -> SurfaceDouble the size of the Surface.
smoothscale
Section titled “smoothscale”def smoothscale(surface: Surface, size, dest_surface: Surface | None = None) -> SurfaceResize with bilinear filtering.
smoothscale_by
Section titled “smoothscale_by”def smoothscale_by(surface: Surface, factor, dest_surface: Surface | None = None) -> SurfaceSmooth resize by a scalar factor or (fx, fy) tuple.
get_smoothscale_backend
Section titled “get_smoothscale_backend”def get_smoothscale_backend() -> strset_smoothscale_backend
Section titled “set_smoothscale_backend”def set_smoothscale_backend(backend: str) -> Nonedef chop(surface: Surface, rect) -> SurfaceRemove an interior rectangle; the remaining areas collapse together.
invert
Section titled “invert”def invert(surface: Surface, dest_surface: Surface | None = None) -> SurfaceInvert RGB values (alpha unchanged).
grayscale
Section titled “grayscale”def grayscale(surface: Surface, dest_surface: Surface | None = None) -> SurfaceConvert to grayscale.
solid_overlay
Section titled “solid_overlay”def solid_overlay(surface: Surface, color, dest_surface: Surface | None = None, keep_alpha: bool = False) -> SurfaceReplace all non-transparent pixels with a solid color.
average_color
Section titled “average_color”def average_color(surface: Surface, rect=None, consider_alpha: bool = False) -> tuple[int, int, int, int]Get the average RGBA color of a surface or sub-region.
average_surfaces
Section titled “average_surfaces”def average_surfaces(surfaces: Sequence[Surface], dest_surface: Surface | None = None, palette_colors: int = 1) -> SurfaceAverage the colors of multiple same-size surfaces.
threshold
Section titled “threshold”def threshold(dest_surface, surface: Surface, search_color, threshold_color=(0, 0, 0, 255), set_color=(0, 0, 0, 0), set_behavior: int = 1, other_surface: Surface | None = None, inverse: bool = False) -> intFind/set pixels within a color threshold. Returns count of matching pixels.
box_blur
Section titled “box_blur”def box_blur(surface: Surface, radius: int, repeat_edge_pixels: bool = True, dest_surface: Surface | None = None) -> SurfaceApply a box blur with the given pixel radius.
gaussian_blur
Section titled “gaussian_blur”def gaussian_blur(surface: Surface, radius: int, repeat_edge_pixels: bool = True, dest_surface: Surface | None = None) -> SurfaceApply a Gaussian blur with the given pixel radius.
laplacian
Section titled “laplacian”def laplacian(surface: Surface, dest_surface: Surface | None = None) -> SurfaceEdge-detection via Laplacian filter.
def hsl(surface: Surface, hue: float = 0, saturation: float = 0, lightness: float = 0, dest_surface: Surface | None = None) -> SurfaceAdjust HSL of a surface. Values are offsets.
pixelate
Section titled “pixelate”def pixelate(surface: Surface, pixel_size: int, dest_surface: Surface | None = None) -> SurfacePixelate a surface by downscaling and upscaling.