code wiki / (root) / nx_simlab.nx

nx_simlab.nx

buildroot/runtime/nx_simlab.nx

6353 B126 linesdepth 0pulls 0 transitivereach 1 importersview sourcekind librarytopic simlab
docsdependenciesstructsconstsfunctions

about

nx_simlab.nx -- Simulates 2D gravitational orbits using integer arithmetic for both native and browser execution.

dependencies 0 imports · 1 importers

nx_simlab.nx nx_simlab_gate.nx

imports: none

imported by: nx_simlab_gate.nx

structs

none

consts

2const O_MAGIC_4096: i64 = 4096
12const W: i64 = 256
13const H: i64 = 256
14const O_FB: i64 = 0 // framebuffer W*H i64 packed-RGB at linear-mem offset 0 (W*H*8 = 524288 bytes)
15const O_ST: i64 = 524288 // scalars: [0]x [1]y [2]vsx [3]vsy [4]mode(0=leapfrog,1=euler) [5]steps [6]E0 [7]tcount [8]thead
16const O_TR: i64 = 524416 // trajectory ring buffer: TRAILN points x 2 i64 (px,py)
17const TRAILN: i64 = 200
18const SC: i64 = 100000
19const GM: i64 = 15625000000000 // (SC/8)^2 * SC -> circular speed SC/8 at r=SC
20const D: i64 = 64
21const VS: i64 = 128 // = 2*D (exact symplectic half-kick)
22const DD2: i64 = 8192 // = 2*D*D (position step divisor)
23const VY0: i64 = 12500 // initial tangential speed (circular)
24const CX: i64 = 128
25const CY: i64 = 128
26const SPX: i64 = 70 // pixels per SC (orbit radius -> 70 px)
27const STEPS_PER_TICK: i64 = 32

functions

29func rgb(r: i64, g: i64, b: i64) -> i64 { return (r & 255) | ((g & 255) << 8) | ((b & 255) << 16) }
called by 1: render_impl
30func isqrt(N: i64) -> i64 { if N<2 { return N } var x: i64=N; var y: i64=(x+1)/2; while y<x { x=y; y=(x + N/x)/2 } return x }
called by 3: energy2step_onemain
32func putpx(base: i64, px: i64, py: i64, c: i64) -> i64
called by 2: discrender_impl
36func disc(base: i64, px: i64, py: i64, r: i64, c: i64) -> i64
called by 1: render_impl calls 1: putpx
43func clear_fb(base: i64, c: i64) -> i64 { let fb: *i64=(base+O_FB) as *i64; var i: i64=0; while i<W*H { fb[i]=c; i=i+1 } return 0 }
called by 1: render_impl
46func energy2(x: i64, y: i64, vsx: i64, vsy: i64) -> i64 { let r: i64=isqrt(x*x+y*y); let vrx: i64=vsx/VS; let vry: i64=vsy/VS; return vrx*vrx+vry*vry - 2*GM/r }
called by 3: reset_implrender_implmain calls 1: isqrt
48func reset_impl(base: i64) -> i64
called by 2: init_impltick_impl calls 1: energy2
54func init_impl(base: i64) -> i64 { let st: *i64=(base+O_ST) as *i64; st[4]=0; reset_impl(base); return 0 }
called by 2: initmain calls 1: reset_impl
56func step_one(base: i64) -> i64
called by 1: tick_impl calls 1: isqrt
76func record_trail(base: i64) -> i64
called by 1: tick_impl
83func tick_impl(base: i64, cmd: i64) -> i64
92func render_impl(base: i64) -> i64
120func ww() -> i64 { return W }
called by 1: main
121func hh() -> i64 { return H }
called by 1: main
122func fb_off() -> i64 { return O_FB }
called by 1: main
123func init() -> i64 { return init_impl(0) }
calls 1: init_impl
124func tick(cmd: i64) -> i64 { return tick_impl(0, cmd) }
calls 1: tick_impl
125func render() -> i64 { return render_impl(0) }
calls 1: render_impl
126func mem_bytes() -> i64 { return O_TR + TRAILN*2*8 + O_MAGIC_4096 }