(* Tiny animation test - no chunking needed *) (* Uses 20x20 images which are ~1067 bytes base64 (well under 4096) *) module K = Kgp let solid_color_rgba ~width ~height ~r ~g ~b ~a = let pixels = Bytes.create (width * height * 4) in for i = 0 to (width * height) - 1 do let idx = i * 4 in Bytes.set pixels idx (Char.chr r); Bytes.set pixels (idx + 1) (Char.chr g); Bytes.set pixels (idx + 2) (Char.chr b); Bytes.set pixels (idx + 3) (Char.chr a) done; Bytes.to_string pixels let send cmd ~data = print_string (K.Command.to_string cmd ~data); flush stdout let () = (* Use 20x20 to avoid chunking: 20*20*4 = 1600 bytes, base64 ~2134 bytes *) let width, height = 20, 20 in let image_id = 999 in (* Clear any existing images *) send (K.Command.delete ~quiet:`Errors_only (`All_visible_and_free)) ~data:""; (* Step 1: Transmit base frame (red) - matching Go's sequence *) let red_frame = solid_color_rgba ~width ~height ~r:255 ~g:0 ~b:0 ~a:255 in send (K.Command.transmit ~image_id ~format:`Rgba32 ~width ~height ~quiet:`Errors_only ()) ~data:red_frame; (* Step 2: Add frame (orange) with 100ms gap - like Go *) let orange_frame = solid_color_rgba ~width ~height ~r:255 ~g:165 ~b:0 ~a:255 in send (K.Command.frame ~image_id ~format:`Rgba32 ~width ~height ~frame:(K.Frame.make ~gap_ms:100 ~composition:`Overwrite ()) ~quiet:`Errors_only ()) ~data:orange_frame; (* Step 3: Add frame (yellow) *) let yellow_frame = solid_color_rgba ~width ~height ~r:255 ~g:255 ~b:0 ~a:255 in send (K.Command.frame ~image_id ~format:`Rgba32 ~width ~height ~frame:(K.Frame.make ~gap_ms:100 ~composition:`Overwrite ()) ~quiet:`Errors_only ()) ~data:yellow_frame; (* Step 4: Add frame (green) *) let green_frame = solid_color_rgba ~width ~height ~r:0 ~g:255 ~b:0 ~a:255 in send (K.Command.frame ~image_id ~format:`Rgba32 ~width ~height ~frame:(K.Frame.make ~gap_ms:100 ~composition:`Overwrite ()) ~quiet:`Errors_only ()) ~data:green_frame; (* Step 5: Create placement - exactly like Go *) send (K.Command.display ~image_id ~placement:(K.Placement.make ~placement_id:1 ~cell_x_offset:0 ~cell_y_offset:0 ~cursor:`Static ()) ~quiet:`Errors_only ()) ~data:""; (* Step 6: Start animation - exactly like Go (NO root frame gap) *) send (K.Command.animate ~image_id (K.Animation.set_state ~loops:1 `Run)) ~data:""; print_endline ""; print_endline "Tiny animation (20x20) - Red -> Orange -> Yellow -> Green"; print_endline "This uses no chunking. Press Enter to stop..."; flush stdout; let _ = read_line () in (* Stop animation *) send (K.Command.animate ~image_id (K.Animation.set_state `Stop)) ~data:""; (* Clean up *) send (K.Command.delete ~quiet:`Errors_only (`All_visible_and_free)) ~data:""; print_endline "Done."