Fractal SVG logo

Fractal SVG

A TypeScript library for generating beautiful, self-similar fractal patterns in SVG format with support for gradients, L-systems, and interactive CLI.

Fractal SVG is a TypeScript library for generating beautiful, self-similar fractal patterns in clean, scalable SVG format. From classic Sierpinski carpets to space-filling Hilbert curves, it supports 10 fractal types with multi-color gradients, circular backgrounds, and both interactive and CLI modes.

Features

  • 10 Fractal Types — Sierpinski carpet, Koch snowflake, Mandelbrot set, Julia sets, Dragon curve, Hilbert curve, Lévy C curve, Sierpinski arrowhead, Peano curve, and Gosper flowsnake
  • Vector Output — Clean, scalable SVG files with efficient single-path rendering for L-system fractals
  • Gradient Support — Multi-color linear gradients at any angle
  • Circular Backgrounds — Optional circular backdrop behind fractals, perfect for logo designs
  • Interactive & CLI Modes — User-friendly prompts or scriptable commands

Demo

Play with the interactive fractal generator

Quick Start

# Clone and install
git clone https://github.com/cbnsndwch/fractal-svg.git
cd fractal-svg && pnpm install

# Interactive mode
pnpm dev

# CLI examples
npx tsx src/index.ts koch --sides 3 --iter 4 --gradient "#ff6b6b,#4ecdc4"
npx tsx src/index.ts dragon --iter 12 --stroke "#ff6b6b" --strokeWidth 1.5
npx tsx src/index.ts mandelbrot --gradient "#22c55e,#06b6d4,#3b82f6"

Supported Fractal Types

TypeDescriptionRendering
carpetSierpinski-style grid carpetRectangles
kochKoch curve snowflake/polygonPath (filled)
mandelbrotMandelbrot set boundaryContour path
juliaJulia set with customizable constantContour path
dragonDragon curve (L-system)Path (stroked)
hilbertHilbert space-filling curvePath (stroked)
levyLévy C curve (feathery pattern)Path (stroked)
sierpinskiSierpinski arrowhead curvePath (stroked)
peanoPeano space-filling curvePath (stroked)
gosperGosper flowsnake curvePath (stroked)

Design Principles

All generated fractals follow these invariants:

  1. Square Output — Width and height are always equal
  2. Centered Fractals — All fractals are centered at (size/2, size/2)
  3. Circular Bounding — Fractals fit within an inscribed circle with radius size/2 - margin

For the full usage guide and API reference, visit the GitHub repository.

Tech Stack

  • TypeScript
  • Node.js
  • SVG
  • L-Systems
  • Fractals
  • CLI
  • pnpm

Latest Updates

View all