{
"id": "293",
"prompt": "A tiny color pixel editor: an 8x8 canvas at 2 bits per cell packed into ONE state slot per row (shift and mask to read a cell, subtract-then-add to write it - there is no bitwise NOT), a 4-swatch palette picker with the current selection ringed in white, drag-to-paint with the chosen color, and SAVE / LOAD / CLEAR buttons where save copies all 8 row slots into a second bank of slots so load restores the drawing later. Painting works on hold; the buttons are edge-detected.",
"solution_rl": "fn frame(t: i32) {\n host::display::clear(0x0e0f12);\n let palette = [0x14161c, 0xffcc33, 0x33ff88, 0x66aaff];\n let px: i32 = host::display::pointer_x();\n let py: i32 = host::display::pointer_y();\n let down: i32 = host::display::pointer_down();\n let prev: i32 = host::display::state_get(21);\n host::display::state_set(21, down);\n let sel: i32 = host::display::state_get(20);\n\n if down == 1 && px >= 96 && px < 416 && py >= 40 && py < 360 {\n let cx: i32 = (px - 96) / 40;\n let cy: i32 = (py - 40) / 40;\n let row: i32 = host::display::state_get(10 + cy);\n let cur: i32 = (row >> (cx * 2)) & 3;\n host::display::state_set(10 + cy, row - (cur << (cx * 2)) + (sel << (cx * 2)));\n }\n\n if down == 1 && prev == 0 {\n if py >= 380 && py < 420 && px >= 96 && px < 376 {\n let pick: i32 = (px - 96) / 70;\n if pick >= 0 && pick < 4 {\n host::display::state_set(20, pick);\n }\n }\n if py >= 440 && py < 480 {\n if px >= 96 && px < 186 {\n let mut i: i32 = 0;\n while i < 8 {\n host::display::state_set(30 + i, host::display::state_get(10 + i));\n i = i + 1;\n }\n host::display::state_set(22, 30);\n }\n if px >= 206 && px < 296 {\n let mut j: i32 = 0;\n while j < 8 {\n host::display::state_set(10 + j, host::display::state_get(30 + j));\n j = j + 1;\n }\n }\n if px >= 316 && px < 416 {\n let mut k: i32 = 0;\n while k < 8 {\n host::display::state_set(10 + k, 0);\n k = k + 1;\n }\n }\n }\n }\n\n let mut cy2: i32 = 0;\n while cy2 < 8 {\n let row2: i32 = host::display::state_get(10 + cy2);\n let mut cx2: i32 = 0;\n while cx2 < 8 {\n host::display::fill_rect(96 + cx2 * 40 + 1, 40 + cy2 * 40 + 1, 38, 38, palette[(row2 >> (cx2 * 2)) & 3]);\n cx2 = cx2 + 1;\n }\n cy2 = cy2 + 1;\n }\n\n let mut s: i32 = 0;\n while s < 4 {\n if s == sel {\n host::display::fill_rect(94 + s * 70, 378, 64, 44, 0xffffff);\n }\n host::display::fill_rect(96 + s * 70, 380, 60, 40, palette[s]);\n s = s + 1;\n }\n host::display::fill_rect(96, 440, 90, 40, 0x232833);\n host::display::draw_string(112, 452, \"SAVE\", 0xffffff, 1);\n host::display::fill_rect(206, 440, 90, 40, 0x232833);\n host::display::draw_string(222, 452, \"LOAD\", 0xffffff, 1);\n host::display::fill_rect(316, 440, 100, 40, 0x232833);\n host::display::draw_string(332, 452, \"CLEAR\", 0xffffff, 1);\n let flash: i32 = host::display::state_get(22);\n if flash > 0 {\n host::display::draw_string(96, 14, \"SAVED TO THE SLOT\", 0x33ff88, 1);\n host::display::state_set(22, flash - 1);\n } else {\n host::display::draw_string(96, 14, \"DRAG TO PAINT\", 0x556677, 1);\n }\n host::display::present();\n}\n",
"tags": [
"app",
"paint",
"bitmask"
]
}