Api Reference

Screen

class Asciinpy.screen.Screen(resolution: Resolutions, max_fps: int | None, forcestop: int | None, debug: bool, show_fps: bool, sysdout: bool, timer: bool)

A meta class for a screen object.

Attributes:
resolutions: Resolutions

The resolution of the screen.

max_fps: int

The fps cap for the screen.

aspect_ratio: int

The aspect ratio of the screen.

show_fps: bool

A boolean flag whether an FPS text box is shown on screen.

timer: int

A number in seconds that the screen is allowed to run in entirity, when reached exits gracefully.

sysdout: bool

A boolean flag on whether visualization of the rendering is enabled.

debug: bool

A boolean flag whether debug mode is turned on.

property frame: str

The current frame rendered.

property fps: int

The amount of frames rendered per the second passed.

property average_fps: float

The amount of frames rendered on average from start to present.

property tick: int

Internal ticks, from 0 to 25 for timing certain things.

blit(*objects: Blitable, **kwargs)

Simply calls the object’s internal blit method onto itself and does necessary records.

Parameters:

objects – Any number of models to be blitted onto screen.

refresh(log_frames=False)

Empties the current frame. If sysdout is enabled, it is printed onto the window.

Parameters:

log_frames (bool) – Whether to keep track of the amount of frames displayed throughout the session.

events()

Generally, the client does not capture user events this method must be called in order to gather them.

draw(point: List[int] | Tuple[int, int], char: str)

Paints a specific point on the cavas with the character.

class Asciinpy.screen.Window(*args, **kwargs)

An abstract representation of a window, the class handles the internal loops.

Subclasses of Window must implement Window.loop as it’s client loop. Whereas traditionally, it as a decorator.

Attributes:
resolutions: Resolutions

The resolution of the screen.

max_fps: int

The fps cap for the screen.

fov: int

The fov of the screen relevant for 3D rendering.

screen: Optional[Screen]

A screen object instantiated when run.

enable_debug(mode: Literal['k', 'c'] | None = None, origin_depth: int | None = None)

Enables debug mode for developers. Defaults to debug mode k.

Modes:

k - Executes the application until interrupted but remains open c - Executes the application until interrupted then closes

Offloads program onto a subprocess on an external Terminal with the given mode.

loop(screen: Screen | None = None, forcestop: int | None = None) Callable[[Callable[[Screen], None]], Callable[[Screen], None]]

Registers the client loop under loop of window class. This consenquentially limits the decorator to be re-used.

Returns:

(Callable[[Screen], None]) The wrapped function.

replay(frames: List[str], fps: int = 1)

Replays a given list of frames with the specified fps limit.

Parameters:
  • frames (int) – A list of frames to play.

  • fps – The FPS at which the replay is rendered. It is defaulted to 1.

set_fov(fov: float)

Sets the screen fov, this is only relevant if 3D objects are involved.

Parameters:

fov (float) – The FOV of the screen in radians. Defaults to 90 degrees or pi/2.

Values

class Asciinpy.values.Resolutions(value)

The preset resolutions class that contains static variable for usage and transformation.

Members:

Basic = (50, 25)

Medium = (60, 30)

Large = (100, 50)

HD = (352, 240)

static custom(dimensions: Tuple[int, int])

Instantiate a custom resolution and stores it as a enum member at Resolutions.Custom

Utilities

class Asciinpy.utils.Profiler(path: str)

Instance profiler wrapper for CProfiler.

Encapsulate the call with a context manager of the profiler and a file path to save the statistics returned.

with Profiler("file.txt"):
    window.run(show_fps=True)

You can also use it functionally for any reason.

pf = Profiler("file.txt")
pf.start()
window.run(show_fps=True)
pf.stop()
start()

Starts gathering statistics.

stop()

Stop gathering statistics.

utils.get_floor() List[int | float]

Takes in a 2d array of coordinates and returns the floor coordinate.

Use utils.get_floor_ceil() if you need both floor and ceiling

Returns:

(List[AnyInt]) The floor coordinate.

utils.get_ceil() List[int | float]

Takes in a 2d array of coordinates and returns the ceiling coordinate.

Use utils.get_floor_ceil() if you need both floor and ceiling

Returns:

(List[AnyInt]) The ceil coordinate.

utils.get_floor_ceil() Tuple[List[int | float], List[int | float]]

Takes in a 2d array of coordinates and returns a tuple of lists: This functional is not simply a macro to calling utils.get_floor() or utils.get_ceil() it specializes in getting both simultaneoulsy with a slightly better speed.

[Max_X_axis, Max_Y_axis], [Min_X_axis, Min_Y_axis]

Returns:

(List[AnyInt], List[AnyInt]) The floor and ceil coordinate.

utils.beautify(frame: List[str] | str) str

Maps an uncut frame into different pieces with newline characters to make it readable in a given context of dimension.

Parameters:
  • dimension (Tuple[int, int]) – The bordering dimension of this line frame.

  • frame (Union[str, List[str]:) – The frame to be converted from newline characters to a straight line.

Returns:

(str) The joined entire string frame.

utils.morph(end_string: str, consume: Literal['start', 'end'] = 'end', loop: bool = True) List[str]

Morphs one string onto another and return a string array of all the frames needed to be displayed.

Args:

initial_string (str): The starting frame of the resulting string. end_string (str): The ending frame of the resulting string. consume (Literal[“end”], Literal[“start”]): Direction of space consumption. loop (bool): Whether to make the morphing loop-friendly. Defaults to True.

Returns:

Tuple[List[str]]: All the frames needed to be displayed for the morphing process.

Line and Matrixes

class Asciinpy.geometry.Line(p1: Tuple[int, int], p2: Tuple[int, int])

A conceptual line class with simple properties. Basic properties are calculated and recalculated if and when they are needed.

Parameters:
  • p1 (List[int, int]) – Starting point

  • p2 (List[int, int]) – Endpoint

property points

The points that join p1 to p2.

Type:

List[Tuple[int, int]]

2D Definitors

class Asciinpy._2D.definitors.Collidable(occupancy: Set[Tuple[int | float, int | float]] = {})

An collidable object that exists in 2D space.

collides_with(model: Collidable) bool

Returns True if there are any intersections between the occupation of the collidable itself and the collidable being compared.

Parameters:

model (Collidable) – The collidable to be compared with.

Returns:

(bool) Whether if the current model is in collision with the opposite model.

class Asciinpy._2D.definitors.Collidable(occupancy: Set[Tuple[int | float, int | float]] = {})

Bases: object

An collidable object that exists in 2D space.

collides_with(model: Collidable) bool

Returns True if there are any intersections between the occupation of the collidable itself and the collidable being compared.

Parameters:

model (Collidable) – The collidable to be compared with.

Returns:

(bool) Whether if the current model is in collision with the opposite model.

class Asciinpy._2D.definitors.Mask(image: str, coordinate: Sequence[int | float] = [1, 1], color: Color | None = None)

Bases: Collidable, Blitable

A masks is a rasterizable object.

A mask determines a top left point in cartesian space by getting the top-most and left-most coordinates of the object regardless of it’s shape or form.

Masks rasterizes objects by constructing simply a mappings of pixels instead of shallow images for rasterization and therefore extending the operations you can do on Masks.

static get_pixmap(coordinate: Sequence[int | float], image: str) Dict[str, List[List[int | float] | Tuple[int | float, int | float]]]

Acquire a pixmap with relative coordinates of the image on the screen.

property midpoint: Tuple[int | float, int | float]

Midpoint of the object - otherwise can be taken as the median.

property occupancy: Set[Tuple[int, int]]

A set of all the coordinates that this structure occupies.

blit(screen: Screen)

Internal blitting method the blitable.

2D Objects

class Asciinpy._2D.objects.Tile(coordinate: Tuple[int, int], length: Tuple[int, int] | int, texture: str = '█', color: Color | None = None)

Bases: Plane

An plane for rectangle/square like objects.

class Asciinpy._2D.objects.Text(coordinate: Tuple[int, int], text: str)

Bases: Plane

A plane for rendering text.

class Asciinpy._2D.objects.Polygon(coordinates: List[Tuple[int, int]], texture: str = '█', color: Color | None = None)

Bases: Mask

A mask for n verticies constructed using the Line objects.

blit(screen: Screen)

Internal blitting method the blitable.

class Asciinpy._2D.objects.Square(coordinate: List[int] | Tuple[int, int], length: int, texture: str = '█', color: Color | None = None)

Bases: Mask

A mask for square/rectangle like objects with complex transformations.