How it works
InstaCalc (the game) · Engine Architecture · November 2026

How InstaCalc (the game) works

A 54 KB WebGL2 renderer (ic-3d.js) + symbolic CAS (ic-slim.mjs) where plain-text .ic equations compile directly into 3D meshes, combat rules, and WebAudio—with zero image or audio files in gameplay.

54 KB ic-3d.js WebGL2 renderer 19+ .ic declarative cartridges 448 CAS values doctested 145 KB shipped graphics layer
Gameplay & Pedagogy

Time to make math afraid of you

Calcy is a pocket calculator with boxing gloves who fights formula stacks on graph paper—where a stack stands is its x.

Stage 1 · Knowing WHAT Needs to Be Done (What InstaCalc (the game) & .ic Teach)

Deciding which operation (d/dx, √, ln, −1) to reach for—and encoding that strategic judgment as a rule while ic-slim.mjs handles the computation.

Stage 2 · Knowing HOW to Compute It Manually (When Needed)

Traditional drills force manual arithmetic first. Once you intuitively know what a derivative, root, or log does and when to use it, learning the by-hand steps is natural.

Calcy stands on graph paper between block stacks labelled x squared and minus 4. Dashed orange lines mark where a stack's value is zero, and a pencil curve shows its graph. Four cards sit at the bottom: square root, ln, d/dx and minus 1.
A real frame from the game. The pencil curve is the locked stack's graph; the dashed lines are its roots, where it pops for free.
How the game plays (4-step combat loop)

1. Read the Stack

Top block is f(x); bottom block is x (its position on the graph paper).

2. Pick an Operation

d/dx (front kick), ln (backflip), √ (uppercut), or −1 (jab).

3. Hit Zero = Pop!

Reduce the stack to 0—or lure it onto a root f(x) = 0 for a free pop.

4. Dodge Asymptotes

Dividing by 0 or taking ln of a negative triggers a backlash bomb.

The core idea

The paper is the plane

A stack's value is f(x), where x is its spot on the paper. So walking is a math decision, learned by playing: lure x² − 4 onto x = 2 and it pops on its own; bait 30/x toward the y-axis and it boils over like a bomb; push ln x left of zero and it turns ghostly. Nobody is asked to calculate anything. The cards are moves: √ is an uppercut, d/dx a front kick, ln a backflip kick, −1 a jab.

Try it
x² − 4
Loading the engine
3.20where it stands (x)
--its value, f(x)
--its slope, f′(x)
--its roots (free pops)
--real domain
--asymptotes
--parity
--closure speed
compiled closure: --
Punch
New stack

Drag the stack along the paper, or punch it with a card.

Every card here goes to the Instacalc engine the game ships (engine/ic-slim.mjs) through the game's own adapter (engine/ic-engine.js), with the boil-over line at a value of 70 from play.html.

Under the hood · Problem-oriented DSLs

Meanings in .ic, tiny host.* drivers in JS

Inspired by VPRI STEPS / Nile / Gezira: every formula, 3D rig, audio patch, art pack, and gameplay rule lives in declarative .ic cartridges. JavaScript is a compact driver kernel (engine/ic-host.js: ZFRules + host.{rules,gl,audio,ui,save,font,zf,loop,cartridge}), the CAS adapter (engine/ic-engine.js + engine/ic-slim.mjs), and the custom WebGL2 renderer (/vendor/ic-3d/ic-3d.js).

End-to-end data & execution pipeline
.ic Cartridges (Plain Text) rules/*.ic · meta/*.ic audio/{sfx,music}.ic Enemies, bosses, rigs, styles, SFX patches, @example proofs Live Game Formulas "x^2 - 4" + card (√, d/dx, ln) Evaluated at spawn or card hit, cached by formula text (never touches CAS at 60 fps) ic-host.js (Host Kernel) ZFRules parser + @example runner host.{rules, gl, audio, ui, save} Loads .ic sheets, builds 3D meshes, runs WebAudio synth & UI bindings AOT .ic → .generated.js three-math, geo-dsl, physics, juice-math ic-engine.js + ic-slim.mjs CAS: simplify, derive, integrate, solve Emits monomorphic JS closures F.f(x) 5–25 ns/call · splits block terms (z) play.html & Hub Arena 60 fps loop reads F.f(x), roots, asymptotes, physics & HUD 0 image/audio assets in play ic-3d.js (Instacalc GL) Custom single-pass WebGL2 Three.js-compatible scene graph ACES + derivative bump + shadows Audio & Music Host host.audio + ic-music-host.js WebAudio synth from .ic patches
Measuring the layers…

Zero duplicated data tables. Views, cameras, style packs, SFX patches, and 3D boss/enemy specs load directly from .ic via host.rules.loadSheet().

VPRI ceiling (~85–90% in .ic). Roughly 25% of shipped gzip bytes are pure .ic text (the rest is the WebGL2/CAS compiler kernel & fonts); over 85% of game & asset definitions are .ic source.

Zero binary assets. Every 3D mesh, canvas decal, graph texture, and synth patch is generated from source code at load.

1. Calculus → 3D Mesh

Analytic functions extrude and lathe directly into Three/ic-3d meshes.

{s: extrude(-0.7, 0.7, 0.7), fn: x => 0.1 * exp(2.75 * (x + 0.7) / 1.4)}

2. Symmetry & Polar Loops

One bilateral flag + golden-angle comprehensions replace imperative loops.

{s: sph(0.12 + i*0.024, 10, 8), p: [cos(i*2.4)*r, 0.2+i*0.14, sin(i*2.4)*r]}

3. APL Broadcast & Pipes

Rank-polymorphic math and markdown tables collapse config boilerplate.

glove_costs = round(20 * 1.6 ^ (0..<5))
sfx.ic: mtof(n) = 440 * (2 ^ ((n - 69) / 12))

4. Gezira Vector & Audio Ops

2D face textures and multi-oscillator SFX compile from pure records.

coin: {tones: [{f: mtof(88), d: 0.09}, {f: mtof(93), d: 0.16, at: 0.05}]}

5. Inline Doctests & Solver

@example proofs & equation backsolving verify sheets at load. Open .ic Lab

/// @example round(mtof(69)) => 440
/// @example len(enemy_models) => 10

How InstaCalc Itself Is Made

Compiler + Reactive Sheet Architecture (not a black-box CAS)

1. Toki + Parsley

A zero-allocation tokenizer (Toki) and Pratt parser (Parsley) turn infix math, APL ranges (0..<5), and .ic rules into a compact AST.

2. Symbolic CAS (ic-slim.mjs)

Runs tree-rewriting rules for simplify, derive, integrate, and solve only when a formula spawns or takes a card hit.

3. Monomorphic Closures

Compiles ASTs to plain JS functions F.f(x) (~25–130 ns/call) and splits terms into clay blocks so 60 fps loops never touch the CAS.

4. host.* + ic-3d.js

ic-host.js binds .ic rules, @example proofs, WebAudio synths, and procedural geometry directly into the WebGL2 renderer.

The renderer, running

Instacalc GL, live on this page

Calcy and a block stack from the hub's kit (meta/meta-kit.js), built from code and drawn by Instacalc GL, the game's own WebGL2 renderer in /vendor/ic-3d/ic-3d.js. It keeps three.js's API, so the same scene code runs on either; three.js 0.160 stays only as the test oracle that every frame is compared against. The numbers are read from the renderer each half second. Drag to turn the desk.

Waiting to scroll into view
renderer--
frames per second--
draw calls, last frame--
triangles, last frame--
shader programs--
textures on the GPU--
geometries--
meshes in the scene--
shader compile, total--
JS heap--
Scene Calcy + x²+2x−4
Same scene on three.js

Frame match today (gl/compare.cjs, 2026-11-14): 17 of 17 frames pass against three.js; twelve are the same image, the five boss frames score SSIM 0.9984 to 0.9993. play-test.cjs passes all 178 checks on both renderers.

Zero binary assets · Procedural geometry

Math → 3D Mesh: Procedural .ic Assets & Cutaways

Instead of shipping multi-megabyte .glb or .obj meshes, InstaCalc (the game) defines shields, pillars, crystals, and boss props with tiny .ic math equations (polar radii r(θ) = R + a·cos(k·θ), lathe profiles, and twisted extrusions). At load time, geo-dsl.ic → geo-dsl.generated.js and ic-3d.js evaluate the equations into GPU vertex/triangle buffers.

.ic Math Source

~118 B

Plain-text parametric equation—readable, diffable, and doctested.

Generated GPU Buffer

--

Synthesized once at load into WebGL2 Float32Array attributes.

Static .glb / .obj

120–450 KB

Baked vertex dumps are ~1,000× larger than the .ic equation.

Preset
View
Procedural .ic Mesh (ic-3d.js)
Live .ic Equation (editable r(t, y))

          
vertices--
triangles--
Shipped build vs. dev sources

145 KB shipped game · live dev-source tree

The minified production build ships in 145.4 KB gzipped (first three treemap views). The Live bundle breakdown tree below crawls the unbundled, readable dev files served in this folder.

Graphics layer145.4 KB of 150 KB

Measured on the built game by the scorecard: 113 KB of code, 7 KB of page and CSS, 25 KB of self-hosted font subsets. Under budget with 4.6 KB to spare; Brotli makes it 129 KB.

Instacalc engine17 KB to 3.4 MB, by build
17 KBcalculator core: parser, units, functions
55 KB+ derivatives and simplify
164 KB+ integrals: every card in the game
228 KB+ solving and limits
3.4 MBthe full product build, with charts, table tools and reference data the game never calls

Counted separately from the graphics budget. The game ships 176 KB behind the title (the 164 KB math build plus a 12 KB adapter and baked rules), under its 180 KB target.

Declarative .ic Share vs host.* Driver Kernel (live from origin)Measuring…

Measuring all served .ic cartridges (green), thin ic-host.js / ic-engine.js adapters (orange), and imperative rendering/DOM code…

JS Host / Game WebGL2 / ic-3d.js .ic Rules CSS / Browser

Measuring

Live bundle breakdown

Live crawl across play.html, meta/meta.html, and battlebot.html. Click any phase or folder to expand.

Phase / Folder / FileRawGzip
Fetching the files…
Total——

This folder serves the game's readable sources, one file each, so these numbers are larger than the scorecard's: the build (tools/build-game.mjs) bundles, minifies and tree-shakes play.html and Instacalc GL into one script. Gzip here is your browser's CompressionStream at its default level; the scorecard uses gzip -9, so expect a few percent of difference.

The rules & cartridges, as written

Plain-text .ic sheets evaluated live by host.rules

Every rule, style pack, SFX patch, camera spec, and procedural 3D sculpture lives in plain-text .ic. Click any sheet to inspect its source and run its embedded @example doctests in your browser.

Loading the sheets…
Loading…

Walkthroughs

Follow one thing all the way through

Step-by-step trace: card → CAS → 3D → SFX (4 walkthroughs)
    1 / 5
    Interactive Font FX

    Math Typography Preview Card

    Live broad-nib cursive ln + curve-baseline f(x) wave warp rendered in real time via canvas.

    Live: broad-nib Bezier cursive ln + golden vector-path tracer along f(x) = sin(kx)
    In the game · Live

    What the math looks like on the desk

    Instead of static screenshots, this stage boots the live playable play.html engine in god mode and switches scenarios and art packs on the fly, paired with inline callouts for the active .ic rule and shader pass.

    Scenario
    Art Style
    .ic rule: combat.ic · chain_window = 2.4s shader: ic-3d.js · Lambert + 1024px PCF shadow

    Pop Chain on Desk Day: clearing one stack triggers neighbor pops within the chain radius; each pop steps up the chord in sfx.ic.

    60fps Particle Lab
    Sunflower Spiral r = c·√i, θ = i·2.39996 Hover the canvas to inspect live phase & coordinates.

    Each effect is a short .ic sheet whose motion is a pure formula of particle age t, compiled to a shader. 2,512 probes match the Instacalc engine.

    Architecture comparison

    Why InstaCalc vs. Unity, Godot, or Three.js?

    Honest trade-offs: symbolic math + 145 KB web boot vs. heavy-art tooling and physics engines.

    DimensionInstaCalc (.ic + ic-3d.js)Unity / Godot (Web Export)Honest Verdict
    Bundle & cold boot~145 KB gfx + 176 KB CAS · <250 ms4–60 MB WASM + assets · 3–12 sInstaCalc for instant web play
    Dynamic formulasNative CAS (derive, integrate, solve) + closure JITRequires writing or embedding custom parser/CASInstaCalc (by 10× less glue)
    3D asset pipeline150 B .ic equations → GPU buffersBlender / Maya → .glb / .fbx + importerInstaCalc for math; Unity/Godot for art
    Physics & lightingCustom springs + single-pass WebGL2 shadowsPhysX/Jolt, PBR, baked GI, post-FX stackUnity / Godot for heavy 3D worlds
    Modding & proofsPlain-text .ic + inline @example doctestsExternal Lua/WASM sandbox or C# reflectionInstaCalc for safe live rule editing
    Detailed strengths & trade-offs (8-point breakdown)

    Where InstaCalc Beats Mainstream Engines

    • Symbolic math as a live game primitive: In Unity/Godot, curves are baked into AnimationCurve keyframes or lookup tables. Here, x² + 2x − 4 is a live AST: d/dx, ∫, root-finding, and term-splitting happen symbolically, then compile to ~25 ns JS closures.
    • 150-byte parametric 3D vs. 400 KB .glb blobs: No Blender export-reimport loop, binary git bloat, or fixed LODs. A 3-line .ic equation generates solid meshes, wireframes, and cross-section cutaways at load.
    • 145 KB instant browser cold-boot: Unity WebGL exports routinely ship 15–60 MB of WASM + runtime before frame 1. InstaCalc (the game)'s entire WebGL2 renderer + game boots in ~145 KB gzipped.
    • Diffable, doctested .ic rules + player scripting: Every balance table, SFX synth patch, camera rig, and autopilot rule is plain text verified by inline /// @example proofs at load—safe for players to edit live.

    Honest Verdict: Where Unity / Godot Still Win

    • Art-heavy 3D & skeletal animation: If you need ZBrush sculpts, mocap IK blend trees, PBR texture atlases, or global illumination, use Unity/Godot/Unreal—ic-3d.js is built for stylized procedural math, not photogrammetry.
    • General rigid-body & ragdoll physics: physics.ic excels at springs, clay squash-and-stretch, and arena projectiles, not 500-stack Jolt/PhysX ragdoll simulations or navmesh crowd AI.
    • Visual WYSIWYG editors & console SDKs: Non-programmer level designers expect drag-and-drop scene inspectors and one-click Switch/PS5/Xbox exports. InstaCalc is text-first and web-native.
    • Debugging complex game state: Unity/Godot have mature step-through frame debuggers and scene-tree inspectors; .ic sheets rely on ic-agree doctests and browser DevTools.
    How it was built

    Project timeline & verification

    8-stage build log & automated verification checks (448 CAS values · 178 play checks)
    1. A neon prototype

      "Zero Frame" proved the loop: towers that are formulas, weapons that are operations, zero means destroyed.

    2. Rules moved into .ic

      Every tunable number and table went into Instacalc sheets, checked against the real engine with ic-agree. Play stayed identical.

    3. Rules you write yourself

      An autopilot: playing by hand is free and pays most, your own .ic rules are free, full auto costs battery.

    4. The look came from concept art

      Image-model concepts set the target; a real-time three.js arena was tuned against them with blind reviews until reviewers struggled to tell a game frame from the concept.

    5. The paper became the plane

      Position became x, roots became free pops, asymptotes became bombs, and the neon look retired for a cozy desk.

    6. Bots played it hundreds of times

      Newcomer, skilled and critic bots found a 70-second walkover, free wrong answers and a lose screen that blamed the wrong thing. A one-command fun check now replays them after every change.

    7. Theme packs, music, helpers

      Eight art styles, a mood composer built on musical modes, and designs for drones and turrets programmed in .ic. Other AIs joined through GitHub issues.

    8. Its own engine, top to bottom

      Instacalc GL replaced three.js with frames that match pixel for pixel, ic-slim.mjs replaced stand-in math, and garbage per frame fell from 2.4 MB to 0.34 MB.

    How a change is provenToolWhat it says today
    Rules match the real engineic-agree14 sheets · 263 rows · 448 values · all agree
    The game still playsplay-test.cjs178 checks, including a full boss fight
    Frames match three.jsgl/compare.cjs17 of 17 frames pass
    It is still funfun-check.cjs9 bots vs a baseline
    The music obeys its theorycomposer-test.cjs9,984 bars · every cadence
    It looks shippableblind reviewerscore screens read as indie
    What's next

    Any formula in, a correct game out

    The Instacalc engine is the game's math: it loads behind the title, the game asks it once when a stack spawns or a card lands, and its answer is compiled into a function that runs in 5 to 25 nanoseconds, fast enough for every frame. Every answer is exact Instacalc math, checked on 6,278 formulas. That unlocks the features nobody can copy quickly:

    The formula forge. Type any expression and it becomes an enemy, with its blocks, shells, roots and asymptotes derived correctly.
    Calc Colossus. Paste any Instacalc calc and it becomes a boss: rows are body parts and the dependency graph is its skeleton.
    Units as weapons. Convert a stack from km to miles or melt it from °C to K, using Instacalc's unit system.
    More bosses from their math. After the golem: even functions are symmetric, poles grow spikes, periodic ones dance on the beat.