feat(effects): add entropy parameter to effect plugins

- Add entropy field to EffectConfig (0.0 = calm, 1.0 = chaotic)
- Provide compute_entropy() method in EffectContext for dynamic scoring
- Update Fade, Firehose, Glitch, Noise plugin defaults with entropy values
- Enables finer control: intensity (strength) vs entropy (randomness)

This separates deterministic effect strength from probabilistic chaos, allowing more expressive control in UI panel and presets.

Fixes #32
This commit is contained in:
2026-03-18 12:19:26 -07:00
parent cdcdb7b172
commit a95b24a246
5 changed files with 30 additions and 4 deletions

View File

@@ -44,6 +44,11 @@ class PartialUpdate:
@dataclass
class EffectContext:
"""Context passed to effect plugins during processing.
Contains terminal dimensions, camera state, frame info, and real-time sensor values.
"""
terminal_width: int
terminal_height: int
scroll_cam: int
@@ -56,6 +61,26 @@ class EffectContext:
items: list = field(default_factory=list)
_state: dict[str, Any] = field(default_factory=dict, repr=False)
def compute_entropy(self, effect_name: str, data: Any) -> float:
"""Compute entropy score for an effect based on its output.
Args:
effect_name: Name of the effect
data: Processed buffer or effect-specific data
Returns:
Entropy score 0.0-1.0 representing visual chaos
"""
# Default implementation: use effect name as seed for deterministic randomness
# Better implementations can analyze actual buffer content
import hashlib
data_str = str(data)[:100] if data else ""
hash_val = hashlib.md5(f"{effect_name}:{data_str}".encode()).hexdigest()
# Convert hash to float 0.0-1.0
entropy = int(hash_val[:8], 16) / 0xFFFFFFFF
return min(max(entropy, 0.0), 1.0)
def get_sensor_value(self, sensor_name: str) -> float | None:
"""Get a sensor value from context state.
@@ -80,6 +105,7 @@ class EffectContext:
class EffectConfig:
enabled: bool = True
intensity: float = 1.0
entropy: float = 0.0 # Visual chaos metric (0.0 = calm, 1.0 = chaotic)
params: dict[str, Any] = field(default_factory=dict)