(* Debug: Output animation escape sequences for comparison with Go *) 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 = let s = K.Command.to_string cmd ~data in (* Print escaped version for debugging *) String.iter (fun c -> let code = Char.code c in if code = 27 then print_string "\\x1b" else if code < 32 || code > 126 then Printf.printf "\\x%02x" code else print_char c ) s; print_newline () let () = let width, height = 80, 80 in let image_id = 300 in print_endline "=== OCaml Animation Debug ===\n"; (* Step 1: Transmit base frame *) print_endline "1. Transmit base frame (a=t):"; 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; print_newline (); (* Step 2: Add frame *) print_endline "2. Add frame (a=f):"; 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; print_newline (); (* Step 3: Put/display placement *) print_endline "3. Create placement (a=p):"; 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:""; print_newline (); (* Step 4: Set root frame gap *) print_endline "4. Set root frame gap (a=a,r=1,z=100):"; send (K.Command.animate ~image_id (K.Animation.set_gap ~frame:1 ~gap_ms:100)) ~data:""; print_newline (); (* Step 5: Animate *) print_endline "5. Start animation (a=a,s=3,v=1):"; send (K.Command.animate ~image_id (K.Animation.set_state ~loops:1 `Run)) ~data:""; print_newline (); (* Step 6: Stop animation *) print_endline "6. Stop animation:"; send (K.Command.animate ~image_id (K.Animation.set_state `Stop)) ~data:""