Snow 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.snow_effect.SnowEffect(buffer: Buffer, background: str, settings: SnowSettings = None)[source]

Bases: BaseEffect

A class to represent a snow effect.

__init__(buffer: Buffer, background: str, settings: SnowSettings = None)[source]

Initializes the SnowEffect.

Parameters:
  • buffer (Buffer) – Effect buffer to render changes to.

  • background (str) – Character or string used for the background of the effect.

  • settings (SnowSettings, optional) – Configuration for the snow effect. Defaults to None.

set_snow_intensity(intensity: float)[source]

Sets the probability of a new snowflake spawning per column per frame.

Parameters:

intensity (float) – Value between 0.01 and 1.0.

set_wind(wind: float)[source]

Sets the horizontal wind bias that influences snowflake drift.

Parameters:

wind (float) – Wind strength from -1.0 (hard left) to 1.0 (hard right).

set_show_info(show_info: bool)[source]

Toggles the snowflake debug info overlay.

Parameters:

show_info (bool) – Whether to show flake counts on screen.

update_collision(img_start_x: int, img_start_y: int, img_width: int, img_height: int, collision: bool, smart_transparent: bool, image_buffer: Buffer = None)[source]

Configures collision detection with an image.

Parameters:
  • img_start_x (int) – Image x position on screen.

  • img_start_y (int) – Image y position on screen.

  • img_width (int) – Width of the image.

  • img_height (int) – Height of the image.

  • collision (bool) – Whether to enable collision.

  • smart_transparent (bool) – Smart transparency flag.

  • image_buffer (Buffer, optional) – Buffer containing the image. Defaults to None.

generate_snowflake(x: int)[source]

Generates a new snowflake at the given x position with a wind-influenced drift bias.

Parameters:

x (int) – The x position to spawn the snowflake at.

can_stack(x: int, y: int) bool[source]

Checks whether accumulated snow at (x, y) is dense enough to stack onto the row above.

Parameters:
  • x (int) – Column to check.

  • y (int) – Row to check.

Returns:

True if snow should stack upward.

Return type:

bool

is_colliding(x: int, y: int) bool[source]

Checks whether a snowflake at (x, y) would collide with an image.

Parameters:
  • x (int) – Column to check.

  • y (int) – Row to check.

Returns:

True if the position is inside the image boundary.

Return type:

bool

handle_snowflake_landing(x: int, y: int)[source]

Accumulates snow at the landing position and updates the ground character.

Parameters:
  • x (int) – Column where the flake landed.

  • y (int) – Row where the flake landed.

add_info()[source]

Renders debug info (flake counts) at the top of the buffer.

render_frame(frame_number: int)[source]

Renders a single frame of the snow effect.

Parameters:

frame_number (int) – The current frame number.