{
"id": "065",
"prompt": "The classic idle-screen logo: a small rectangle labeled \"DVD\" drifts diagonally, bounces off all four edges, and switches to the next color of a 6-color palette array on every wall hit. Position and velocity persist in state slots (no structs in rustlite), the palette index in another slot; also count the bounces in a corner.",
"solution_rl": "fn frame(t: i32) {\n let pal = [0xff4040, 0xffc040, 0x40ff70, 0x40c0ff, 0x8060ff, 0xff60c0];\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, 30);\n host::display::state_set(2, 40);\n host::display::state_set(3, 2);\n host::display::state_set(4, 2);\n }\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 let mut hits: i32 = host::display::state_get(5);\n x = x + vx;\n y = y + vy;\n if x < 0 { x = 0; vx = 0 - vx; hits = hits + 1; }\n if x > w - 48 { x = w - 48; vx = 0 - vx; hits = hits + 1; }\n if y < 0 { y = 0; vy = 0 - vy; hits = hits + 1; }\n if y > h - 22 { y = h - 22; vy = 0 - vy; hits = hits + 1; }\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::state_set(5, hits);\n host::display::clear(0x000000);\n host::display::fill_rect(x, y, 48, 22, pal[hits % 6]);\n host::display::draw_string(x + 8, y + 4, \"DVD\", 0x000000, 2);\n host::display::draw_number(6, 6, hits, 0x606060, 1);\n host::display::present();\n}\n",
"tags": [
"state",
"animation",
"arrays",
"no-struct-boundary"
]
}