PixelArray
Represents a 2D pixel buffer for image manipulation and blitting operations.
Constructor
-
PixelArray(size: Vec2) → PixelArray -
PixelArray(file_path: str) → PixelArray
Represents a 2D pixel buffer for image manipulation and blitting operations.
Properties
| Name | Description | Type |
|---|---|---|
alpha_mod | The alpha modulation value for the pixel array. | int |
color_key | The color key for transparency. | Color |
height | The height of the pixel array. | int |
size | The size of the pixel array as a Vec2. | Vec2 |
width | The width of the pixel array. | int |
Methods
Blit
blit(
pixel_array: PixelArray,
pos: Vec2,
anchor: Any = None,
src: Any = None
) → NoneBlit (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
) → NoneBlit (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() → PixelArrayCreate 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) → NoneFill the entire pixel array with a solid color.
Args
color: The color to fill the pixel array with.
Get At
get_at(coord: Vec2) → ColorGet 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() → RectGet 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
) → NoneScroll 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.