CLASS v1.8.0

PixelArray

pykraken.PixelArray

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

More about PixelArray

A PixelArray is a 2D array of pixels that can be manipulated, drawn on, and used as a source for texture creation or blitting to other PixelArrays. Supports pixel-level operations, color key transparency, and alpha blending.

Reference

PYTHON API

Constructor

method2 overloads
PixelArray(width: int, height: int)
PixelArray(file_path: str | PathLike)

Overloaded function.

  1. PixelArray(width: int, height: int)

Create a new PixelArray with the specified dimensions.

Args

  • width (int) — The width of the pixel array.
  • height (int) — The height of the pixel array.

Raises

  • RuntimeError — If pixel array creation fails.
  1. PixelArray(file_path: str | PathLike)

Create a PixelArray by loading an image from a file.

Args

  • file_path (str | PathLike[str]) — Path to the image file to load.

Raises

  • RuntimeError — If the file cannot be loaded or doesn't exist.

alpha_mod

property
alpha_mod: int

The alpha modulation value for the pixel array.

Controls the overall transparency of the pixel array. Values range from 0 (fully transparent) to 255 (fully opaque).

Returns

  • int — The current alpha modulation value [0-255].

Raises

  • RuntimeError — If getting the alpha value fails.

color_key

property
color_key: Color

The color key for transparency.

When set, pixels of this color will be treated as transparent during blitting operations. Used for simple transparency effects.

Returns

  • Color — The current color key.

Raises

  • RuntimeError — If getting the color key fails.

height

property
height: int

The height of the pixel array.

Returns

  • int — The pixel array height.

size

property
size: Vec2

The size of the pixel array as a Vec2.

Returns

  • Vec2 — The pixel array size as (width, height).

width

property
width: int

The width of the pixel array.

Returns

  • int — The pixel array width.

blit

method2 overloads
blit(self, pixel_array: PixelArray, pos: Vec2, anchor: Vec2 = Vec2(0.000000, 0.000000), src: Rect = Rect(x=0.000000, y=0.000000, w=0.000000, h=0.000000)) -> None
blit(self, pixel_array: PixelArray, dst: Rect, src: Rect = Rect(x=0.000000, y=0.000000, w=0.000000, h=0.000000)) -> None

Overloaded function.

  1. blit(self, pixel_array: PixelArray, pos: Vec2, anchor: Vec2 = Vec2(0.000000, 0.000000), src: Rect = Rect(x=0.000000, y=0.000000, w=0.000000, h=0.000000)) -> None

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

Args

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

Raises

  • RuntimeError — If the blit operation fails.
  1. blit(self, pixel_array: PixelArray, dst: Rect, src: Rect = Rect(x=0.000000, y=0.000000, w=0.000000, h=0.000000)) -> None

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

Args

  • pixel_array (PixelArray) — The source pixel array to blit from.
  • dst (Rect) — The destination rectangle on this pixel array.
  • src (Rect, optional) — The source rectangle to blit from. Defaults to entire source pixel array.

Raises

  • RuntimeError — If the blit operation fails.

copy

method
copy(self) -> 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

method
fill(self, color: Color) -> None

Fill the entire pixel array with a solid color.

Args

  • color (Color) — The color to fill the pixel array with.

get_at

method
get_at(self, x: int, y: int) -> Color

Get the color of a pixel at the specified coordinates.

Args

  • x (int) — The x-coordinate of the pixel.
  • y (int) — The y-coordinate of the pixel.

Returns

  • Color — The color of the pixel at the specified coordinates.

Raises

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

get_rect

method
get_rect(self) -> Rect

Get a rectangle representing the pixel array bounds.

Returns

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

scroll

method
scroll(self, dx: int, dy: int, scroll_mode: ScrollMode) -> None

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

Args

  • dx (int) — Horizontal scroll offset in pixels.
  • dy (int) — Vertical scroll offset in pixels.
  • scroll_mode (ScrollMode, optional) — 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

method
set_at(self, x: int, y: int, color: Color) -> None

Set the color of a pixel at the specified coordinates.

Args

  • x (int) — The x-coordinate of the pixel.
  • y (int) — The y-coordinate of the pixel.
  • color (Color) — The color to set the pixel to.

Raises

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

Find your next step

Start typing to search the manual.