nx_solarsim.nx
buildroot/runtime/nx_solarsim.nx
about
nx_solarsim.nx -- Simulates the solar system with integer-based N-body physics, rendering planets and trails in a packed RGB framebuffer.
dependencies 0 imports · 1 importers
imports: none
imported by: nx_solarsim_gate.nx
structs
| none |
consts
| 2 | const O_MAGIC_38700: i64 = 38700 |
| 3 | const O_MAGIC_72300: i64 = 72300 |
| 4 | const O_MAGIC_100000: i64 = 100000 |
| 5 | const O_MAGIC_152400: i64 = 152400 |
| 6 | const O_MAGIC_520300: i64 = 520300 |
| 7 | const O_MAGIC_4096: i64 = 4096 |
| 19 | const W: i64 = 256 |
| 20 | const H: i64 = 256 |
| 21 | const O_FB: i64 = 0 // framebuffer W*H i64 packed-RGB at offset 0 (W*H*8 = 524288 bytes) |
| 22 | const N: i64 = 5 // planets: Mercury, Venus, Earth, Mars, Jupiter |
| 23 | const O_X: i64 = 524288 // x[N] (true coords, AU*SC) |
| 24 | const O_Y: i64 = 524328 // y[N] |
| 25 | const O_VSX: i64 = 524368 // vsx[N] (velocity * VS) |
| 26 | const O_VSY: i64 = 524408 // vsy[N] |
| 27 | const O_R0: i64 = 524448 // r0[N] initial radius (for display scale + period) |
| 28 | const O_RPX: i64 = 524488 // rpx[N] display radius in pixels |
| 29 | const O_TH: i64 = 524528 // trail head[N] |
| 30 | const O_TC: i64 = 524568 // trail count[N] |
| 31 | const O_STEP: i64 = 524608 // [0] global step counter |
| 32 | const O_TR: i64 = 524616 // trails: N*TRAILN points * 2 i64 (px,py) |
| 33 | const TRAILN: i64 = 80 |
| 34 | const SC: i64 = 100000 // 1 AU = 100000 units |
| 35 | const GM: i64 = 15625000000000 // (SC/8)^2 * SC -> circular speed SC/8 at r=SC (Earth period ~3222 steps) |
| 36 | const DD2: i64 = 8192 // position-step divisor (= 2*D*D, D=64) |
| 37 | const VS: i64 = 128 // velocity scale (= 2*D, exact symplectic half-kick) |
| 38 | const CX: i64 = 128 |
| 39 | const CY: i64 = 128 |
| 40 | const STEPS_PER_TICK: i64 = 24 |
functions
| 42 | func rgb(r: i64, g: i64, b: i64) -> i64 { return (r & 255) | ((g & 255) << 8) | ((b & 255) << 16) } |
| 43 | func isqrt(N0: i64) -> i64 { if N0<2 { return N0 } var x: i64=N0; var y: i64=(x+1)/2; while y<x { x=y; y=(x + N0/x)/2 } return x } |
| 44 | func color_of(p: i64) -> i64 |
| 51 | func dim(c: i64) -> i64 { return rgb((c&255)*2/5, ((c>>8)&255)*2/5, ((c>>16)&255)*2/5) } |
| 52 | func radius_of(p: i64) -> i64 { if p==4 { return 4 } return 2 } // Jupiter a touch bigger called by 1: render_impl |
| 54 | func putpx(base: i64, px: i64, py: i64, c: i64) -> i64 |
| 58 | func disc(base: i64, px: i64, py: i64, r: i64, c: i64) -> i64 |
| 65 | 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 |
| 68 | func energy_p(base: i64, p: i64) -> i64 |
| 74 | func set_planet(base: i64, p: i64, a: i64) -> i64 |
| 83 | func init_impl(base: i64) -> i64 |
| 94 | func step_one_impl(base: i64, p: i64) -> i64 |
| 107 | func record_trail(base: i64, p: i64) -> i64 called by 1: tick_impl |
| 116 | func tick_impl(base: i64, cmd: i64) -> i64 |
| 127 | func render_impl(base: i64) -> i64 |
| 145 | func ww() -> i64 { return W } called by 1: main |
| 146 | func hh() -> i64 { return H } called by 1: main |
| 147 | func fb_off() -> i64 { return O_FB } called by 1: main |
| 148 | func init() -> i64 { return init_impl(0) } calls 1: init_impl |
| 149 | func tick(cmd: i64) -> i64 { return tick_impl(0, cmd) } calls 1: tick_impl |
| 150 | func render() -> i64 { return render_impl(0) } calls 1: render_impl |
| 151 | func mem_bytes() -> i64 { return O_TR + N*TRAILN*2*8 + O_MAGIC_4096 } |