let initial () = { board = Automata.initial (module M); n = None; pos = (0, 0); current = M.default }
let render { board; current; pos = px, py; _ } =
- for x = 0 to (Graphics.size_x () / 16) + 1 do
- for y = 0 to (Graphics.size_y () / 16) + 1 do
+ let w = (Graphics.size_x () / 16) + 1
+ and h = (Graphics.size_y () / 16) + 1 in
+ let wx = px - (w / 2)
+ and wy = py - (h / 2) in
+ for x = wx to wx + w do
+ for y = wy to wy + h do
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 * 16) (y * 16) 16 16;
+ Graphics.fill_rect ((x - wx) * 16) ((y - wy) * 16) 16 16;
Graphics.set_color (Graphics.rgb 127 127 127);
- Graphics.draw_rect (x * 16) (y * 16) 16 16
+ Graphics.draw_rect ((x - wx) * 16) ((y - wy) * 16) 16 16
done
done;
let r, g, b = M.color current 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 ((px * 16) + 5) ((py * 16) + 5) 6 6;
+ Graphics.fill_rect (((px - wx) * 16) + 5) (((py - wy) * 16) + 5) 6 6;
Graphics.set_color (Graphics.rgb 127 127 127);
- Graphics.draw_rect ((px * 16) + 5) ((py * 16) + 5) 6 6
+ Graphics.draw_rect (((px - wx) * 16) + 5) (((py - wy) * 16) + 5) 6 6
let update st =
let set_current ({ board; pos = x, y; current; _ } as st) =