{
"id": "239",
"prompt": "Six satellites orbiting a sun in the center forever, no floats and no trig tables: use a toy linear pull (velocity += (center - pos) / 128 in 1/16-px fixed point) and integrate velocity BEFORE position - that semi-implicit order is what keeps the orbits from spiraling out. Seed each particle at a different radius with a perpendicular starting velocity of about r/11 so they circle instead of plunging. Yellow sun, particles tinted by index.",
"solution_rl": "fn 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 if host::display::state_get(0) == 0 {\n host::display::state_set(0, 1);\n let mut i: i32 = 0;\n while i < 6 {\n let r: i32 = 40 + i * 18;\n host::display::state_set(8 + i * 4, (cx + r) * 16);\n host::display::state_set(9 + i * 4, cy * 16);\n host::display::state_set(10 + i * 4, 0);\n host::display::state_set(11 + i * 4, r * 16 / 11);\n i = i + 1;\n }\n }\n host::display::clear(0x000008);\n host::display::fill_rect(cx - 10, cy - 10, 20, 20, 0xffd830);\n let mut i: i32 = 0;\n while i < 6 {\n let b: i32 = 8 + i * 4;\n let mut x: i32 = host::display::state_get(b);\n let mut y: i32 = host::display::state_get(b + 1);\n let mut vx: i32 = host::display::state_get(b + 2);\n let mut vy: i32 = host::display::state_get(b + 3);\n vx = vx + (cx * 16 - x) / 128;\n vy = vy + (cy * 16 - y) / 128;\n x = x + vx;\n y = y + vy;\n host::display::state_set(b, x);\n host::display::state_set(b + 1, y);\n host::display::state_set(b + 2, vx);\n host::display::state_set(b + 3, vy);\n let g: i32 = 120 + i * 22;\n host::display::fill_rect(x / 16 - 3, y / 16 - 3, 6, 6, g * 256 + 255);\n i = i + 1;\n }\n host::display::draw_string(8, 8, \"GRAVITY WELL\", 0x506070, 1);\n host::display::present();\n}\n",
"tags": [
"simulation",
"orbits",
"state",
"fixed-point"
]
}