code wiki / (root) / nx_gassim.nx

nx_gassim.nx

buildroot/runtime/nx_gassim.nx

6922 B133 linesdepth 0pulls 0 transitivereach 2 importersview sourcekind librarytopic gassim
docsdependenciesstructsconstsfunctions

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

nx_gassim.nx nx_gassim_gate.nx nx_sim_film_gate.nx

imports: none

imported by: nx_gassim_gate.nxnx_sim_film_gate.nx

structs

none

consts

2const O_MAGIC_1600: i64 = 1600
3const O_MAGIC_3200: i64 = 3200
4const O_MAGIC_2000: i64 = 2000
5const O_MAGIC_3600: i64 = 3600
6const O_MAGIC_4096: i64 = 4096
16const W: i64 = 256
17const H: i64 = 256
18const O_FB: i64 = 0 // framebuffer W*H i64 packed-RGB
19const N: i64 = 20 // particles
20const O_PX: i64 = 524288 // px[N] (sim coords, box 0..BW)
21const O_PY: i64 = 524448
22const O_VX: i64 = 524608
23const O_VY: i64 = 524768
24const O_COL: i64 = 524928 // [0] cumulative collision count
25const O_STEP: i64 = 524936 // [0] step counter
26const BW: i64 = 16000 // sim box width/height
27const RAD: i64 = 240 // particle radius (sim units)
28const TWO_R2: i64 = 230400 // (2*RAD)^2
29const STEPS_PER_TICK: i64 = 2

functions

31func rgb(r: i64, g: i64, b: i64) -> i64 { return (r & 255) | ((g & 255) << 8) | ((b & 255) << 16) }
called by 1: render_impl
32func 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
34func putpx(base: i64, px: i64, py: i64, c: i64) -> i64
called by 1: disc
38func disc(base: i64, px: i64, py: i64, r: i64, c: i64) -> i64
called by 1: render_impl calls 1: putpx
45func 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
48func 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
50func energy(base: i64) -> i64
called by 1: main
55func init_impl(base: i64) -> i64
73func step_one_impl(base: i64) -> i64
called by 2: tick_implmain calls 1: rdiv
106func tick_impl(base: i64, cmd: i64) -> i64
called by 2: tickmain calls 2: init_implstep_one_impl
112func render_impl(base: i64) -> i64
called by 3: rendermainmain calls 4: clear_fbrgbisqrtdisc
127func ww() -> i64 { return W }
called by 1: main
128func hh() -> i64 { return H }
called by 1: main
129func fb_off() -> i64 { return O_FB }
called by 1: main
130func init() -> i64 { return init_impl(0) }
calls 1: init_impl
131func tick(cmd: i64) -> i64 { return tick_impl(0, cmd) }
calls 1: tick_impl
132func render() -> i64 { return render_impl(0) }
calls 1: render_impl
133func mem_bytes() -> i64 { return O_STEP + O_MAGIC_4096 }