Dual-Mode Circular Barcode Standard: Circle & LonCle v1.1.8
LonCle

The Open Standard for High-Density Circular Barcodes

CircleCode encodes arbitrary data into concentric circular arcs with dual visual styles: classic discrete pills (Circle) or continuous sweeping arcs (LonCle). Decode across full 360° orientations with subpixel computer vision directly in web browsers and mobile apps.

Zero installation required to test. All demos run client-side in your browser.

How CircleCode Works

CircleCode combines circular geometry with subpixel computer vision:

1

Concentric Arc Geometry

Data bits are distributed across concentric rings (4 to 14 rings). Each ring has a calculated radius, slot count, and fixed angular dash spacing ($0.35$ density).

2

Finder Spoke & Centroid

A reference dark finder spoke at $0^\circ$ and a dark center badge ($R=42$) anchor the barcode in 2D space, allowing 360° omnidirectional detection.

3

Perspective & Tilt Recovery

When photographed from an angle, circles distort into ellipses. The decoder computes spatial moments to normalize perspective tilt before reading bits.

4

Checksum & Error Recovery

Every payload includes a 16-bit header, length byte, and Modulo-256 checksum with aggressive 1–3 bit recovery for low-contrast or partially shadowed codes.

Formal Specification

Mathematical & Algorithmic Foundations

SPECIFICATION.md ↗ • ARCHITECTURE.md ↗ • API.md ↗

Mathematical formulations governing concentric ring distributions, slot allocation, 360° rotational alignment, subpixel spatial moments, and elliptical inverse coordinate transforms.

1. Concentric Radii Distribution ($r_i$)

A CircleCode barcode is normalized to an outer boundary disc of radius $R_{\text{disc}} = 190$ with a center branding badge of radius $r_{\text{badge}} = 42$. For $k$ rings ($k \in [4, 14]$), each ring $i \in [0, k-1]$ is mapped uniformly between $r_{\text{start}} = 55$ and $r_{\text{end}} = 157$:

$$r_i = 55 + (157 - 55) \times \frac{i}{k - 1}, \quad \text{for } i \in [0, k - 1]$$
• Standard 5-ring configuration: $r_0 = 55.0$, $r_1 = 80.5$, $r_2 = 106.0$, $r_3 = 131.5$, $r_4 = 157.0$.

2. Angular Slot Allocation ($n_i$) & Dash Width

To maintain equal physical bit density across expanding ring perimeters, the angular slot count $n_i$ grows proportionally to radius $r_i$ with constant density factor $d = 0.35$:

$$n_i = \max\left(12, \; \lfloor r_i \times 0.35 \rfloor\right), \qquad \Delta\theta_i = \frac{2\pi}{n_i}$$

Each slot subtends angle $\Delta\theta_i$. The physical dash stroke spans an angular active zone:

$$\theta_{\text{dash}} \in \left[j \Delta\theta_i + 0.28\Delta\theta_i, \;\; j \Delta\theta_i + 0.72\Delta\theta_i\right] \quad (\text{active width} = 0.44\Delta\theta_i)$$

3. 360° Rotational Alignment ($\theta_0$)

Slot $0$ across every ring is reserved as a continuous radial finder spoke. The decoder sweeps the entire $360^\circ$ circle in $1.8^\circ$ angular increments ($M = 200$ samples) to find rotation angle $\theta_0$ that minimizes aggregate luminance:

$$\theta_0 = \arg\min_{\theta \in [0, 2\pi)} \frac{1}{k} \sum_{i=0}^{k-1} \text{Luminance}(r_i, \theta)$$

4. Subpixel Centroid & Scale Estimation

The dark center badge ($R = 42$) is localized via annular contrast differential operator, followed by subpixel first-order spatial moments:

$$\text{Score} = \text{Mean}_{\text{out}}(1.10 \times r) - \text{Mean}_{\text{in}}(0.82 \times r)$$
$$c_x = \frac{1}{N}\sum_{p=1}^N x_p, \qquad c_y = \frac{1}{N}\sum_{p=1}^N y_p, \qquad r_{\text{refined}} = \sqrt{\frac{N}{\pi}}$$

5. Perspective Tilt Recovery (Inverse Coordinate Transformation)

Oblique camera angles compress circular geometries into ellipses along tilt angle $\phi$. The decoder normalizes perspective via 2D rotation and aspect ratio correction:

$$\begin{bmatrix} u \\ v \end{bmatrix} = \begin{bmatrix} \cos\phi & \sin\phi \\ -\sin\phi & \cos\phi \end{bmatrix} \begin{bmatrix} x_r \\ y_r \end{bmatrix}, \qquad v' = v \times \text{aspect}$$
$$\begin{bmatrix} x_r' \\ y_r' \end{bmatrix} = \begin{bmatrix} \cos\phi & -\sin\phi \\ \sin\phi & \cos\phi \end{bmatrix} \begin{bmatrix} u \\ v' \end{bmatrix}, \quad \text{where } \text{aspect} \in [0.84, 0.91]$$

6. Binary Framing, Checksum & Error Correction

The bitstream begins with a 16-bit big-endian length header $L$, followed by $8L$ data bits (UTF-8) and an 8-bit modulo-256 checksum:

$$L = \sum_{j=0}^{15} \text{Bits}[j] \cdot 2^{15 - j}, \qquad \text{chk} = \left(\sum_{q=0}^{L-1} \text{byte}_q\right) \pmod{256}$$

If $\Delta = (\text{chk}_{\text{expected}} - \text{chk}_{\text{actual}}) \pmod{256} = \pm 2^p$ matches a single bit discrepancy, CircleCode repairs the bit flip deterministically in $O(L)$ time.

Which Engine Should You Use?

Choose the right engine for your application's requirements:

Feature Pure JavaScript (@axphia/circlecode) Native Rust WASM (circlecode/wasm)
Best Use Case Web Image Uploads & Forms Real-Time Mobile Camera Scanning
Decoding Latency Device-dependent Device-dependent; benchmark locally
External Dependencies Zero (runs everywhere out-of-the-box) Requires circlecode_core_bg.wasm binary
CPU & Battery Impact Depends on device and workload Requires device measurements
Ideal Environment Drag & drop file upload, Node.js, static files Live smartphone camera feed, kiosks, PWAs

Quick Installation & Code Usage

Install via npm or include the standalone browser bundle directly:

# Install official v1.1.8 release via NPM npm install @axphia/circlecode@1.1.8

1. Generating Codes (Encoder)

Create circular barcodes in LonCle or Circle mode and render to SVG or HTML5 Canvas:

import { buildModel, renderToSVG, renderToCanvas } from '@axphia/circlecode'; // 1. Build circular code model const model = buildModel('https://circlecode.js.org', { rings: 7, density: 0.35 }); // 2. Export vector SVG in LonCle mode (connected sweeping arcs) const svg = renderToSVG(model, { style: 'loncle', dark: '#0071e3', light: '#ffffff', center: 'Pay' }); // 3. Or render to Canvas in Circle mode (classic discrete dashes) renderToCanvas(model, canvas.getContext('2d'), 400, { style: 'circle', dark: '#1d1d1f', light: '#8e8e93', center: 'MyBrand' });

2. Pure JS Scanner (Web Image Uploads & Drag-and-Drop)

Zero-dependency client-side decoding from user file uploads or canvas elements:

import { scanCanvas, scanImageData, CircleScanner } from '@axphia/circlecode'; // A) Scan directly from an uploaded image or HTMLCanvasElement const result = scanCanvas(myCanvas, { aggressive: false }); if (result.ok) { console.log('Decoded payload:', result.text); console.log('Rings detected:', result.rings, 'Rotation:', result.rot); }

3. Native WebAssembly Scanner

Rust WASM decoder; measure latency and resource use on the target device:

import init, { scan_frame_wasm } from 'https://cdn.jsdelivr.net/npm/@axphia/circlecode@1.1.8/wasm/circlecode_core.js'; // 1. Initialize WebAssembly core await init({ module_or_path: 'https://cdn.jsdelivr.net/npm/@axphia/circlecode@1.1.8/wasm/circlecode_core_bg.wasm' }); // 2. Decode an RGBA camera frame const result = scan_frame_wasm(rgbaPixelData, 400, 400, true); if (result.ok) { console.log('WASM instant lock:', result.text); }

4. Standalone Browser CDN

Include directly via script tag in vanilla HTML:

<script src="https://cdn.jsdelivr.net/npm/@axphia/circlecode@1.1.8/dist/circlecode.min.js"></script> <script> const { buildModel, renderToCanvas, scanCanvas } = window.CircleCode; </script>
Live Interactive Showcase

Teleport to Web Demos

Experience CircleCode live in action. Select a tool to teleport directly into the web-use-demo/ environment: