{
"id": "143",
"prompt": "Two-tone siren you can arm with a tap (edge-detected toggle in state slots): while armed, alternate 600 Hz and 900 Hz sawtooth blasts every 30 frames - fire each tone only on its boundary frame - and flash the matching half of the screen red or blue like a police light bar. Disarming must call host::audio::stop(-1) so nothing keeps ringing.",
"solution_rl": "fn frame(t: i32) {\n let w: i32 = host::display::width();\n let h: i32 = host::display::height();\n let down: i32 = host::display::pointer_down();\n let prev: i32 = host::display::state_get(0);\n let mut on: i32 = host::display::state_get(1);\n if down == 1 && prev == 0 {\n on = 1 - on;\n if on == 0 { host::audio::stop(-1); }\n }\n host::display::state_set(0, down);\n host::display::state_set(1, on);\n let hi: i32 = (t / 30) % 2;\n if on == 1 && t % 30 == 0 {\n if hi == 1 {\n host::audio::tone(900, 290, 2);\n } else {\n host::audio::tone(600, 290, 2);\n }\n }\n let mut left: i32 = 0x200008;\n let mut right: i32 = 0x000820;\n if on == 1 && hi == 1 { left = 0xff2020; }\n if on == 1 && hi == 0 { right = 0x4060ff; }\n host::display::clear(0x000000);\n host::display::fill_rect(0, 0, w / 2, h, left);\n host::display::fill_rect(w / 2, 0, w / 2, h, right);\n if on == 1 {\n host::display::draw_string(24, h / 2, \"TAP = OFF\", 0xffffff, 2);\n } else {\n host::display::draw_string(24, h / 2, \"TAP = SIREN\", 0xffffff, 2);\n }\n host::display::present();\n}\n",
"tags": [
"audio",
"pointer",
"state",
"modulo"
]
}