]> git.f4mnq.fr Git - cells.git/commitdiff
Dessin bien plus efficace des lignes entre les cases
authorAmélia Coutard-Sander <git@f4mnq.fr>
Wed, 7 Jan 2026 13:38:54 +0000 (14:38 +0100)
committerAmélia Coutard-Sander <git@f4mnq.fr>
Wed, 7 Jan 2026 13:53:54 +0000 (14:53 +0100)
bin/modes.ml

index 5e9c14c057ce60cda54c0a38a44c0e2dda0bd7ea..834c3c4ffc89cf7af7dca4c9ababe17fec1446a4 100644 (file)
@@ -49,8 +49,10 @@ let get_name (m : (module Automata.Automaton)) =
 
 let render_world (EditorState (m, { board; pos = px, py; size })) =
         let module M = (val m) in
-        let w = (Graphics.size_x () / size) + 1
-        and h = (Graphics.size_y () / size) + 1 in
+        let sx = Graphics.size_x ()
+        and sy = Graphics.size_y () in
+        let w = (sx / size) + 1
+        and h = (sy / size) + 1 in
         let wx = px - (w / 2)
         and wy = py - (h / 2) in
         for x = wx to wx + w do
@@ -58,12 +60,18 @@ let render_world (EditorState (m, { board; pos = px, py; size })) =
             let r, g, b = M.color (Automata.get x y board) in
             let r, g, b = (int_of_char r, int_of_char g, int_of_char b) in
             Graphics.set_color (Graphics.rgb r g b);
-            Graphics.fill_rect ((x - wx) * size) ((y - wy) * size) size size;
-            Graphics.set_color (Graphics.rgb 127 127 127);
-            Graphics.draw_rect ((x - wx) * size) ((y - wy) * size) size size
+            Graphics.fill_rect ((x - wx) * size) ((y - wy) * size) size size
           done
         done;
         Graphics.set_color (Graphics.rgb 127 127 127);
+        for x = 0 to w do
+          Graphics.moveto (x * size) 0;
+          Graphics.lineto (x * size) sy
+        done;
+        for y = 0 to h do
+          Graphics.moveto 0 (y * size);
+          Graphics.lineto sx (y * size)
+        done;
         Graphics.draw_rect (((px - wx) * size) + 1) (((py - wy) * size) + 1) (size - 2) (size - 2)
 
 module rec Command : (Mode with type initer = string) = struct