Base Renderer¶

Copyright 2023 Ethan Christensen

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

class bruhanimate.bruhrenderer.base_renderer.BaseRenderer(screen: Screen, frames: int = 100, frame_time: float = 0.1, effect_type: Literal['static', 'offset', 'noise', 'stars', 'plasma', 'gol', 'rain', 'matrix', 'drawlines', 'snow', 'twinkle', 'audio', 'chat', 'firework', 'fire', 'julia'] = 'static', background: str = ' ', transparent: bool = False, collision: bool = False)[source]¶

Bases: object

Base class for rendering effects on the screen.

__init__(screen: Screen, frames: int = 100, frame_time: float = 0.1, effect_type: Literal['static', 'offset', 'noise', 'stars', 'plasma', 'gol', 'rain', 'matrix', 'drawlines', 'snow', 'twinkle', 'audio', 'chat', 'firework', 'fire', 'julia'] = 'static', background: str = ' ', transparent: bool = False, collision: bool = False)[source]¶
validate_effect_type(effect_type: Literal['static', 'offset', 'noise', 'stars', 'plasma', 'gol', 'rain', 'matrix', 'drawlines', 'snow', 'twinkle', 'audio', 'chat', 'firework', 'fire', 'julia']) None[source]¶

Validates the provided effect type against a list of valid effect types.

Parameters:

effect_type (EffectType) – The effect type to be validated.

Raises:

InvalidEffectTypeError – If the provided effect type is not valid.

create_effect(effect_type: Literal['static', 'offset', 'noise', 'stars', 'plasma', 'gol', 'rain', 'matrix', 'drawlines', 'snow', 'twinkle', 'audio', 'chat', 'firework', 'fire', 'julia']) object[source]¶

Creates an instance of the specified effect type.

Parameters:

effect_type (EffectType) – The type of effect to be created.

Returns:

An instance of the specified effect type.

Raises:

ValueError – If the provided effect type is not recognized.

create_buffer() Buffer[source]¶

Creates a new buffer with the specified height and width.

Args:

Returns:

A newly created buffer object.

update_collision(collision: bool)[source]¶

Updates the effect’s collision state.

Parameters:

collision (bool) – The new collision state.

Returns:

None

update_smart_transparent(smart_transparent: bool)[source]¶

Updates the effect’s smart transparent state.

Parameters:

smart_transparent (bool) – The new smart transparent state.

Returns:

None

push_front_to_screen()[source]¶

Pushes the front buffer to the screen.

Returns:

None

render_exit()[source]¶

Renders an exit message on the screen.

Returns:

None

run(end_message=True)[source]¶

Runs the renderer for a specified number of frames or indefinitely.

Parameters:

end_message (bool) – Whether to render an exit message after finishing. Defaults to True.

Returns:

None

update_exit_stats(msg1=None, msg2=None, wipe=None, x_loc=None, y_loc=None, centered=False)[source]¶

Updates the exit message statistics. :param msg1: The first line of the exit message. Defaults to None. :type msg1: str :param msg2: The second line of the exit message. Defaults to None. :type msg2: str :param wipe: Whether to clear the screen before rendering the exit message. Defaults to False. :type wipe: bool :param x_loc: The x-coordinate of the exit message. Defaults to 0. :type x_loc: int :param y_loc: The y-coordinate of the exit message. Defaults to 1. :type y_loc: int :param centered: Whether to center the exit message horizontally. Defaults to True. :type centered: bool

Returns:

None

abstract render_frame()[source]¶

Renders a single frame of the effect.

Returns:

None