shadows.py

shadows.py – Lightweight real‑time shadow system for LunaEngine.

Provides:
- LightCaster: light source (position, colour, distance).
- ShadowCaster: object that casts shadows (circle/rect/polygon/texture).
- SCSManager: manager that renders shadows with fallback, optional gradient,
 optional blur, and debug overlays.

class LightCaster

Description

A light source that illuminates ShadowCasters and casts shadows.

Methods
def __init__(self: Any, position: Tuple[float, float], shape: Literal['point', 'circle', 'rect'], color_key: Union[ColorKeys, List[Tuple[int, int, int, float]], List[Color]], brightness: float = 8.0, distance: float = 16.0, size: Optional[Union[float, Tuple[float, float]]] = None) -> Any
No documentation
def _assert_color_key(self: Any, key: Any) -> Any
No documentation

class ShadowCaster

Description

An object that casts a shadow when illuminated by a LightCaster.

Attributes
x: Union[int, float] = None
y: Union[int, float] = None
shape: Literal['rect', 'circle', 'polygon', 'texture'] = None
color_key: ColorKeys = None
size: Union[Rect, Tuple[int, int], Tuple[float, float], None] = None
alpha_factor: float = None
shadow_depth: float = None
shadow_spread: float = None
Methods
def position(self: Any) -> Union[Tuple[int, int], Tuple[float, float]]
No documentation
def __init__(self: Any, position: Union[Vector2, Rect, Tuple[int, int], Tuple[float, float]], shape: Literal['rect', 'circle', 'polygon', 'texture'], color_key: Union[ColorKeys, List[Tuple[int, int, int, float]], List[Color]], size: Optional[Union[Rect, Tuple[int, int], Tuple[float, float]]] = None, alpha_factor: float = 0.6, shadow_depth: float = 1.0, shadow_spread: float = 1.0) -> Any
No documentation
def assert_color_key(self: Any, to_assert: Union[ColorKeys, List[Tuple[int, int, int, float]], List[Color]]) -> ColorKeys
No documentation
def compute_shadow_polygon(self: Any, lx: float, ly: float, max_dist: float) -> List[Tuple[float, float]]
Return the shadow polygon vertices for this caster.
The actual length is max_dist * self.shadow_depth.
The angular spread is multiplied by self.shadow_spread.

class SCSManager

Description

Manages all lights and shadow casters. Renders shadows with fallback,
optional gradient (per‑polygon), optional blur, and debug overlays.

Methods
def __init__(self: Any, engine: 'LunaEngine') -> Any
No documentation
def add_shadow(self: Any, position: Any, shape: Any, color_key: Any, size: Any = None, alpha_factor: float = 0.6, shadow_depth: float = 1.0, shadow_spread: float = 1.0) -> ShadowCaster
No documentation
def add_light(self: Any, position: Any, shape: Any, color_key: Any, brightness: float = 8.0, distance: float = 16.0, size: Any = None) -> LightCaster
No documentation
def _draw_caster(self: Any, caster: ShadowCaster, renderer: OpenGLRenderer, color: Color) -> Any
No documentation
def render(self: Any, renderer: OpenGLRenderer) -> Any
Renders all shadows in two passes:
 1. Fallback ambient shadow (low alpha) for every caster.
 2. Per‑light shadow polygons with either:
    - uniform alpha (if use_gradient is False)
    - linear gradient (if use_gradient is True)
If engine.debug_enabled is True, also draws debug overlays.
If shadow_blur > 0, shadows are rendered off‑screen, blurred, then composited.
def get_stats(self: Any) -> Any
Return simple statistics.

Global Functions

def pixel_to_centimeter(pixels: Union[int, float], dpi: int = 96) -> Union[int, float]

No documentation

def centimeter_to_pixel(centimeters: Union[int, float], dpi: int = 96) -> Union[int, float]

No documentation

def meter_to_pixel(meters: Union[int, float], dpi: int = 96) -> Union[int, float]

No documentation

Back to Graphics Module