Background Color Renderer¶
A renderer that applies background colors to ASCII art.
This module provides functionality for rendering ASCII art with customizable background colors. It extends the BaseRenderer class to add background color capabilities while maintaining compatibility with other rendering features.
Example
Basic usage with a simple ASCII art image:
from bruhanimate import Screen, BackgroundColorRenderer
def demo(screen):
renderer = BackgroundColorRenderer(
screen=screen,
img=["Hello", "World"],
on_color_code=27 # Light blue background
)
renderer.run()
Screen.show(demo)
Note
The background color is applied using ANSI color codes (0-255). Common colors include:
27: Light blue
196: Red
46: Green
226: Yellow
- class bruhanimate.bruhrenderer.background_color_renderer.BackgroundColorRenderer(screen, img: List[str], 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, on_color_code: int = 27)[source]¶
Bases:
BaseRenderer
A renderer that applies background colors to ASCII art.
This renderer allows you to display ASCII art with a specified background color. It centers the image on the screen and maintains the original text appearance while adding the background color effect.
- Parameters:
screen – The screen object to render to
img (List[str]) – The ASCII art image as a list of strings
frames (int, optional) – Number of frames to render. Defaults to 100.
frame_time (float, optional) – Time between frames in seconds. Defaults to 0.1.
effect_type (EffectType, optional) – The type of effect to apply. Defaults to “static”.
background (str, optional) – Background character. Defaults to “ “.
transparent (bool, optional) – Whether to use transparency. Defaults to False.
collision (bool, optional) – Whether to enable collision detection. Defaults to False.
on_color_code (int, optional) – ANSI color code (0-255) for background. Defaults to 27.
- Raises:
Exception – If no color code is provided or if the color code is invalid
Example
Creating a renderer with a red background:
renderer = BackgroundColorRenderer( screen=screen, img=["▄▄▄", "███", "▀▀▀"], on_color_code=196, # Red background frame_time=0.05 )
- __init__(screen, img: List[str], 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, on_color_code: int = 27)[source]¶
Initialize the BackgroundColorRenderer with the specified parameters.
- render_img_frame(frame_number)[source]¶
Render a single frame of the image with the background color.
This method applies the background color to each character of the image while maintaining the original character appearance. The image is centered on the screen.
- Parameters:
frame_number (int) – The current frame number being rendered
Note
This method is called internally by the renderer’s main loop. It should not typically be called directly.
Example
Internal rendering process:
for frame in range(frames): renderer.render_img_frame(frame) renderer.display_frame()