nx_pendulum.nx
buildroot/runtime/nx_pendulum.nx
about
nx_pendulum.nx -- Simulates a nonlinear pendulum using integer arithmetic and symplectic integration for accurate physical behavior.
dependencies 0 imports · 1 importers
imports: none
imported by: nx_pendulum_gate.nx
structs
| none |
consts
| 2 | const O_MAGIC_3141593: i64 = 3141593 |
| 3 | const O_MAGIC_6283185: i64 = 6283185 |
| 4 | const O_MAGIC_1570796: i64 = 1570796 |
| 5 | const O_MAGIC_1047198: i64 = 1047198 |
| 6 | const O_MAGIC_4096: i64 = 4096 |
| 15 | const W: i64 = 256 |
| 16 | const H: i64 = 256 |
| 17 | const O_FB: i64 = 0 |
| 18 | const O_TH: i64 = 524288 // theta (micro-rad, x1e6) |
| 19 | const O_OM: i64 = 524296 // omega (micro-rad / s) |
| 20 | const O_GLN: i64 = 524304 // restoring numerator = 980/L (g/L * dt * 1e5, g=9.8 dt=1ms) |
| 21 | const O_AMP: i64 = 524312 // initial amplitude (micro-rad) |
| 22 | const O_LIN: i64 = 524320 // 0 = true sin pendulum, 1 = linear approximation (for the liar-kill) |
| 23 | const O_STEP: i64 = 524328 |
| 24 | const O_THEAD: i64 = 524336 |
| 25 | const O_TCNT: i64 = 524344 |
| 26 | const O_TR: i64 = 524352 // bob trail (display px,py) |
| 27 | const TRAILN: i64 = 120 |
| 28 | const SC: i64 = 1000000 // micro-unit scale |
| 29 | const DT_DIV: i64 = 1000 // theta += omega/1000 (dt = 1ms) |
| 30 | const GL_DIV: i64 = 100000 // omega -= GLN*sin(theta)/1e5 |
| 31 | const CX: i64 = 128 |
| 32 | const PIVY: i64 = 40 |
| 33 | const LPX: i64 = 155 // rod length in pixels |
| 34 | const STEPS_PER_TICK: i64 = 16 |
functions
| 36 | func rgb(r: i64, g: i64, b: i64) -> i64 { return (r & 255) | ((g & 255) << 8) | ((b & 255) << 16) } called by 1: render_impl |
| 37 | func sin_fixed(Xin: i64) -> i64 |
| 49 | func cos_fixed(X: i64) -> i64 { return sin_fixed(X+O_MAGIC_1570796) } |
| 51 | func putpx(base: i64, px: i64, py: i64, c: i64) -> i64 |
| 55 | func disc(base: i64, px: i64, py: i64, r: i64, c: i64) -> i64 |
| 62 | func line(base: i64, x0: i64, y0: i64, x1: i64, y1: i64, c: i64) -> i64 |
| 71 | 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 |
| 73 | func init_impl(base: i64) -> i64 |
| 84 | func step_one_impl(base: i64) -> i64 |
| 94 | func record_trail(base: i64) -> i64 |
| 103 | func tick_impl(base: i64, cmd: i64) -> i64 |
| 110 | func render_impl(base: i64) -> i64 |
| 125 | func ww() -> i64 { return W } called by 1: main |
| 126 | func hh() -> i64 { return H } called by 1: main |
| 127 | func fb_off() -> i64 { return O_FB } called by 1: main |
| 128 | func init() -> i64 { return init_impl(0) } calls 1: init_impl |
| 129 | func tick(cmd: i64) -> i64 { return tick_impl(0, cmd) } calls 1: tick_impl |
| 130 | func render() -> i64 { return render_impl(0) } calls 1: render_impl |
| 131 | func mem_bytes() -> i64 { return O_TR + TRAILN*2*8 + O_MAGIC_4096 } |