PixelArray

Represents a 2D pixel buffer for image manipulation and blitting operations.

Constructor

Represents a 2D pixel buffer for image manipulation and blitting operations.

Properties


NameDescriptionType
alpha_modThe alpha modulation value for the pixel array.int
color_keyThe color key for transparency.Color
heightThe height of the pixel array.int
sizeThe size of the pixel array as a Vec2.Vec2
widthThe width of the pixel array.int

Methods


Blit

blit(
    pixel_array: PixelArray,
    pos: Vec2,
    anchor: Any = None,
    src: Any = None
) None

Blit (copy) another pixel array onto this pixel array at the specified position with anchor alignment.

Args

  • pixel_array : The source pixel array to blit from.
  • pos : The position to blit to.
  • anchor : The anchor point for positioning. Defaults to (0,0) TopLeft.
  • src : The source rectangle to blit from. Defaults to entire source pixel array.

Raises

  • RuntimeError : If the blit operation fails.

blit(
    pixel_array: PixelArray,
    dst: Rect,
    src: Any = None
) None

Blit (copy) another pixel array onto this pixel array with specified destination and source rectangles.

Args

  • pixel_array : The source pixel array to blit from.
  • dst : The destination rectangle on this pixel array.
  • src : The source rectangle to blit from. Defaults to entire source pixel array.

Raises

  • RuntimeError : If the blit operation fails.

Copy

copy() PixelArray

Create a copy of this pixel array.

Returns

PixelArray : A new PixelArray that is an exact copy of this one.

Raises

  • RuntimeError : If pixel array copying fails.

Fill

fill(color: Color) None

Fill the entire pixel array with a solid color.

Args

  • color : The color to fill the pixel array with.

Get At

get_at(coord: Vec2) Color

Get the color of a pixel at the specified coordinates.

Args

  • coord : The coordinates of the pixel as (x, y).

Returns

Color : The color of the pixel at the specified coordinates.

Raises

  • IndexError : If coordinates are outside the pixel array bounds.

Get Rect

get_rect() Rect

Get a rectangle representing the pixel array bounds.

Returns

Rect : A rectangle with position (0, 0) and the pixel array's dimensions.

Scroll

scroll(
    dx: SupportsInt,
    dy: SupportsInt,
    scroll_mode: ScrollMode
) None

Scroll the pixel array's contents by the specified offset.

Args

  • dx : Horizontal scroll offset in pixels.
  • dy : Vertical scroll offset in pixels.
  • scroll_mode : Behavior for pixels scrolled off the edge.
  • - REPEAT : Wrap pixels around to the opposite edge.
  • - ERASE : Fill scrolled areas with transparent pixels.
  • - SMEAR : Extend edge pixels into scrolled areas.

Set At

set_at(coord: Vec2, color: Color) None

Set the color of a pixel at the specified coordinates.

Args

  • coord : The coordinates of the pixel as (x, y).
  • color : The color to set the pixel to.

Raises

  • IndexError : If coordinates are outside the pixel array bounds.