My agentic slop goes here. Not intended for anyone else!
1(* Minimal animation test - shows exact bytes sent *)
2
3module K = Kgp
4
5let solid_color_rgba ~width ~height ~r ~g ~b ~a =
6 let pixels = Bytes.create (width * height * 4) in
7 for i = 0 to (width * height) - 1 do
8 let idx = i * 4 in
9 Bytes.set pixels idx (Char.chr r);
10 Bytes.set pixels (idx + 1) (Char.chr g);
11 Bytes.set pixels (idx + 2) (Char.chr b);
12 Bytes.set pixels (idx + 3) (Char.chr a)
13 done;
14 Bytes.to_string pixels
15
16let send cmd ~data =
17 print_string (K.Command.to_string cmd ~data);
18 flush stdout
19
20let () =
21 let width, height = 40, 40 in (* Smaller for faster testing *)
22 let image_id = 500 in
23
24 (* Clear any existing image *)
25 send (K.Command.delete ~quiet:`Errors_only (`All_visible_and_free)) ~data:"";
26
27 (* Step 1: Transmit base frame (red) *)
28 let red_frame = solid_color_rgba ~width ~height ~r:255 ~g:0 ~b:0 ~a:255 in
29 send
30 (K.Command.transmit
31 ~image_id
32 ~format:`Rgba32
33 ~width ~height
34 ~quiet:`Errors_only
35 ())
36 ~data:red_frame;
37
38 (* Step 2: Add frame (blue) *)
39 let blue_frame = solid_color_rgba ~width ~height ~r:0 ~g:0 ~b:255 ~a:255 in
40 send
41 (K.Command.frame
42 ~image_id
43 ~format:`Rgba32
44 ~width ~height
45 ~frame:(K.Frame.make ~gap_ms:500 ~composition:`Overwrite ())
46 ~quiet:`Errors_only
47 ())
48 ~data:blue_frame;
49
50 (* Step 3: Add frame (green) *)
51 let green_frame = solid_color_rgba ~width ~height ~r:0 ~g:255 ~b:0 ~a:255 in
52 send
53 (K.Command.frame
54 ~image_id
55 ~format:`Rgba32
56 ~width ~height
57 ~frame:(K.Frame.make ~gap_ms:500 ~composition:`Overwrite ())
58 ~quiet:`Errors_only
59 ())
60 ~data:green_frame;
61
62 (* Step 4: Create placement *)
63 send
64 (K.Command.display
65 ~image_id
66 ~placement:(K.Placement.make
67 ~placement_id:1
68 ~cursor:`Static
69 ())
70 ~quiet:`Errors_only
71 ())
72 ~data:"";
73
74 (* Step 5: Set root frame gap - IMPORTANT: root frame has no gap by default *)
75 send
76 (K.Command.animate ~image_id (K.Animation.set_gap ~frame:1 ~gap_ms:500))
77 ~data:"";
78
79 (* Step 6: Start animation *)
80 send
81 (K.Command.animate ~image_id (K.Animation.set_state ~loops:1 `Run))
82 ~data:"";
83
84 print_endline "";
85 print_endline "Animation should be playing (red -> blue -> green).";
86 print_endline "Press Enter to stop...";
87 flush stdout;
88 let _ = read_line () in
89
90 (* Stop animation *)
91 send
92 (K.Command.animate ~image_id (K.Animation.set_state `Stop))
93 ~data:"";
94
95 (* Clean up *)
96 send (K.Command.delete ~quiet:`Errors_only (`All_visible_and_free)) ~data:"";
97 print_endline "Done."