Transform - JakeTurner616/pygame-lua-bindings GitHub Wiki

Pygame transform functions

flip(surface, flip_x, flip_y)

Flip the surface horizontally, vertically, or both.

Parameters:

  • surface: The surface to flip.
  • flip_x: Whether to flip the surface horizontally.
  • flip_y: Whether to flip the surface vertically.

Returns: A new surface that is flipped.

scale(surface, width, height)

Scale the surface to the specified width and height.

Parameters:

  • surface: The surface to scale.
  • width: The new width of the surface.
  • height: The new height of the surface.

Returns: A new surface that is scaled.

scale_by(surface, factor_x, factor_y)

Scale the surface by the specified factors along the x and y axes.

Parameters:

  • surface: The surface to scale.
  • factor_x: The factor to scale by along the x-axis.
  • factor_y: The factor to scale by along the y-axis.

Returns: A new surface that is scaled by the specified factors.

rotate(surface, angle)

Rotate the surface by the specified angle.

Parameters:

  • surface: The surface to rotate.
  • angle: The angle to rotate the surface by.

Returns: A new surface that is rotated.

rotozoom(surface, angle, scale)

Rotate and scale the surface.

Parameters:

  • surface: The surface to rotate and scale.
  • angle: The angle to rotate the surface by.
  • scale: The scaling factor.

Returns: A new surface that is rotated and scaled.

scale2x(surface)

Scale the surface to twice its size.

Parameters:

  • surface: The surface to scale.

Returns: A new surface that is scaled to twice its size.

smoothscale(surface, width, height)

Smoothly scale the surface to the specified width and height.

Parameters:

  • surface: The surface to scale.
  • width: The new width of the surface.
  • height: The new height of the surface.

Returns: A new surface that is smoothly scaled.

smoothscale_by(surface, factor_x, factor_y)

Smoothly scale the surface by the specified factors along the x and y axes.

Parameters:

  • surface: The surface to scale.
  • factor_x: The factor to scale by along the x-axis.
  • factor_y: The factor to scale by along the y-axis.

Returns: A new surface that is smoothly scaled by the specified factors.

chop(surface, x, y, width, height)

Chop a rectangular area out of the surface.

Parameters:

  • surface: The surface to chop.
  • x: The x-coordinate of the top-left corner of the rectangle.
  • y: The y-coordinate of the top-left corner of the rectangle.
  • width: The width of the rectangle.
  • height: The height of the rectangle.

Returns: A new surface with the specified rectangular area chopped out.

laplacian(surface)

Apply the Laplacian filter to the surface.

Parameters:

  • surface: The surface to apply the filter to.

Returns: A new surface with the Laplacian filter applied.

average_color(surface, x=None, y=None, width=None, height=None, consider_alpha=False)

Calculate the average color of the surface or a specific rectangular area.

Parameters:

  • surface: The surface to calculate the average color of.
  • x: The x-coordinate of the top-left corner of the rectangle (optional).
  • y: The y-coordinate of the top-left corner of the rectangle (optional).
  • width: The width of the rectangle (optional).
  • height: The height of the rectangle (optional).
  • consider_alpha: Whether to consider the alpha channel in the calculation (optional).

Returns: The average color as a tuple.

grayscale(surface)

Convert the surface to grayscale.

Parameters:

  • surface: The surface to convert to grayscale.

Returns: A new surface that is converted to grayscale.

threshold(dest_surface, surface, r, g, b, a, tr, tg, tb, ta)

Apply a color threshold to the surface.

Parameters:

  • dest_surface: The destination surface.
  • surface: The source surface.
  • r: The red component of the color to search for.
  • g: The green component of the color to search for.
  • b: The blue component of the color to search for.
  • a: The alpha component of the color to search for.
  • tr: The red component of the threshold color.
  • tg: The green component of the threshold color.
  • tb: The blue component of the threshold color.
  • ta: The alpha component of the threshold color.

Returns: The number of pixels that were changed.