nx_gassim.nx
buildroot/runtime/nx_gassim.nx
about
nx_gassim.nx -- Simulates elastic collisions and motion of particles in a 2D box to demonstrate kinetic theory and thermalization.
dependencies 0 imports · 2 importers
imports: none
imported by: nx_gassim_gate.nxnx_sim_film_gate.nx
structs
| none |
consts
| 2 | const O_MAGIC_1600: i64 = 1600 |
| 3 | const O_MAGIC_3200: i64 = 3200 |
| 4 | const O_MAGIC_2000: i64 = 2000 |
| 5 | const O_MAGIC_3600: i64 = 3600 |
| 6 | const O_MAGIC_4096: i64 = 4096 |
| 16 | const W: i64 = 256 |
| 17 | const H: i64 = 256 |
| 18 | const O_FB: i64 = 0 // framebuffer W*H i64 packed-RGB |
| 19 | const N: i64 = 20 // particles |
| 20 | const O_PX: i64 = 524288 // px[N] (sim coords, box 0..BW) |
| 21 | const O_PY: i64 = 524448 |
| 22 | const O_VX: i64 = 524608 |
| 23 | const O_VY: i64 = 524768 |
| 24 | const O_COL: i64 = 524928 // [0] cumulative collision count |
| 25 | const O_STEP: i64 = 524936 // [0] step counter |
| 26 | const BW: i64 = 16000 // sim box width/height |
| 27 | const RAD: i64 = 240 // particle radius (sim units) |
| 28 | const TWO_R2: i64 = 230400 // (2*RAD)^2 |
| 29 | const STEPS_PER_TICK: i64 = 2 |
functions
| 31 | func rgb(r: i64, g: i64, b: i64) -> i64 { return (r & 255) | ((g & 255) << 8) | ((b & 255) << 16) } called by 1: render_impl |
| 32 | 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 } called by 1: render_impl |
| 34 | func putpx(base: i64, px: i64, py: i64, c: i64) -> i64 called by 1: disc |
| 38 | func disc(base: i64, px: i64, py: i64, r: i64, c: i64) -> i64 |
| 45 | 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 |
| 48 | func rdiv(num: i64, den: i64) -> i64 { if num>=0 { return (num + den/2)/den } return 0 - ((0-num + den/2)/den) } called by 1: step_one_impl |
| 50 | func energy(base: i64) -> i64 called by 1: main |
| 55 | func init_impl(base: i64) -> i64 |
| 73 | func step_one_impl(base: i64) -> i64 |
| 106 | func tick_impl(base: i64, cmd: i64) -> i64 |
| 112 | func render_impl(base: i64) -> i64 |
| 127 | func ww() -> i64 { return W } called by 1: main |
| 128 | func hh() -> i64 { return H } called by 1: main |
| 129 | func fb_off() -> i64 { return O_FB } called by 1: main |
| 130 | func init() -> i64 { return init_impl(0) } calls 1: init_impl |
| 131 | func tick(cmd: i64) -> i64 { return tick_impl(0, cmd) } calls 1: tick_impl |
| 132 | func render() -> i64 { return render_impl(0) } calls 1: render_impl |
| 133 | func mem_bytes() -> i64 { return O_STEP + O_MAGIC_4096 } |