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.
- resolutions:
- 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.
- class Asciinpy.screen.Window(*args, **kwargs)¶
An abstract representation of a window, the class handles the internal loops.
Subclasses of Window must implement
Window.loopas 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.
- resolutions:
- 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.
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)
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.
- 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¶
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:
objectAn 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,BlitableA 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.
2D Objects¶
- class Asciinpy._2D.objects.Tile(coordinate: Tuple[int, int], length: Tuple[int, int] | int, texture: str = '█', color: Color | None = None)¶
Bases:
PlaneAn plane for rectangle/square like objects.
- class Asciinpy._2D.objects.Text(coordinate: Tuple[int, int], text: str)¶
Bases:
PlaneA plane for rendering text.