{
"id": "067",
"prompt": "A square on an invisible horizontal spring: it accelerates toward the pointer's x with force proportional to distance (a = (target - x)/16 in fixed point), carries momentum, and is damped by 7/8 each frame so it overshoots and settles like a real spring. Position and velocity live in state slots since rustlite locals reset every frame. Draw a thin target line at the pointer x.",
"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 / 2 * 16);\n host::display::state_set(2, 0);\n }\n let target: i32 = host::display::pointer_x() * 16;\n let mut x: i32 = host::display::state_get(1);\n let mut v: i32 = host::display::state_get(2);\n v = v + (target - x) / 16;\n v = v * 7 / 8;\n x = x + v;\n host::display::state_set(1, x);\n host::display::state_set(2, v);\n host::display::clear(0x000000);\n host::display::fill_rect(target / 16, 0, 1, h, 0x304050);\n host::display::fill_rect(x / 16 - 14, h / 2 - 14, 28, 28, 0x40ffa0);\n host::display::present();\n}\n",
"tags": [
"physics",
"pointer",
"state",
"easing"
]
}