Monorepo for Aesthetic.Computer
aesthetic.computer
1# KidLisp Embed Feature
2
3## Overview
4
5The new `embed` command and `$`-prefixed function syntax allows you to import and run cached KidLisp snippets in their own isolated painting buffers, then paste the results onto your main canvas.
6
7## Usage Examples
8
9### Basic Embedding
10
11```lisp
12; If you have saved code with cache code "abc123XY":
13
14; Method 1: Direct function call (auto-pastes at 0,0)
15($abc123XY)
16
17; Method 2: Direct function call with custom buffer size
18($abc123XY 128 128)
19
20; Method 3: Explicit embed syntax
21(embed $abc123XY)
22(embed $abc123XY 64 64)
23
24; Method 4: Embed and paste at specific coordinates
25(paste ($abc123XY 32 32) 100 100)
26```
27
28### Advanced Usage
29
30```lisp
31; Create a composition using multiple cached snippets
32(wipe "black")
33
34; Load a background pattern in a large buffer
35(paste ($background 256 256) 0 0)
36
37; Add smaller decorative elements
38(paste ($stars 64 64) 50 50)
39(paste ($moon 32 32) 200 20)
40
41; Overlay text or UI elements
42(paste ($ui 128 32) 64 200)
43```
44
45### Buffer Dimensions
46
47- Default: 256x256 pixels
48- Custom: `($code width height)`
49- Position args ignored: `($code x y width height)` (x,y ignored for API consistency)
50
51## How It Works
52
531. **Fetch**: Loads cached KidLisp source code from the network using the cache ID
542. **Isolate**: Creates a new painting buffer with specified dimensions
553. **Execute**: Runs the cached code in its own KidLisp context within the buffer
564. **Return**: Returns the painted buffer as a painting object
575. **Paste**: Auto-pastes at (0,0) for standalone calls, or can be manually positioned
58
59## Technical Details
60
61- Each embedded snippet runs in its own isolated KidLisp environment
62- The painting buffer has its own coordinate system starting at (0,0)
63- Network requests are cached to avoid repeated fetching
64- Supports all KidLisp graphics commands: `ink`, `box`, `line`, `circle`, etc.
65- Error handling: Failed embeds show red error buffer
66
67## Benefits
68
69- **Modularity**: Break complex art into reusable components
70- **Collaboration**: Share and remix cached code snippets
71- **Performance**: Render complex patterns in appropriately-sized buffers
72- **Composition**: Layer multiple elements at different scales and positions
73
74## Error Handling
75
76If a cached code fails to load or execute:
77- A red semi-transparent buffer is returned to indicate the error
78- Error details are logged to the console
79- The main program continues to execute normally