Add composable ASCII art with per-cell effects and explicit effect loading
Implements ascii_fx_zone effect that allows applying arbitrary sexp effects to each character cell via cell_effect lambdas. Each cell is rendered as a small image that effects can operate on. Key changes: - New ascii_fx_zone effect with cell_effect parameter for per-cell transforms - Zone context (row, col, lum, sat, hue, etc.) available in cell_effect lambdas - Effects are now loaded explicitly from recipe declarations, not auto-loaded - Added effects_registry to plan for explicit effect dependency tracking - Updated effect definition syntax across all sexp effects - New run_staged.py for executing staged recipes - Example recipes demonstrating alternating rotation and blur/rgb_split patterns Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -150,6 +150,68 @@ def test_effect_execution():
|
||||
return passed, failed
|
||||
|
||||
|
||||
def test_ascii_fx_zone():
|
||||
"""Test ascii_fx_zone effect with zone expressions."""
|
||||
print("Testing ascii_fx_zone...")
|
||||
|
||||
interp = get_interpreter()
|
||||
|
||||
# Load the effect
|
||||
effects_dir = Path(__file__).parent / "effects"
|
||||
load_effects_dir(str(effects_dir))
|
||||
|
||||
# Create gradient test frame
|
||||
frame = np.zeros((120, 160, 3), dtype=np.uint8)
|
||||
for x in range(160):
|
||||
frame[:, x] = int(x / 160 * 255)
|
||||
frame = np.stack([frame[:,:,0]]*3, axis=2)
|
||||
|
||||
# Test 1: Basic without expressions
|
||||
result, _ = run_effect('ascii_fx_zone', frame, {'cols': 20}, {})
|
||||
assert result.shape == frame.shape
|
||||
print(" Basic run: OK")
|
||||
|
||||
# Test 2: With zone-lum expression
|
||||
expr = parse('(* zone-lum 180)')
|
||||
result, _ = run_effect('ascii_fx_zone', frame, {
|
||||
'cols': 20,
|
||||
'char_hue': expr
|
||||
}, {})
|
||||
assert result.shape == frame.shape
|
||||
print(" Zone-lum expression: OK")
|
||||
|
||||
# Test 3: With multiple expressions
|
||||
scale_expr = parse('(+ 0.5 (* zone-lum 0.5))')
|
||||
rot_expr = parse('(* zone-row-norm 30)')
|
||||
result, _ = run_effect('ascii_fx_zone', frame, {
|
||||
'cols': 20,
|
||||
'char_scale': scale_expr,
|
||||
'char_rotation': rot_expr
|
||||
}, {})
|
||||
assert result.shape == frame.shape
|
||||
print(" Multiple expressions: OK")
|
||||
|
||||
# Test 4: With numeric literals
|
||||
result, _ = run_effect('ascii_fx_zone', frame, {
|
||||
'cols': 20,
|
||||
'char_hue': 90,
|
||||
'char_scale': 1.2
|
||||
}, {})
|
||||
assert result.shape == frame.shape
|
||||
print(" Numeric literals: OK")
|
||||
|
||||
# Test 5: Zone position expressions
|
||||
col_expr = parse('(* zone-col-norm 360)')
|
||||
result, _ = run_effect('ascii_fx_zone', frame, {
|
||||
'cols': 20,
|
||||
'char_hue': col_expr
|
||||
}, {})
|
||||
assert result.shape == frame.shape
|
||||
print(" Zone position expression: OK")
|
||||
|
||||
print(" ascii_fx_zone OK")
|
||||
|
||||
|
||||
def main():
|
||||
print("=" * 60)
|
||||
print("S-Expression Effect Interpreter Tests")
|
||||
@@ -159,6 +221,7 @@ def main():
|
||||
test_interpreter_basics()
|
||||
test_primitives()
|
||||
test_effect_loading()
|
||||
test_ascii_fx_zone()
|
||||
passed, failed = test_effect_execution()
|
||||
|
||||
print("=" * 60)
|
||||
|
||||
Reference in New Issue
Block a user