code wiki / (root) / nx_pendulum.nx

nx_pendulum.nx

buildroot/runtime/nx_pendulum.nx

6238 B131 linesdepth 0pulls 0 transitivereach 1 importersview sourcekind librarytopic pendulum
docsdependenciesstructsconstsfunctions

about

nx_pendulum.nx -- Simulates a nonlinear pendulum using integer arithmetic and symplectic integration for accurate physical behavior.

dependencies 0 imports · 1 importers

nx_pendulum.nx nx_pendulum_gate.nx

imports: none

imported by: nx_pendulum_gate.nx

structs

none

consts

2const O_MAGIC_3141593: i64 = 3141593
3const O_MAGIC_6283185: i64 = 6283185
4const O_MAGIC_1570796: i64 = 1570796
5const O_MAGIC_1047198: i64 = 1047198
6const O_MAGIC_4096: i64 = 4096
15const W: i64 = 256
16const H: i64 = 256
17const O_FB: i64 = 0
18const O_TH: i64 = 524288 // theta (micro-rad, x1e6)
19const O_OM: i64 = 524296 // omega (micro-rad / s)
20const O_GLN: i64 = 524304 // restoring numerator = 980/L (g/L * dt * 1e5, g=9.8 dt=1ms)
21const O_AMP: i64 = 524312 // initial amplitude (micro-rad)
22const O_LIN: i64 = 524320 // 0 = true sin pendulum, 1 = linear approximation (for the liar-kill)
23const O_STEP: i64 = 524328
24const O_THEAD: i64 = 524336
25const O_TCNT: i64 = 524344
26const O_TR: i64 = 524352 // bob trail (display px,py)
27const TRAILN: i64 = 120
28const SC: i64 = 1000000 // micro-unit scale
29const DT_DIV: i64 = 1000 // theta += omega/1000 (dt = 1ms)
30const GL_DIV: i64 = 100000 // omega -= GLN*sin(theta)/1e5
31const CX: i64 = 128
32const PIVY: i64 = 40
33const LPX: i64 = 155 // rod length in pixels
34const STEPS_PER_TICK: i64 = 16

functions

36func rgb(r: i64, g: i64, b: i64) -> i64 { return (r & 255) | ((g & 255) << 8) | ((b & 255) << 16) }
called by 1: render_impl
37func sin_fixed(Xin: i64) -> i64
49func cos_fixed(X: i64) -> i64 { return sin_fixed(X+O_MAGIC_1570796) }
called by 2: record_trailrender_impl calls 1: sin_fixed
51func putpx(base: i64, px: i64, py: i64, c: i64) -> i64
called by 3: disclinerender_impl
55func disc(base: i64, px: i64, py: i64, r: i64, c: i64) -> i64
called by 1: render_impl calls 1: putpx
62func line(base: i64, x0: i64, y0: i64, x1: i64, y1: i64, c: i64) -> i64
called by 1: render_impl calls 1: putpx
71func 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
73func init_impl(base: i64) -> i64
called by 3: tick_implinitmain
84func step_one_impl(base: i64) -> i64
called by 2: tick_implmeasure_period calls 1: sin_fixed
94func record_trail(base: i64) -> i64
called by 1: tick_impl calls 2: sin_fixedcos_fixed
103func tick_impl(base: i64, cmd: i64) -> i64
110func render_impl(base: i64) -> i64
125func ww() -> i64 { return W }
called by 1: main
126func hh() -> i64 { return H }
called by 1: main
127func fb_off() -> i64 { return O_FB }
called by 1: main
128func init() -> i64 { return init_impl(0) }
calls 1: init_impl
129func tick(cmd: i64) -> i64 { return tick_impl(0, cmd) }
calls 1: tick_impl
130func render() -> i64 { return render_impl(0) }
calls 1: render_impl
131func mem_bytes() -> i64 { return O_TR + TRAILN*2*8 + O_MAGIC_4096 }