Skip to main content

Overview

The Monolex Tint System is implemented in both Rust (Production) and TypeScript/JavaScript (Lab/Tool). Both implementations follow the identical Gestalt Core-Flow pattern and are algorithmically equivalent.
┌─────────────────────────────────────────────────────────────────┐
│  DUAL IMPLEMENTATION ARCHITECTURE                               │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  ┌─────────────────────────┐    ┌──────────────────────────┐    │
│  │  Rust (Production)      │    │  TypeScript (Lab/Tool)   │    │
│  │  ─────────────────────  │    │  ────────────────────────│    │
│  │  theme_transform.rs     │    │  hue-warp-lab.html       │    │
│  │  theme_cache.rs         │    │  (embedded JS)           │    │
│  │  oklab.rs               │    │                          │    │
│  │                         │    │                          │    │
│  │  Purpose:               │    │  Purpose:                │    │
│  │  • Runtime transforms   │    │  • Interactive tuning    │    │
│  │  • LRU cache            │    │  • Visual verification   │    │
│  │  • High performance     │    │  • Parameter exploration │    │
│  └────────────┬────────────┘    └─────────────┬────────────┘    │
│               │                               │                 │
│               └───────────────┬───────────────┘                 │
│                               ▼                                 │
│                   ┌───────────────────────┐                     │
│                   │  IDENTICAL ALGORITHM  │                     │
│                   │  • Core-Flow pattern  │                     │
│                   │  • Same math          │                     │
│                   │  • Same parameters    │                     │
│                   └───────────────────────┘                     │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

Core Functions Comparison

warp_hue_compress (CORE Function)

Role: Hue compression inside the Caustic region - OkLCH Polar space operation
┌───────────────────────────────────────────────────────────────────────┐
│  warp_hue_compress() ALGORITHM                                        │
├───────────────────────────────────────────────────────────────────────┤
│                                                                       │
│  INPUTS: hue, pull_hue, strength, width (all in radians)              │
│                                                                       │
│  STEP 1: Early Exit                                                   │
│  if width == 0 OR strength == 0  →  return hue (no change)            │
│                                                                       │
│  STEP 2: Normalize Delta to [-π, π]                                   │
│  delta = hue - pull_hue                                               │
│  while delta > π:  delta -= 2π                                        │
│  while delta < -π: delta += 2π                                        │
│                                                                       │
│  STEP 3: Zone Decision                                                │
│  ┌────────────────────────────────────────────────────────────────┐   │
│  │  |delta| ≤ width  →  INSIDE ZONE (compress toward pull_hue)    │   │
│  │       ratio = |delta| / width                                  │   │
│  │       compressed = ratio × (1 - strength)                      │   │
│  │       result = pull_hue + sign(delta) × compressed × width     │   │
│  │                                                                │   │
│  │  |delta| > width  →  OUTSIDE ZONE (expand away from pull_hue)  │   │
│  │       Redistribute remaining hue space                         │   │
│  │       Maintain total coverage of [0, 2π]                       │   │
│  └────────────────────────────────────────────────────────────────┘   │
│                                                                       │
│  OUTPUT: warped_hue (normalized to [0, 2π])                           │
│                                                                       │
└───────────────────────────────────────────────────────────────────────┘
Rust Implementation:
fn warp_hue_compress(hue: f32, pull_hue: f32, strength: f32, width: f32) -> f32 {
    if width == 0.0 || strength == 0.0 {
        return hue;
    }

    let mut delta = hue - pull_hue;
    let two_pi = 2.0 * std::f32::consts::PI;
    while delta > std::f32::consts::PI {
        delta -= two_pi;
    }
    while delta < -std::f32::consts::PI {
        delta += two_pi;
    }

    let abs_d = delta.abs();

    if abs_d <= width {
        // Inside pull zone: compress
        let ratio = abs_d / width;
        let compressed = ratio * (1.0 - strength);
        let result = pull_hue + delta.signum() * compressed * width;
        result.rem_euclid(two_pi)
    } else {
        // Outside: expand
        let outside_range = std::f32::consts::PI - width;
        let new_outside_range = std::f32::consts::PI - width * (1.0 - strength);
        let outside_delta = abs_d - width;
        let expanded_delta =
            width * (1.0 - strength) + (outside_delta / outside_range) * new_outside_range;
        let result = pull_hue + delta.signum() * expanded_delta;
        result.rem_euclid(two_pi)
    }
}
TypeScript Implementation:
function warpHueCompress(hue, pullHue, strength, width) {
    if (width === 0 || strength === 0) return hue;

    let delta = hue - pullHue;
    const TWO_PI = 2 * Math.PI;
    while (delta > Math.PI) delta -= TWO_PI;
    while (delta < -Math.PI) delta += TWO_PI;

    const absD = Math.abs(delta);

    if (absD <= width) {
        // Inside pull zone: compress
        const ratio = absD / width;
        const compressed = ratio * (1 - strength);
        const result = pullHue + Math.sign(delta) * compressed * width;
        return ((result % TWO_PI) + TWO_PI) % TWO_PI;
    } else {
        // Outside: expand
        const outsideRange = Math.PI - width;
        const newOutsideRange = Math.PI - width * (1 - strength);
        const outsideDelta = absD - width;
        const expandedDelta =
            width * (1 - strength) + (outsideDelta / outsideRange) * newOutsideRange;
        const result = pullHue + Math.sign(delta) * expandedDelta;
        return ((result % TWO_PI) + TWO_PI) % TWO_PI;
    }
}
Gestalt Core Analysis:
┌─────────────────────────────────────────────────────────────────┐
│  warp_hue_compress = PURE CORE FUNCTION                         │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  Input: hue (radian) - Polar angle                              │
│  Output: warped_hue (radian) - Transformed Polar angle          │
│                                                                 │
│  Operation characteristics:                                     │
│  • Operates entirely in angle (Hue) space                       │
│  • Does not reference L, C                                      │
│  • Manipulates color identity (Hue) only                        │
│                                                                 │
│  → CORE: Polar space, identity definition                       │
│                                                                 │
│  Match: Rust === TypeScript                                     │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

fill_with_oklab_gradient (FLOW Function)

Role: OkLab linear interpolation inside Caustic region - Cartesian space operation
┌─────────────────────────────────────────────────────────────────┐
│  fill_with_oklab_gradient = PURE FLOW FUNCTION                  │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  Input: hue, L, C (Polar coordinates)                           │
│  Output: (L, a, b) (Cartesian coordinates)                      │
│                                                                 │
│  Key operation:                                                 │
│  • left_a = C * cos(left_hue)   ← Polar → Cartesian transform   │
│  • right_a = C * cos(right_hue)                                 │
│  • result_a = lerp(left_a, right_a, t)  ← FLOW: linear interp   │
│                                                                 │
│  Why FLOW?                                                      │
│  • Straight path in OkLab Cartesian space                       │
│  • Avoids Hue space discontinuities                             │
│  • Smooth gradient without muddy colors                         │
│                                                                 │
│  → FLOW: Cartesian space, derived color generation              │
│                                                                 │
│  Match: Rust === TypeScript                                     │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

apply_hue_warp (CORE + FLOW Hybrid)

Mode Comparison:
┌─────────────────────────────────────────────────────────────────┐
│  apply_hue_warp: MODE COMPARISON                                │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  Mode 0 (none):                                                 │
│  ─────────────                                                  │
│  • Bypass all processing                                        │
│  • Preserve original colors                                     │
│  • Neither CORE nor FLOW                                        │
│                                                                 │
│  Mode 1 (compress):                                             │
│  ────────────────                                               │
│  • warp_hue_compress() only                                     │
│  • Hue redistribution                                           │
│  • PURE CORE                                                    │
│                                                                 │
│  Mode 2 (compressGradient) - DEFAULT:                           │
│  ─────────────────────────────────────                          │
│  • Inside zone: fill_with_oklab_gradient()                      │
│  • Outside zone: warp_hue_compress()                            │
│  • FLOW inside + CORE outside                                   │
│  • Optimal harmony                                              │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

Parameter Mapping

Full Parameter Table

Rust (snake_case)TypeScript (camelCase)TypeGestalt
dark_anchor_huedarkAnchorHuef32CORE
dark_anchor_chromadarkAnchorChromaf32CORE
tint_huetintHuef32CORE
tint_strengthtintStrengthf32CORE
tint_chromatintChromaf32CORE
bg_hue_inheritbgHueInheritf32CORE
bg_chroma_boostbgChromaBoostf32CORE
text_hue_inherittextHueInheritf32CORE
border_hue_inheritborderHueInheritf32CORE
ansi_hue_inheritansiHueInheritf32CORE
bright_hue_inheritbrightHueInheritf32CORE
pull_complementarypullComplementaryf32CORE
pull_widthpullWidthf32CORE
pull_strengthpullStrengthf32CORE+FLOW
pull_modepullModeenumCORE+FLOW
bg_secondary_ratiobgSecondaryRatiof32FLOW
bg_tertiary_ratiobgTertiaryRatiof32FLOW
text_secondary_ratiotextSecondaryRatiof32FLOW
text_tertiary_ratiotextTertiaryRatiof32FLOW

Numeric Precision

Float Type Comparison

AspectRustTypeScript
Typef32 (32-bit)number (64-bit)
Significand23 bits52 bits
Max precision~7 digits~15 digits

Practical Impact

┌─────────────────────────────────────────────────────────────────┐
│  PRECISION IMPACT ON COLOR                                      │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  Output: 8-bit RGB per channel (0-255)                          │
│                                                                 │
│  Required precision: 1/256 ~ 0.0039                             │
│  f32 precision: ~1.2e-7                                         │
│  f64 precision: ~2.2e-16                                        │
│                                                                 │
│  Both far exceed requirements → NO VISIBLE DIFFERENCE           │
│                                                                 │
│  Edge case: Hue angle wrapping                                  │
│  • Rust: result.rem_euclid(two_pi)                              │
│  • JS:   ((result % TWO_PI) + TWO_PI) % TWO_PI                  │
│  • Both produce identical [0, 2pi) range                        │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

OkLab Implementation

Matrix Constants (Identical)

RGB to LMS (M1):
┌                                                     ┐
│ 0.4122214708  0.5363325363  0.0514459929            │
│ 0.2119034982  0.6806995451  0.1073969566            │
│ 0.0883024619  0.2817188376  0.6299787005            │
└                                                     ┘
LMS’ to OkLab (M2):
┌                                                     ┐
│ 0.2104542553  0.7936177850 -0.0040720468            │
│ 1.9779984951 -2.4285922050  0.4505937099            │
│ 0.0259040371  0.7827717662 -0.8086757660            │
└                                                     ┘
Both implementations use the same Bjorn Ottosson matrices for OkLab conversion.

Development Workflow

┌─────────────────────────────────────────────────────────────────┐
│  RUST <-> TYPESCRIPT DEVELOPMENT WORKFLOW                       │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  ┌────────────────────────────────────────────────────────┐     │
│  │  1. EXPERIMENT (TypeScript)                            │     │
│  │  ─────────────────────────                             │     │
│  │  hue-warp-lab.html                                     │     │
│  │  • Real-time parameter adjustment                      │     │
│  │  • Immediate visual feedback                           │     │
│  │  • Color Wheel, Palette preview                        │     │
│  └────────────────────────────────────────────────────────┘     │
│                       │                                         │
│                       ▼                                         │
│  ┌────────────────────────────────────────────────────────┐     │
│  │  2. VERIFY (TypeScript)                                │     │
│  │  ────────────────────                                  │     │
│  │  • Confirm desired color results                       │     │
│  │  • Test edge cases                                     │     │
│  │  • Copy theme definition object                        │     │
│  └────────────────────────────────────────────────────────┘     │
│                       │                                         │
│                       ▼                                         │
│  ┌────────────────────────────────────────────────────────┐     │
│  │  3. APPLY (Rust)                                       │     │
│  │  ──────────────                                        │     │
│  │  theme_cache.rs                                        │     │
│  │  • Update ThemeParams defaults                         │     │
│  │  • Or pass dynamically via Frontend invoke()           │     │
│  └────────────────────────────────────────────────────────┘     │
│                       │                                         │
│                       ▼                                         │
│  ┌────────────────────────────────────────────────────────┐     │
│  │  4. TEST (Rust)                                        │     │
│  │  ────────────                                          │     │
│  │  cargo test                                            │     │
│  │  • Unit tests for transforms                           │     │
│  │  • Integration with LRU cache                          │     │
│  │  • Actual terminal verification                        │     │
│  └────────────────────────────────────────────────────────┘     │
│                                                                 │
│  Since algorithms are identical:                                │
│  Success in TypeScript → Success in Rust                        │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

Verification Summary

┌─────────────────────────────────────────────────────────────────┐
│  IMPLEMENTATION VERIFICATION SUMMARY                            │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  Category                 Status   Notes                        │
│  ────────────────────────────────────────────────────────────   │
│  warp_hue_compress        OK       CORE function identical      │
│  fill_with_oklab_gradient OK       FLOW function identical      │
│  apply_hue_warp           OK       Mode selection identical     │
│  transform_truecolor      OK       7-step pipeline identical    │
│  OkLab conversions        OK       Same matrices                │
│  Parameter mapping        OK       All 20+ params mapped        │
│  Numeric precision        OK       Both exceed requirements     │
│  Gestalt Core-Flow        OK       Same pattern in both         │
│                                                                 │
│  ═══════════════════════════════════════════════════════════    │
│                                                                 │
│  VERDICT: Rust === TypeScript (Functionally Identical)          │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

THE CENTER

Language-Agnostic Pattern

The dual implementation proves that Gestalt Core-Flow is a language-independent mathematical pattern.
Connection to Core-Flow:
├── CORE operations: Same Polar angle math in any language
│   → atan2, cos, sin work identically everywhere
├── FLOW operations: Same Cartesian lerp in any language
│   → Linear algebra is universal
├── Development flexibility: Experiment in JS, deploy in Rust
│   → Rapid iteration without sacrificing performance
└── Mathematical foundation: Not framework-dependent
    → Can be ported to any platform (GPU shaders, WASM, etc.)
Key Insight: Gestalt Core-Flow is the mathematical language of color manipulation. Whether implemented in Rust, TypeScript, Python, or GPU shaders, the same pattern produces the same results because it is grounded in mathematics, not implementation details. This makes the Tint System:
  • Portable: Same algorithm works everywhere
  • Verifiable: Test in JS, confident in Rust
  • Maintainable: Single source of truth (the math)
  • Extensible: Add new platforms without redesign

Back to Tint System Overview

Return to the TrueColor Tint System architecture overview