PIXPY
pixpy (module)
Methods
pixpy.add_event_listener
Add a function that can intercept events. The function should return False if the event should not be propagated. Returnsid.
pixpy.all_events
Return the list of all pending events, and clear them.pixpy.allow_break
Allow Ctrl-C to break out of run looppixpy.blend_color
Blend two colors together.t should be between 0 and 1.
pixpy.blend_colors
Get a color from a color range. Works similar to bilinear filtering of an 1D texture.pixpy.get_clipboard
Get the current clipboard content as a string.pixpy.get_display
Get the current display, if any.pixpy.get_pointer
Get the xy coordinate of the mouse pointer (in screen space).pixpy.inside_polygon
Check if thepoint is inside the polygon formed by points.
pixpy.is_pressed
Returns True if the keyboard or mouse key is held down.pixpy.load_font
Load a TTF font.pixpy.load_png
Create an Image from a png file on disk.pixpy.open_display
open_display(width: int = -1, height: int = -1, full_screen: bool = False, visible: bool = True) -> Screen
pixpy.open_display
Opens a new window with the given size. This also initializes pix and is expected to have been called before any other pix calls. Subsequent calls to this method returns the same screen instance, since you can only have one active display in pix.pixpy.post_event
Post an event to pixpy, that will be returned by the next call toall_events().
pixpy.quit_loop
Make run_loop() return False. Thread safe.pixpy.remove_event_listener
Remove event listener via itsid.
pixpy.rgba
Combine four color float components into a 32-bit color.pixpy.run_every_frame
Add a function that should be run every frame. If the function returns false it will stop being called.pixpy.run_loop
Should be called first in your main rendering loop. Clears all pending events and all pressed keys. Returns True as long as the application is running (the user has not closed the window or quit in some other waypixpy.save_png
Save an Image to diskpixpy.set_clipboard
Set the clipboard content to the provided text.pixpy.set_keyboard_device
Set the device number that keyboard events will originate from. This can be used to handle multiple readline calls from consoles.pixpy.update_tweens
Manually update tweenspixpy.was_pressed
Returns True if the keyboard or mouse key was pressed this loop.run_loop() refreshes these states.
pixpy.was_released
Returns True if the keyboard or mouse key was pressed this loop.run_loop() refreshes these states.
Constants
pixpy.BLEND_ADD = 0x03020001
pixpy.BLEND_COPY = 0x00010000
pixpy.BLEND_MULTIPLY = 0x03060000
pixpy.BLEND_NORMAL = 0x03020303
Canvas
A Canvas is used for rendering. It is implemented by both Screen and Image.
Properties
Canvas.backface_culling
bool
If true, backward facing polygons will not be rendered.
Canvas.blend_mode
int
Set the blend mode. Normally one of the constants BLEND_ADD, BLEND_MULTIPLY or BLEND_NORMAL.
Canvas.draw_color
int
Set the draw color.
Canvas.line_width
float
Set the line with in fractional pixels.
Canvas.offset
Float2
The offset into a the source canvas this canvas was created from, if any.
Canvas.point_size
float
Set the point size in fractional pixels.
Canvas.scale
Float2
Canvas.size
Float2
The size of this canvas in pixels
Canvas.target_size
Float2
Methods
Canvas.begin_lines
Clear the last line point. The next call toline(p) or rounded_line(p, r) will start a new line sequence.
Canvas.circle
Draw an (outline) circleCanvas.clear
Clear the canvas using given color.Canvas.complex_polygon
Draw a complex filled polygon that can consist of holes.Canvas.copy
Make a copy of the self.Canvas.draw
draw(image: Image, top_left: Optional[Float2] = None, center: Optional[Float2] = None, size: Float2 = Float2.ZERO, rot: float = 0) -> None
Canvas.draw
Render a console.top_left and size are in pixels. If size is not given, it defaults to tile_size*grid_size.
To render a full screen console (scaling as needed):
console.render(screen, size=screen.size)
Canvas.filled_circle
Draw a filled circle.Canvas.filled_rect
Draw a filled rectangle.Canvas.flood_fill
Flood fill starting from the given position with the specified color.Canvas.flush
Flush pixel operationsCanvas.get_pointer
Get the xy coordinate of the mouse pointer (in canvas space).Canvas.line
Draw a line between start and end.Canvas.line
Draw a line from the end of the last line to the given position.Canvas.lines
Draw a line strip from all the given points.Canvas.log_to
Log draw commands to this fileCanvas.plot
Draw a point.Canvas.plot
Drawn points given by the array like objects. points should n*2 floats and colors should contain n unsigned ints.
Canvas.polygon
Draw a filled polygon by stringing together the given points. If convex istrue the polygon is rendered as a simple triangle fan, otherwise the polygon is split into triangles using the ear-clipping method.
Canvas.rect
Draw a rectangle.Canvas.rounded_line
Draw a line between start and end.Canvas.rounded_line
Draw a line from the end of the last line to the given position.Canvas.set_pixel
Write a pixel into the image.Canvas.to_image
Create a new image from this canvasConsole
A console is a 2D grid of tiles that can be rendered.
Properties
Console.autoscroll
bool
Should we scroll console upwards when writes pass bottom edge?
Console.bg_color
int
Background color.
Console.cursor_color
int
Cursor color.
Console.cursor_on
bool
Determine if the cursor should be visible.
Console.cursor_pos
Int2
The current location of the cursor. This will be used when calling write().
Console.fg_color
int
Foreground color.
Console.grid_size
Int2
Get number cols and rows.
Console.reading_line
bool
True if console is in read_line mode at the moment.
Console.size
Int2
Get size of consoles in pixels (tile_size * grid_size).
Console.tile_size
Int2
Get size of a single tile.
Console.wrap_lines
bool
Should we wrap when writing passing right edge?
Constructors
Console(cols: int, rows: int, font_file: Optional[os.PathLike] = None, tile_size: Float2 = Int2(-1, -1), font_size: int = -1)
cols*rows tiles.
font_file is the file name of a TTF font to use as backing. If no font is given, the built in Unscii font will be used.
tile_size sets the size in pixels of each tile. If not given, it will be derived from the size of a character in the font with the provided font_size.
cols*row tiles. Use the provided tile_set.
Methods
Console.cancel_line
Stop line edit mode.Console.clear
Clear the console.Console.clear_area
Clear the given rectangle, setting the current foreground and background colors.Console.colorize_section
Colorize the given area with the current foreground and background color, without changing the charactersConsole.get
Get tile at positionConsole.get_image_for
Get the image of a specific tile. Use to render the tile manually, or to copy another image into the tile;console.get_image_for(1024).copy_from(some_tile_image).
Console.get_tiles
Get all the tiles and colors as an array of ints. Format is:[tile0, fg0, bg0, tile1, fg1, bg1 ...] etc.
Console.put
Puttile at given position, optionally setting a specific foreground and/or background color
Console.read_line
Puts the console in line edit mode.A cursor will be shown and all text events will be captured by the console until Enter is pressed. At this point the entire line will be pushed as a TextEvent.
Console.set_color
Set the default colors used when putting/writing to the console.Console.set_device_no
Set the device number that will be reported for TextEvents from this console.Console.set_line
Change the edited line.Console.set_readline_callback
Sets a cllback that will be called when a line of text was entered by the user. Setting this will stop the normal TextEvent from being sent.Console.set_tile_images
Set images to use for a set of indexes, starting atstart_no.
Console.set_tiles
Set tiles from an array of ints.Console.write
Console.write
Write text to the console at the current cursor position and using the current colors. Will advance cursor position, and wrap if it passes the right border of the console.Float2
Represents an floating point coordinate or size. Mostly behaves like a normal float when used in arithmetic operations.
Properties
Float2.with_x0
Float2
Float2.with_y0
Float2
Float2.x
float
Float2.xx
Float2
Float2.y
float
Float2.yx
Float2
Float2.yy
Float2
Constructors
Methods
Float2.angle
Get the (counter-clockwise) angle between the vector and the X-axis (1,0).Float2.clamp
Separately clamp the x and y component between the corresponding components in the given arguments.Float2.clip
Compare the point against the bounding box defined by low/high. Returns (0,0) if point is inside the box, or a negative or positive distance to the edge if outside.Float2.cossin
Returns (cos(x), sin(y)).Float2.from_angle
Rotates the X-axis (1,0) aroundangle clockwise and returns the result.
Float2.inside_polygon
Check if thepoint is inside the polygon formed by points.
Float2.mag
Get magnitude (length) of vectorFloat2.mag2
Get the squared magnitudeFloat2.norm
Get the normalized vector.Float2.random
Returns Float2(rnd(x), rnd(y)) where rnd(n) returns a random number between 0 and n.Float2.toi
Convert aFloat2 to an Int2
Float2.tween_from
tween_from(value: Float2, secs: float = 1.0, ease: Callable[[float], float] = <built-in method of PyCapsule object at 0x104743880>) -> Float2
from to its current value in secs seconds.
Float2.tween_to
tween_to(value: Float2, secs: float = 1.0, ease: Callable[[float], float] = <built-in method of PyCapsule object at 0x104743740>) -> Float2
to in secs seconds.
Float2.tween_velocity
Move Vec2f with velocityspeed.
Font
Represents a TTF (Freetype) font that can be used to create text images.
Constructors
Create a font from a TTF file.Methods
Font.make_image
Create an image containing the given text.Font.text_size
Return the size (bounding rectangle) of the given text.Image
A (GPU Side) image, represented by a texture reference and 4 UV coordinates. Images works like arrays in the sense that it is cheap to create new views into images (using crop(), split() etc).
Properties
Image.backface_culling
bool
If true, backward facing polygons will not be rendered.
Image.blend_mode
int
Set the blend mode. Normally one of the constants BLEND_ADD, BLEND_MULTIPLY or BLEND_NORMAL.
Image.draw_color
int
Set the draw color.
Image.height
float
Image.line_width
float
Set the line with in fractional pixels.
Image.offset
Float2
The offset into a the source canvas this canvas was created from, if any.
Image.point_size
float
Set the point size in fractional pixels.
Image.pos
Float2
The position of this image in its texture. Will normally be (0, 0) unless this image was split or cropped from another image.
Image.scale
Float2
Image.size
Float2
Size of the image in (fractional) pixels.
Image.target_size
Float2
Image.width
float
Constructors
Create an empty image of the given size. Create an image from an array of 32-bit colors.Methods
Image.begin_lines
Clear the last line point. The next call toline(p) or rounded_line(p, r) will start a new line sequence.
Image.circle
Draw an (outline) circleImage.clear
Clear the canvas using given color.Image.complex_polygon
Draw a complex filled polygon that can consist of holes.Image.copy
Make a copy of the self.Image.copy_from
Render another image into this one.Image.copy_to
Render this image into another.Image.crop
Crop an image. Returns a view into the old image.Image.draw
draw(image: Image, top_left: Optional[Float2] = None, center: Optional[Float2] = None, size: Float2 = Float2.ZERO, rot: float = 0) -> None
Image.draw
Render a console.top_left and size are in pixels. If size is not given, it defaults to tile_size*grid_size.
To render a full screen console (scaling as needed):
console.render(screen, size=screen.size)
Image.filled_circle
Draw a filled circle.Image.filled_rect
Draw a filled rectangle.Image.flood_fill
Flood fill starting from the given position with the specified color.Image.flush
Flush pixel operationsImage.get_pointer
Get the xy coordinate of the mouse pointer (in canvas space).Image.line
Draw a line between start and end.Image.line
Draw a line from the end of the last line to the given position.Image.lines
Draw a line strip from all the given points.Image.log_to
Log draw commands to this fileImage.plot
Draw a point.Image.plot
Drawn points given by the array like objects. points should n*2 floats and colors should contain n unsigned ints.
Image.polygon
Draw a filled polygon by stringing together the given points. If convex istrue the polygon is rendered as a simple triangle fan, otherwise the polygon is split into triangles using the ear-clipping method.
Image.rect
Draw a rectangle.Image.rounded_line
Draw a line between start and end.Image.rounded_line
Draw a line from the end of the last line to the given position.Image.set_pixel
Write a pixel into the image.Image.set_texture_filter
Set whether the texture should apply linear filtering.Image.split
Splits the image into as many width * height images as possible, first going left to right, then top to bottom.Image.split
Split the image into exactly size.x * size.y images.Image.to_image
Create a new image from this canvasImage.update
Update the texture with a raw buffer that must fit the texture format.Int2
Represents an integer coordinate or size. Mostly behaves like a normal int when used in arithmetic operations.
Properties
Int2.with_x0
Int2
Int2.with_y0
Int2
Int2.x
int
Int2.xx
Int2
Int2.y
int
Int2.yx
Int2
Int2.yy
Int2
Constructors
Methods
Int2.clamp
Separately clamp the x and y component between the corresponding components in the given arguments.Int2.random
Returns Int2(rnd(x), rnd(y)) where rnd(n) returns a random number between 0 and n.Int2.tof
Convert anInt2 to a Float2
Screen
The main window. Currently there can be only one instance of this class.
Properties
Screen.backface_culling
bool
If true, backward facing polygons will not be rendered.
Screen.blend_mode
int
Set the blend mode. Normally one of the constants BLEND_ADD, BLEND_MULTIPLY or BLEND_NORMAL.
Screen.delta
float
Time in seconds for last frame.
Screen.draw_color
int
Set the draw color.
Screen.fps
int
Current FPS. Set to 0 to disable fixed FPS. Then use seconds or delta to sync your movement.
Screen.frame_counter
int
Screen.height
int
Screen.line_width
float
Set the line with in fractional pixels.
Screen.offset
Float2
The offset into a the source canvas this canvas was created from, if any.
Screen.point_size
float
Set the point size in fractional pixels.
Screen.refresh_rate
int
Actual refresh rate of current monitor.
Screen.scale
Float2
Screen.seconds
float
Total seconds elapsed since starting pix.
Screen.size
Float2
Size (in pixels) of screen.
Screen.target_size
Float2
Screen.visible
bool
Is the window visible?
Screen.width
int
Methods
Screen.begin_lines
Clear the last line point. The next call toline(p) or rounded_line(p, r) will start a new line sequence.
Screen.circle
Draw an (outline) circleScreen.clear
Clear the canvas using given color.Screen.complex_polygon
Draw a complex filled polygon that can consist of holes.Screen.copy
Make a copy of the self.Screen.crop
Crop the screen. Returns a screen reference that can be used to render to that part of the screen.Screen.draw
draw(image: Image, top_left: Optional[Float2] = None, center: Optional[Float2] = None, size: Float2 = Float2.ZERO, rot: float = 0) -> None
Screen.draw
Render a console.top_left and size are in pixels. If size is not given, it defaults to tile_size*grid_size.
To render a full screen console (scaling as needed):
console.render(screen, size=screen.size)
Screen.filled_circle
Draw a filled circle.Screen.filled_rect
Draw a filled rectangle.Screen.flood_fill
Flood fill starting from the given position with the specified color.Screen.flush
Flush pixel operationsScreen.get_pointer
Get the xy coordinate of the mouse pointer (in canvas space).Screen.line
Draw a line between start and end.Screen.line
Draw a line from the end of the last line to the given position.Screen.lines
Draw a line strip from all the given points.Screen.log_to
Log draw commands to this fileScreen.plot
Draw a point.Screen.plot
Drawn points given by the array like objects. points should n*2 floats and colors should contain n unsigned ints.
Screen.polygon
Draw a filled polygon by stringing together the given points. If convex istrue the polygon is rendered as a simple triangle fan, otherwise the polygon is split into triangles using the ear-clipping method.
Screen.rect
Draw a rectangle.Screen.rounded_line
Draw a line between start and end.Screen.rounded_line
Draw a line from the end of the last line to the given position.Screen.set_pixel
Write a pixel into the image.Screen.split
Split the screen into exactly size.x * size.y screen references that can be used as a render target for that part of the screen.Screen.swap
Synchronize with the frame rate of the display and swap buffers so what you have drawn becomes visible. This is normally the last thing you do in your render loop.Screen.swap_async
Async version of swap(). Returns an awaitable that completes when the swap is finished.Screen.to_image
Create a new image from this canvasTileSet
A tileset is a texture split up into tiles for rendering. It is used by the Console class but can also be used directly.
Properties
TileSet.tile_size
Int2
Constructors
TileSet(font_file: str, size: int = -1, tile_size: Int2 = Int2(-1, -1), distance: Int2 = Int2(0, 0))
Methods
TileSet.get_image_for
Get the image for a specific tile. Usecopy_to() on the image to redefine that tile with new graphics. Will allocate a new tile if necessary. Will throw an exception if there is no room.for the new tile in the tile texture.
TileSet.get_image_for
Get the image for a specific character. Usecopy_to() on the image to redefine that tile with new graphics. Will allocate a new tile if necessary. Will throw an exception if there is no room for the new tile in the tile texture.
TileSet.get_tileset_image
Get the entire tileset image. Typically used withsave_png() to check generated tileset.
TileSet.render_text
Render characters from the TileSet at givenpos and given size (defaults to tile_size).
TileSet.render_text
Render characters from the TileSet, each character using the next position frompoints, using the default tile size.
pixpy.event (module)
Click
Event sent when screen was clicked.
Properties
Click.buttons
int
Click.mods
int
Click.pos
Float2
Click.x
float
Click.y
float
Key
Event sent when key was pressed.
Properties
Key.device
int
Key.key
int
Key.mods
int
Move
Event sent when mouse was moved.
Properties
Move.buttons
int
Move.pos
Float2
Move.x
float
Move.y
float
Quit
Event sent when window/app wants to close.
Resize
Event sent when the window was resized
Properties
Resize.x
int
Resize.y
int
Text
Event sent when text was input into the window.
Properties
Text.device
int
Text.text
str
pixpy.color (module)
Constants
color.BLACK = 0x000000ff
color.BLUE = 0x0000aaff
color.BROWN = 0x664400ff
color.CYAN = 0xaaffedff
color.DARK_GREY = 0x333333ff
color.GREEN = 0x00cc54ff
color.GREY = 0x777777ff
color.LIGHT_BLUE = 0x0087ffff
color.LIGHT_GREEN = 0xaaff66ff
color.LIGHT_GREY = 0xbababaff
color.LIGHT_RED = 0xff7777ff
color.ORANGE = 0xdd8754ff
color.PURPLE = 0xcc44ccff
color.RED = 0x870000ff
color.TRANSP = 0x00000000
color.WHITE = 0xffffffff
color.YELLOW = 0xeded77ff
pixpy.key (module)
Constants
key.A1 = 0x00000005
key.B1 = 0x00000008
key.BACKSPACE = 0x00000008
key.DELETE = 0x0000000d
key.DOWN = 0x00000002
key.END = 0x0000000b
key.ENTER = 0x0000000a
key.ESCAPE = 0x0000001b
key.F1 = 0x00100000
key.F10 = 0x00100009
key.F11 = 0x0010000a
key.F12 = 0x0010000b
key.F2 = 0x00100001
key.F3 = 0x00100002
key.F4 = 0x00100003
key.F5 = 0x00100004
key.F6 = 0x00100005
key.F7 = 0x00100006
key.F8 = 0x00100007
key.F9 = 0x00100008
key.FIRE = 0x00000005
key.HOME = 0x0000000c
key.INSERT = 0x00000010
key.L1 = 0x0000000c
key.L2 = 0x0000000f
key.LCTRL = 0x00100011
key.LEFT = 0x00000003
key.LEFT_MOUSE = 0x00100020
key.LSHIFT = 0x00100010
key.MIDDLE_MOUSE = 0x00100022
key.MOD_ALT = 0x00000004
key.MOD_CTRL = 0x00000002
key.MOD_SHIFT = 0x00000001
key.MOUSE4 = 0x00100023
key.MOUSE5 = 0x00100024
key.PAGEDOWN = 0x0000000e
key.PAGEUP = 0x0000000f
key.R1 = 0x0000000b
key.R2 = 0x0000000e
key.RCTRL = 0x00100019
key.RIGHT = 0x00000001
key.RIGHT_MOUSE = 0x00100021
key.RSHIFT = 0x00100018
key.SELECT = 0x00000009
key.SPACE = 0x00000020
key.START = 0x0000000a
key.TAB = 0x00000009
key.UP = 0x00000004
key.X1 = 0x00000006
key.Y1 = 0x00000007