{
"id": "200",
"prompt": "A weather widget: temperature rides a slow day/night cycle 8..32 C from a sine table indexed by t/32. Draw a thermometer - a pixel-circle bulb (dx*dx + dy*dy <= r*r loop), a tube whose red column height maps the 8..32 range, tick marks with labels every 5 degrees - the big current reading, and a scrolling mini history strip along the bottom sampled from the same formula.",
"solution_rl": "fn sv(i: i32) -> i32 {\n let tab = [0, 25, 49, 71, 90, 106, 117, 124, 127, 124, 117, 106, 90, 71, 49, 25, 0, -25, -49, -71, -90, -106, -117, -124, -127, -124, -117, -106, -90, -71, -49, -25];\n tab[i & 31]\n}\n\nfn frame(t: i32) {\n let w: i32 = host::display::width();\n let h: i32 = host::display::height();\n let temp: i32 = 20 + sv(t / 32) * 12 / 127;\n host::display::clear(0x0a0e14);\n let colx: i32 = w / 3;\n let colbase: i32 = h - 140;\n let colh: i32 = 200;\n let by: i32 = colbase + 20;\n let mut dy: i32 = 0 - 16;\n while dy <= 16 {\n let mut dx: i32 = 0 - 16;\n while dx <= 16 {\n if dx * dx + dy * dy <= 256 {\n host::display::set_pixel(colx + dx, by + dy, 0xe04040);\n }\n dx = dx + 1;\n }\n dy = dy + 1;\n }\n host::display::fill_rect(colx - 6, colbase - colh, 13, colh, 0x202028);\n let fh: i32 = (temp - 8) * colh / 24;\n host::display::fill_rect(colx - 4, colbase - fh, 9, fh, 0xe04040);\n let mut v: i32 = 10;\n while v <= 30 {\n let ty: i32 = colbase - (v - 8) * colh / 24;\n host::display::draw_line(colx + 10, ty, colx + 18, ty, 0x808080);\n host::display::draw_number(colx + 24, ty - 4, v, 0x808080, 1);\n v = v + 5;\n }\n host::display::draw_number(colx - 70, colbase - colh, temp, 0xffffff, 4);\n host::display::draw_string(colx - 70, colbase - colh + 36, \"DEG C\", 0x808080, 1);\n let sy: i32 = h - 60;\n let mut x: i32 = 0;\n while x < w {\n let tv: i32 = 20 + sv((t - (w - x) * 4) / 32) * 12 / 127;\n host::display::fill_rect(x, sy + 24 - (tv - 8), 2, 2, 0x40c0ff);\n x = x + 4;\n }\n host::display::draw_string(8, sy - 12, \"HISTORY\", 0x606060, 1);\n host::display::present();\n}\n",
"tags": [
"gauge",
"trig-table",
"time"
]
}