@cbnsndwch/fractal-cli
v0.3.0
Published
CLI tool for generating fractal SVGs
Maintainers
Readme
@cbnsndwch/fractal-cli
Command-line interface for generating fractal SVG patterns.
Installation
# Install globally
npm install -g @cbnsndwch/fractal-cli
# Or use with npx (no installation required)
npx @cbnsndwch/fractal-cliUsage
Interactive Mode
Launch the interactive prompt to be guided through fractal generation:
fractal-svgThe interactive mode will:
- Prompt you to select a fractal type
- Ask for customization parameters
- Generate the SVG and save it to the output directory
Command Line Mode
Generate fractals directly with command-line arguments:
fractal-svg <type> [type-specific-args] [options]Fractal Types
Koch Curve
fractal-svg koch [options]Options:
--sides <n>- Number of sides (3 = snowflake, 4 = square, etc.) [default: 3]--inward- Make bumps point inward [default: false]
Examples:
# Classic Koch snowflake
fractal-svg koch --sides 3 --iter 4 --fill "#3b82f6"
# Hexagonal Koch with gradient
fractal-svg koch --sides 6 --iter 3 --gradient "#22c55e,#3b82f6"
# Square Koch with inward bumps
fractal-svg koch --sides 4 --inward --stroke black --strokeWidth 2Dragon Curve
fractal-svg dragon [options]Example:
fractal-svg dragon --iter 12 --stroke "#ff6b6b" --strokeWidth 1.5Hilbert Curve
fractal-svg hilbert [options]Example:
fractal-svg hilbert --iter 6 --stroke "#3b82f6" --strokeWidth 1Lévy C Curve
fractal-svg levy [options]Example:
fractal-svg levy --iter 14 --stroke "#22c55e" --strokeWidth 0.5Sierpinski Arrowhead
fractal-svg sierpinski [options]Example:
fractal-svg sierpinski --iter 10 --stroke "#f59e0b"Peano Curve
fractal-svg peano [options]Example:
fractal-svg peano --iter 4 --stroke "#8b5cf6"Gosper Curve
fractal-svg gosper [options]Example:
fractal-svg gosper --iter 4 --stroke "#ec4899"Carpet Fractal
fractal-svg carpet <dimension> [options]Arguments:
<dimension>- Fractal dimension (0, 2]. Classic Sierpinski is ~1.8928 (required)
Options:
--kMin <n>- Minimum subdivision factor [default: 2]--kMax <n>- Maximum subdivision factor [default: 9]--maxRects <n>- Max rectangles before stopping [default: 40000]
Examples:
# Classic Sierpinski carpet
fractal-svg carpet 1.8928 --iter 4
# Low-dimension carpet with gradient
fractal-svg carpet 0.63 --gradient "#f59e0b,#ef4444" --size 256Mandelbrot Set
fractal-svg mandelbrot [options]Options:
--resolution <n>- Grid resolution for contour tracing [default: 256]--centerX <n>- Center X in complex plane [default: -0.5]--centerY <n>- Center Y in complex plane [default: 0]--zoom <n>- View width in complex plane [default: 3]--maxIter <n>- Max escape iterations [default: 100]--threshold <n>- Contour threshold level [default: 2]
Examples:
# Default Mandelbrot
fractal-svg mandelbrot --gradient "#22c55e,#06b6d4,#3b82f6"
# Zoomed into an interesting region
fractal-svg mandelbrot --centerX -0.75 --zoom 0.5 --resolution 512Julia Set
fractal-svg julia [options]Options:
--juliaReal <n>- Real part of c constant [default: -0.7]--juliaImag <n>- Imaginary part of c constant [default: 0.27015]--resolution <n>- Grid resolution [default: 256]--centerX <n>- Center X in complex plane [default: 0]--centerY <n>- Center Y in complex plane [default: 0]--zoom <n>- View width [default: 3.5]
Famous Julia constants:
# Dendrite pattern
fractal-svg julia --juliaReal -0.7 --juliaImag 0.27015
# Spiral arms
fractal-svg julia --juliaReal -0.8 --juliaImag 0.156
# Rabbit-like
fractal-svg julia --juliaReal -0.4 --juliaImag 0.6
# Sea horse valley
fractal-svg julia --juliaReal 0.285 --juliaImag 0.01Common Options
These options work with all fractal types:
| Option | Description | Default |
| --------------------- | ---------------------------------- | ------------- |
| --out <file> | Output SVG filename | <type>.svg |
| --size <px> | Canvas size in pixels (min: 64) | 512 |
| --iter <n> | Iteration depth | type-specific |
| --bg <color> | Background color | transparent |
| --circleBg <color> | Circular background behind fractal | none |
| --fill <color> | Fill color | type-specific |
| --gradient <colors> | Comma-separated gradient stops | none |
| --gradientAngle <n> | Gradient angle in degrees | 135 |
| --stroke <color> | Stroke color | type-specific |
| --strokeWidth <n> | Stroke width | type-specific |
| --margin <px> | Margin around the fractal | 10 |
Advanced Examples
Multi-color Gradient
fractal-svg koch --sides 5 --iter 4 \
--gradient "#ff6b6b,#4ecdc4,#45b7d1" \
--gradientAngle 90 \
--size 1024Logo with Circular Background
fractal-svg dragon --iter 12 \
--circleBg "#1e1e1e" \
--stroke "#ffffff" \
--strokeWidth 2 \
--bg transparent \
--out logo.svgCustom Output Location
fractal-svg koch --sides 6 --iter 4 --out logos/my-logo.svgOutput
Generated SVG files are saved to the output/ directory by default. You can specify a custom path with the --out option.
output/
├── koch.svg
├── dragon.svg
├── carpet.svg
└── logos/
└── my-logo.svgIteration Limits
Each fractal type has recommended iteration limits to prevent memory exhaustion:
| Fractal | Default | Maximum | Complexity | | ---------- | ------- | ------- | ----------------- | | carpet | 4 | 8 | N^iter rectangles | | koch | 4 | 7 | 4^iter segments | | mandelbrot | 4 | 10 | resolution-based | | julia | 4 | 10 | resolution-based | | dragon | 12 | 18 | 2^iter segments | | hilbert | 6 | 9 | 4^iter segments | | levy | 14 | 18 | 2^iter segments | | sierpinski | 10 | 14 | 3^iter segments | | peano | 4 | 6 | 9^iter segments | | gosper | 4 | 6 | 7^iter segments |
Development
# Install dependencies
pnpm install
# Run in development mode
pnpm dev
# Build for production
pnpm build
# Type check
pnpm typesRelated Packages
- @cbnsndwch/fractal-generator - Core generation library
- @cbnsndwch/fractal-react - React components
License
MIT © cbnsndwch
