vektra
v0.2.1
Published
Seed-Driven Deterministic Generative Graphics Library
Downloads
32
Maintainers
Readme
📖 About VEKTRA
VEKTRA is a high-performance, deterministic generative graphics library designed for creating complex, aesthetic, and fully reproducible visual art. Built from the ground up using Rust and WebAssembly, it guarantees that a specific numerical seed will produce the exact same visual output across any device or platform.
Whether you're generating SVG vector art for print, or decoding a binary draw-call stream for Canvas/WebGL rendering in the browser, VEKTRA provides a pristine, zero-dependency core architecture that is fast, safe, and highly extensible.
✨ Features
- 🔒 Absolute Determinism: Given the same seed, the exact same graphical output is guaranteed. No floating-point discrepancies.
- 🚀 High-Performance Core: Written in Rust for maximum execution speed and minimal memory footprint.
- 🕸️ WebAssembly Bridge: Seamlessly integrates into browser and Node/Bun environments via WASM.
- 📦 TypeScript Native: Strongly-typed API out of the box, with built-in binary decoders for frontend rendering.
- 🎨 Built-in Aesthetic Presets: Includes curated generative algorithms (
Void,Nebula,Monolith,Bloom). - 📐 Rich Primitive System: Generates complex patterns using mathematical primitives (Voronoi, Wave, Stipple, Subdivide, Flow, Scatter).
- 💾 Dual Output Formats:
- SVG: For crisp, scalable vector graphics.
- Binary DIS (Draw Instruction Stream): A highly optimized, compact binary format that can be easily parsed for high-FPS Canvas/WebGL rendering.
🏗️ Architecture & Structure
VEKTRA is structured as a monorepo containing the Rust core, WASM bridge, and TypeScript package.
vektra/
├── crates/
│ ├── vektra-core/ # The pure Rust generative engine (Zero Dependencies)
│ └── vektra-wasm/ # The WebAssembly bridge and memory management
└── packages/
└── vektra/ # The TypeScript/JavaScript wrapper package1. vektra-core
The brain of VEKTRA. It handles random number generation, spatial mathematics, the rendering pipeline, and the generation of the Draw Instruction Stream (DIS).
2. vektra-wasm
Provides the VektraSession FFI bridge. It takes the Rust core's logic and exposes it via wasm-bindgen so it can be called directly from JavaScript.
3. packages/vektra
The frontend library. It initializes the WASM module and provides a clean TypeScript class for generating graphics, alongside a robust DisDecoder for parsing the binary stream.
🚀 How to Use
Installation
You can install VEKTRA via NPM or Bun:
# Using NPM
npm install vektra
# Using Bun
bun add vektra
# Using Yarn
yarn add vektra(Note: To build VEKTRA from source or contribute to the Rust core, please see BUILD.md).
Quick Start Example (TypeScript)
Here is how to generate a deterministic SVG using VEKTRA in a Node or Bun environment:
import { VektraSession, initVektraSync } from 'vektra';
import * as fs from 'fs';
import * as path from 'path';
// 1. Initialize the WASM Module
const wasmPath = path.join(process.cwd(), 'wasm', 'vektra_wasm_bg.wasm');
const wasmBuffer = fs.readFileSync(wasmPath);
initVektraSync(wasmBuffer); // For browser, use await initVektra('/path/to/wasm')
// 2. Create a Session (Seed: 12345, Width: 800, Height: 600)
const session = new VektraSession(12345, 800, 600);
// 3. Set a Generative Preset
session.setPreset("Nebula");
// 4. Generate SVG Output
const svgString = session.generateSvg();
fs.writeFileSync("output.svg", svgString);
// 5. Generate Binary Stream (For Canvas/WebGL rendering)
const binaryData = session.generateBinary();
// 6. Decode Binary Stream
import { DisDecoder } from 'vektra';
const decoder = new DisDecoder(binaryData);
const drawInstructions = decoder.decode();
console.log(drawInstructions.slice(0, 5));🎨 Primitives & Presets
Available Primitives
VEKTRA's core utilizes a series of generative mathematical primitives:
- Voronoi: Cellular spatial partitioning.
- Wave: Sine/Cosine harmonic interference patterns.
- Stipple: Density-driven point placement.
- Subdivide: Recursive geometric splitting.
- Flow: Perlin/Simplex noise vector fields.
- Scatter: Controlled random distribution.
Curated Presets
Void: Minimalist, dark, and geometric.Nebula: Organic, flowing, and colorful.Monolith: Brutalist, structural, and sharp.Bloom: Soft, radiating, and complex.
👨💻 Developer & Credits
- Developer: Ryan Shelby
- GitHub: MdSagorMunshi
