{
"id": "072",
"prompt": "A magnet ball with real inertia: every frame it accelerates toward the pointer by (pointer - pos)/64 (fixed point, 1 px = 16 units), velocity damped by 15/16, so it orbits and overshoots the cursor instead of sticking to it. State slots hold x, y, vx, vy across frames. Draw a faint line from ball to pointer plus the ball.",
"solution_rl": "fn frame(t: i32) {\n let w: i32 = host::display::width();\n let h: i32 = host::display::height();\n if host::display::state_get(0) == 0 {\n host::display::state_set(0, 1);\n host::display::state_set(1, w * 4);\n host::display::state_set(2, h * 4);\n }\n let px: i32 = host::display::pointer_x();\n let py: i32 = host::display::pointer_y();\n let mut x: i32 = host::display::state_get(1);\n let mut y: i32 = host::display::state_get(2);\n let mut vx: i32 = host::display::state_get(3);\n let mut vy: i32 = host::display::state_get(4);\n vx = vx + (px * 16 - x) / 64;\n vy = vy + (py * 16 - y) / 64;\n vx = vx * 15 / 16;\n vy = vy * 15 / 16;\n x = x + vx;\n y = y + vy;\n host::display::state_set(1, x);\n host::display::state_set(2, y);\n host::display::state_set(3, vx);\n host::display::state_set(4, vy);\n host::display::clear(0x000000);\n host::display::draw_line(x / 16, y / 16, px, py, 0x203040);\n host::display::fill_rect(px - 2, py - 2, 4, 4, 0x606060);\n host::display::fill_rect(x / 16 - 6, y / 16 - 6, 12, 12, 0xff4080);\n host::display::present();\n}\n",
"tags": [
"physics",
"pointer",
"state",
"no-struct-boundary"
]
}