|
| 1 | +# mandel-lua |
| 2 | + |
| 3 | +Pure Lua Mandelbrot set renderer that generates high-quality BMP images and animated sequences. Works with both standard Lua and LuaJIT (LuaJIT provides 100x+ performance improvement). |
| 4 | + |
| 5 | +Always reference these instructions first and fallback to search or bash commands only when you encounter unexpected information that does not match the info here. |
| 6 | + |
| 7 | +## Working Effectively |
| 8 | + |
| 9 | +### Install Dependencies |
| 10 | +- Install Lua: `sudo apt install -y lua5.4 && sudo ln -sf /usr/bin/lua5.4 /usr/bin/lua` |
| 11 | +- Install LuaJIT (STRONGLY RECOMMENDED): `sudo apt install -y luajit` |
| 12 | +- Install ffmpeg for sequences/GIFs: `sudo apt install -y ffmpeg` |
| 13 | +- Verify installation: `lua -v && luajit -v && ffmpeg -version` |
| 14 | + |
| 15 | +### Build and Test |
| 16 | +- **No build process required** - pure interpreted Lua code |
| 17 | +- Run tests: `lua test.lua` - takes <1 second, should show "Tests passed: 13, failed: 0" |
| 18 | +- NEVER CANCEL: All commands complete quickly (<5 minutes max) |
| 19 | + |
| 20 | +### Run Single Image Generation |
| 21 | +- Basic usage: `lua main.lua` or `luajit main.lua` (default: 900x600 image) |
| 22 | +- With LuaJIT: `luajit main.lua -w 3000 -h 2000` - takes ~4 seconds. NEVER CANCEL. Set timeout to 10+ minutes for safety. |
| 23 | +- With standard Lua: `lua main.lua -w 900 -h 600` - takes ~37 seconds. NEVER CANCEL. Set timeout to 60+ minutes. |
| 24 | +- Help: `lua main.lua --help` |
| 25 | + |
| 26 | +### Run Sequence Generation |
| 27 | +- Basic sequence: `LUA_COMMAND=luajit luajit sequence.lua -s 10` |
| 28 | +- With GIF output: `LUA_COMMAND=luajit luajit sequence.lua -s 10 -g` |
| 29 | +- CRITICAL: Always set LUA_COMMAND=luajit for performance (100x faster than standard Lua) |
| 30 | +- NEVER CANCEL: Sequences can take 5-30 minutes depending on size and frame count. Set timeout to 60+ minutes. |
| 31 | +- Help: `lua sequence.lua --help` |
| 32 | + |
| 33 | +## Performance Expectations |
| 34 | +- **LuaJIT (RECOMMENDED)**: 900x600 image ~0.34s, 3000x2000 image ~3.8s |
| 35 | +- **Standard Lua**: 900x600 image ~37s, 3000x2000 image ~6+ minutes |
| 36 | +- **Test suite**: <1 second |
| 37 | +- **Small sequences (10 frames, 100x100)**: <1 second with LuaJIT |
| 38 | +- **Large sequences**: Scale linearly with frame count and image size |
| 39 | + |
| 40 | +## Validation Scenarios |
| 41 | +Always manually validate any changes by running these complete scenarios: |
| 42 | + |
| 43 | +1. **Basic single image**: `luajit main.lua -w 100 -h 100 -v` - should complete in <1s and create mandel-100x100.bmp |
| 44 | +2. **Color gradient**: `luajit main.lua -w 100 -h 100 --color1 FF0000 --color2 FFFF00 --color3 0000FF` - creates fire gradient |
| 45 | +3. **Interactive mode**: `lua main.lua -x -w 100 -h 100` then press 'q' to quit - should allow parameter adjustment |
| 46 | +4. **Test suite**: `lua test.lua` - all 13 tests must pass |
| 47 | +5. **Sequence generation**: `LUA_COMMAND=luajit luajit sequence.lua -w 100 -h 100 -s 3 -g` - creates frames/ directory and output.gif |
| 48 | + |
| 49 | +## Common Tasks |
| 50 | + |
| 51 | +### Available Commands |
| 52 | +```bash |
| 53 | +# Single image generation (default 900x600) |
| 54 | +lua main.lua [options] |
| 55 | +luajit main.lua [options] |
| 56 | + |
| 57 | +# Sequence generation (default 10 frames) |
| 58 | +lua sequence.lua [options] |
| 59 | +luajit sequence.lua [options] |
| 60 | + |
| 61 | +# Run test suite |
| 62 | +lua test.lua |
| 63 | +``` |
| 64 | + |
| 65 | +### Key Options for main.lua |
| 66 | +- `-w, --width <width>` - Image width [Default: 900] |
| 67 | +- `-h, --height <height>` - Image height [Default: 600] |
| 68 | +- `-r, --real <real>` - Real part of center [Default: -0.5] |
| 69 | +- `-i, --imag <imag>` - Imaginary part of center [Default: 0] |
| 70 | +- `-z, --zoom <zoom>` - Zoom level [Default: 0] |
| 71 | +- `-n, --iterations <iter>` - Max iterations [Default: 255] |
| 72 | +- `--color1/2/3 <hex>` - RGB gradient colors [Default: 000000,808080,FFFFFF] |
| 73 | +- `-x, --interactive` - Interactive mode for exploration |
| 74 | +- `-v, --verbose` - Show detailed progress |
| 75 | + |
| 76 | +### Key Options for sequence.lua |
| 77 | +- All main.lua options plus: |
| 78 | +- `-R/-I/-Z/-N` - Target values for sequence endpoint |
| 79 | +- `-s, --sequence <frames>` - Number of frames [Default: 10] |
| 80 | +- `--targetcolor1/2/3 <hex>` - Target gradient for color animation |
| 81 | +- `-g, --gif` - Generate GIF using ffmpeg |
| 82 | + |
| 83 | +### Repository Structure |
| 84 | +``` |
| 85 | +/home/runner/work/mandel-lua/mandel-lua/ |
| 86 | +├── main.lua # Single image generator |
| 87 | +├── sequence.lua # Sequence/animation generator |
| 88 | +├── test.lua # Test suite runner |
| 89 | +├── lib/ # Core libraries |
| 90 | +│ ├── complex.lua # Complex number operations |
| 91 | +│ ├── color.lua # Color gradient handling |
| 92 | +│ ├── cli-command.lua # Command line parsing |
| 93 | +│ ├── lua-bitmap.lua # BMP file generation |
| 94 | +│ └── *-tests.lua # Unit tests for each library |
| 95 | +├── docs/ # Documentation and sample images |
| 96 | +└── frames/ # Generated during sequence creation |
| 97 | +``` |
| 98 | + |
| 99 | +### Environment Variables |
| 100 | +- `LUA_COMMAND` - Controls which interpreter sequence.lua uses for child processes |
| 101 | +- Set to 'luajit' for optimal performance: `LUA_COMMAND=luajit luajit sequence.lua` |
| 102 | + |
| 103 | +### Output Files |
| 104 | +- Single images: `mandel-<width>x<height>.bmp` (or custom with `-o`) |
| 105 | +- Sequences: `frames/frame-NNNN.bmp` + `output.gif` (if `-g` specified) |
| 106 | +- Test output: Text summary to console |
| 107 | + |
| 108 | +## Error Handling |
| 109 | +- Invalid hex colors show clear error messages |
| 110 | +- Missing dependencies will cause command not found errors |
| 111 | +- Interactive mode accepts 'wasd+-erqv' keys plus 'q' to quit |
| 112 | +- All library functions have comprehensive error checking |
| 113 | + |
| 114 | +## Development Guidelines |
| 115 | +- Always run `lua test.lua` before committing changes |
| 116 | +- Test both single image and sequence generation after modifications |
| 117 | +- Use LuaJIT for performance testing and validation |
| 118 | +- Library modules are in `/lib/` - complex.lua, color.lua, cli-command.lua, lua-bitmap.lua |
| 119 | +- Each library has corresponding test file: `*-tests.lua` |
| 120 | + |
| 121 | +## Troubleshooting |
| 122 | +- If renders take too long: Use LuaJIT instead of standard Lua |
| 123 | +- If sequence.lua is slow: Set LUA_COMMAND=luajit environment variable |
| 124 | +- If GIFs don't generate: Ensure ffmpeg is installed and in PATH |
| 125 | +- If tests fail: Check Lua version compatibility (tested with Lua 5.4 and LuaJIT 2.1) |
| 126 | +- Missing frames directory: sequence.lua creates it automatically with `mkdir -p frames` |
0 commit comments