(* Minimal animation test - shows exact bytes sent *) 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 () = let width, height = 40, 40 in (* Smaller for faster testing *) let image_id = 500 in (* Clear any existing image *) send (K.Command.delete ~quiet:`Errors_only (`All_visible_and_free)) ~data:""; (* Step 1: Transmit base frame (red) *) 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 (blue) *) let blue_frame = solid_color_rgba ~width ~height ~r:0 ~g:0 ~b:255 ~a:255 in send (K.Command.frame ~image_id ~format:`Rgba32 ~width ~height ~frame:(K.Frame.make ~gap_ms:500 ~composition:`Overwrite ()) ~quiet:`Errors_only ()) ~data:blue_frame; (* Step 3: 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:500 ~composition:`Overwrite ()) ~quiet:`Errors_only ()) ~data:green_frame; (* Step 4: Create placement *) send (K.Command.display ~image_id ~placement:(K.Placement.make ~placement_id:1 ~cursor:`Static ()) ~quiet:`Errors_only ()) ~data:""; (* Step 5: Set root frame gap - IMPORTANT: root frame has no gap by default *) send (K.Command.animate ~image_id (K.Animation.set_gap ~frame:1 ~gap_ms:500)) ~data:""; (* Step 6: Start animation *) send (K.Command.animate ~image_id (K.Animation.set_state ~loops:1 `Run)) ~data:""; print_endline ""; print_endline "Animation should be playing (red -> blue -> green)."; print_endline "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."