{
"id": "062",
"prompt": "Animate a pendulum swinging from the top center: the bob's horizontal offset comes from a 16-entry sine table (so it slows at the extremes like a real swing), and since rustlite has no sqrt, approximate the rod constraint with y = pivotY + R - x*x/(2*R) (the circle's small-angle expansion). Draw the rod with draw_line, a small pivot block, and a round-ish bob.",
"solution_rl": "fn frame(t: i32) {\n let tab = [0, 49, 90, 117, 127, 117, 90, 49, 0, -49, -90, -117, -127, -117, -90, -49];\n let w: i32 = host::display::width();\n let h: i32 = host::display::height();\n let px: i32 = w / 2;\n let py: i32 = 8;\n let r: i32 = h * 2 / 3;\n let s: i32 = tab[(t / 3) & 15];\n let xoff: i32 = s * (w / 2 - 20) / 127;\n let bx: i32 = px + xoff;\n let by: i32 = py + r - xoff * xoff / (2 * r);\n host::display::clear(0x000000);\n host::display::fill_rect(px - 3, py - 3, 6, 6, 0x808080);\n host::display::draw_line(px, py, bx, by, 0xa0a0a0);\n host::display::fill_rect(bx - 7, by - 7, 14, 14, 0xffb020);\n host::display::present();\n}\n",
"tags": [
"trig-table",
"physics",
"animation"
]
}