1.9 KiB
1.9 KiB
Go Fractals CLI - Design
Overview
A command-line tool that generates ASCII art fractals. Supports two fractal types with configurable output.
Usage
# Sierpinski triangle
fractals sierpinski --size 32 --depth 5
# Mandelbrot set
fractals mandelbrot --width 80 --height 24 --iterations 100
# Custom character
fractals sierpinski --size 16 --char '#'
# Help
fractals --help
fractals sierpinski --help
Commands
sierpinski
Generates a Sierpinski triangle using recursive subdivision.
Flags:
--size(default: 32) - Width of the triangle base in characters--depth(default: 5) - Recursion depth--char(default: '*') - Character to use for filled points
Output: Triangle printed to stdout, one line per row.
mandelbrot
Renders the Mandelbrot set as ASCII art. Maps iteration count to characters.
Flags:
--width(default: 80) - Output width in characters--height(default: 24) - Output height in characters--iterations(default: 100) - Maximum iterations for escape calculation--char(default: gradient) - Single character, or omit for gradient " .:-=+*#%@"
Output: Rectangle printed to stdout.
Architecture
cmd/
fractals/
main.go # Entry point, CLI setup
internal/
sierpinski/
sierpinski.go # Algorithm
sierpinski_test.go
mandelbrot/
mandelbrot.go # Algorithm
mandelbrot_test.go
cli/
root.go # Root command, help
sierpinski.go # Sierpinski subcommand
mandelbrot.go # Mandelbrot subcommand
Dependencies
- Go 1.21+
github.com/spf13/cobrafor CLI
Acceptance Criteria
fractals --helpshows usagefractals sierpinskioutputs a recognizable trianglefractals mandelbrotoutputs a recognizable Mandelbrot set--size,--width,--height,--depth,--iterationsflags work--charcustomizes output character- Invalid inputs produce clear error messages
- All tests pass