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]¶
swap_buffers()[source]¶

Swaps the front and back buffers - the core of double buffering. This makes the completed back buffer visible and gives us a new back buffer to draw to.

Returns:

None

present_frame()[source]¶

Presents the current display buffer to the screen. Only updates screen positions that have actually changed for efficiency.

Returns:

None

clear_back_buffer()[source]¶

Clears the back buffer (current drawing buffer) for the next frame.

Returns:

None

render_to_back_buffer(frame: int)[source]¶

Renders the current frame to the back buffer. This is where all drawing operations happen before presentation.

Parameters:

frame (int) – The current frame number.

Returns:

None

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

render_exit_to_back_buffer()[source]¶

Renders the exit message to the back buffer following double buffering principles.

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

run(end_message=True)[source]¶

Runs the renderer using proper double buffering.

Parameters:

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

Returns:

None

abstract render_frame()[source]¶

Renders a single frame of the effect.

Returns:

None