{
"id": "226",
"prompt": "A morphing rose curve: r = |sin(k*a)| in integer math - 256 samples per revolution using an interpolated 32-entry sine table (raw indices are too chunky for a smooth petal edge), with k stepping through 2..6 every two seconds. Color the trace in four bands and print the current petal multiplier at the bottom.",
"solution_rl": "fn sinf(a: 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 let i: i32 = (a >> 3) & 31;\n let f: i32 = a & 7;\n let s0: i32 = tab[i];\n let s1: i32 = tab[(i + 1) & 31];\n s0 + (s1 - s0) * f / 8\n}\n\nfn cosf(a: i32) -> i32 {\n sinf(a + 64)\n}\n\nfn frame(t: i32) {\n let w: i32 = host::display::width();\n let h: i32 = host::display::height();\n let cx: i32 = w / 2;\n let cy: i32 = h / 2;\n let m: i32 = if w < h { w } else { h };\n let big: i32 = m / 2 - 30;\n let k: i32 = 2 + (t / 120) % 5;\n let pal = [0xff9de2, 0xffd166, 0x9df2ff, 0xb0ff9d];\n host::display::clear(0x070310);\n let mut a: i32 = 0;\n while a < 256 {\n let mut pet: i32 = sinf(a * k);\n if pet < 0 { pet = 0 - pet; }\n let rr: i32 = pet * big / 127;\n let x: i32 = cx + cosf(a) * rr / 127;\n let y: i32 = cy + sinf(a) * rr / 127;\n host::display::fill_rect(x - 1, y - 1, 3, 3, pal[(a >> 6) & 3]);\n a = a + 1;\n }\n host::display::draw_string(8, h - 24, \"PETALS\", 0x554466, 2);\n host::display::draw_number(104, h - 24, k, 0x554466, 2);\n host::display::present();\n}\n",
"tags": [
"generative",
"trig-table",
"math",
"animation"
]
}