Base Effect

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.bruheffect.base_effect.BaseEffect(buffer: Buffer, background: str, *, seed: int | None = None)[source]

Bases: ABC

A simulation with a persistent private raster and explicit resource ownership.

Built-in simulations advance one step per update. Set updates_per_second on the Player to choose their speed independently of presentation FPS. Custom effects can use dt (seconds) for continuous motion instead.

__init__(buffer: Buffer, background: str, *, seed: int | None = None)[source]

Base class for all effects.

Parameters:
  • buffer (Buffer) – Effect buffer to push updates to.

  • background (str) – character or string to use for the background.

  • seed – Non-negative integer for independent Python and NumPy random streams. None uses fresh entropy. Global RNG state is untouched.

start() → None[source]

Acquire runtime resources. Construction must not open devices or threads.

Players and scenes call this before the first update and own cleanup for the duration of playback. Overrides should tolerate repeated calls.

stop() → None[source]

Release runtime resources; safe to call before start or more than once.

close() → None[source]

Release resources through stop(); safe before start and on repeats.

abstract update(dt: float) → None[source]

Advance simulation by one tick; dt is the tick duration in seconds.

resize(size: tuple[int, int]) → None[source]

Change the drawing viewport, retaining the original simulation raster.

Shrinking clips from the bottom/right; growing reveals the original raster again. Cells beyond it remain transparent to the owner. Random streams, resource handles and simulation coordinates are unchanged. Subclasses can override this typed hook to adapt simulation arrays and repaint the private raster at the current tick, then call super().resize. Built-in adapters use this contract; draw must still never advance time.

draw(buffer: Buffer) → None[source]

Copy the latest raster without advancing or sharing mutable cells.