nx_simlab.nx
buildroot/runtime/nx_simlab.nx
about
nx_simlab.nx -- Simulates 2D gravitational orbits using integer arithmetic for both native and browser execution.
dependencies 0 imports · 1 importers
imports: none
imported by: nx_simlab_gate.nx
structs
| none |
consts
| 2 | const O_MAGIC_4096: i64 = 4096 |
| 12 | const W: i64 = 256 |
| 13 | const H: i64 = 256 |
| 14 | const O_FB: i64 = 0 // framebuffer W*H i64 packed-RGB at linear-mem offset 0 (W*H*8 = 524288 bytes) |
| 15 | const 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 |
| 16 | const O_TR: i64 = 524416 // trajectory ring buffer: TRAILN points x 2 i64 (px,py) |
| 17 | const TRAILN: i64 = 200 |
| 18 | const SC: i64 = 100000 |
| 19 | const GM: i64 = 15625000000000 // (SC/8)^2 * SC -> circular speed SC/8 at r=SC |
| 20 | const D: i64 = 64 |
| 21 | const VS: i64 = 128 // = 2*D (exact symplectic half-kick) |
| 22 | const DD2: i64 = 8192 // = 2*D*D (position step divisor) |
| 23 | const VY0: i64 = 12500 // initial tangential speed (circular) |
| 24 | const CX: i64 = 128 |
| 25 | const CY: i64 = 128 |
| 26 | const SPX: i64 = 70 // pixels per SC (orbit radius -> 70 px) |
| 27 | const STEPS_PER_TICK: i64 = 32 |
functions
| 29 | func rgb(r: i64, g: i64, b: i64) -> i64 { return (r & 255) | ((g & 255) << 8) | ((b & 255) << 16) } called by 1: render_impl |
| 30 | func 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 } |
| 32 | func putpx(base: i64, px: i64, py: i64, c: i64) -> i64 |
| 36 | func disc(base: i64, px: i64, py: i64, r: i64, c: i64) -> i64 |
| 43 | func 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 |
| 46 | func 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 } |
| 48 | func reset_impl(base: i64) -> i64 |
| 54 | func init_impl(base: i64) -> i64 { let st: *i64=(base+O_ST) as *i64; st[4]=0; reset_impl(base); return 0 } |
| 56 | func step_one(base: i64) -> i64 |
| 76 | func record_trail(base: i64) -> i64 called by 1: tick_impl |
| 83 | func tick_impl(base: i64, cmd: i64) -> i64 |
| 92 | func render_impl(base: i64) -> i64 |
| 120 | func ww() -> i64 { return W } called by 1: main |
| 121 | func hh() -> i64 { return H } called by 1: main |
| 122 | func fb_off() -> i64 { return O_FB } called by 1: main |
| 123 | func init() -> i64 { return init_impl(0) } calls 1: init_impl |
| 124 | func tick(cmd: i64) -> i64 { return tick_impl(0, cmd) } calls 1: tick_impl |
| 125 | func render() -> i64 { return render_impl(0) } calls 1: render_impl |
| 126 | func mem_bytes() -> i64 { return O_TR + TRAILN*2*8 + O_MAGIC_4096 } |