Skip to content

Xuepoo/vectomancy

Repository files navigation

Vectomancy

English | 简体中文

Vectomancy is a high-performance command-line interface tool designed to parse graphic files and convert them into mathematical parametric equations and rendering scripts. It enables users to transform raster images and vector graphics into mathematically beautiful waveforms.

Example Showcases

Original Image Rendered Output (Uncolored) Rendered Output (Colored)
Original Image Rendered Output Rendered Output
Original Image Rendered Output Rendered Output
Original Image Rendered Output Rendered Output
Original Image Rendered Output Rendered Output

Image Sources

Features

  • Multi-format Mathematical Equation Export: Supports Python (Matplotlib), HTML5 Canvas, and native JSON.
  • AST Size Optimization: Uses Zlib + Base64 encoding to store massive floating-point matrices. This keeps the generated files compact and prevents editors and rendering engines from freezing or crashing when parsing large files.
  • Controllable Smoothness and Rendering Modes:
    • --mode spline: Reconstructs shapes with precise Bezier curve interpolation, combined with the Chaikin algorithm for smoothing to eliminate jagged, staircase-like edges.
    • --mode fourier: Utilizes Fourier series (based on TSP path planning) to approximate a continuous, single-stroke curve of the image.

For a deeper dive into the mathematical algorithms (like Otsu Binarization, Ramer-Douglas-Peucker reduction, Moore Neighborhood Tracing, and FFT), please refer to the User Manual.

Installation

You will need the Rust toolchain installed to build from source.

git clone https://github.com/Xuepoo/vectomancy.git
cd vectomancy/vectomancy
cargo build --release

Run via Container (Docker/Podman):

# Build the container image locally
docker build -t vectomancy .
# Mount current directory and run
docker run --rm -v $(pwd):/data vectomancy run --output /data/output.json /data/input.svg

Precompiled binaries for Linux (Debian, Arch, RedHat, openSUSE, NixOS), Windows, and macOS are available in the GitHub Releases.

CLI Usage

Vectomancy is split into three main subcommands: image, text, and video.

1. Image Subcommand

Process raster (.png, .jpg) or vector (.svg) images:

vectomancy image [OPTIONS] <INPUTS...>

Key Options:

  • -o, --output <OUTPUT>: Path for the generated output file.
  • -f, --format <FORMAT>: Output format (python, html, json, desmos, png, jpg, webp).
  • -m, --mode <MODE>: Fitting mode (fourier, spline, chaikin).
  • -n, --terms <TERMS>: Number of Fourier terms.
  • -c, --chaikin-iters <ITERS>: Number of Chaikin smoothing iterations.
  • --color <true|false>: Enable color sampling.
  • --gpu <true|false>: Enable GPU acceleration (wgpu).
  • --threads <THREADS>: Number of CPU threads.

2. Text Subcommand

Extract outlines directly from a font file (.ttf or .otf) and fit to curves:

vectomancy text --font <FONT_PATH> --output <OUTPUT> <TEXT>

3. Video Subcommand

Process video frames sequentially to extract parametric motion formulas:

vectomancy video --output <OUTPUT> <INPUT_VIDEO>

Configuration loads from ~/.config/vectomancy/config.toml following the XDG Base Directory specification.

FAQ

Q: Will my VSCode freeze when opening the generated Python or HTML files? A: No. We automatically inject anti-scanning directives (like # pylint: disable=all or <!-- eslint-disable -->) at the beginning of the generated scripts. Via Zlib compression, file sizes stay small, which mainstream IDEs can open safely.

License

This project is licensed under the MIT License.

Packages

 
 
 

Contributors

Languages