module Normal (M : Automata.Automaton) = struct
module rec Impl : (Mode with type initer = unit) = struct
- type state = { board: M.t Automata.board; n: int option; pos: int * int; current: M.t }
+ type state = { board: M.t Automata.board; n: int option; pos: int * int; current: M.t; size : int }
type initer = unit
- let initial () = { board = Automata.initial (module M); n = None; pos = (0, 0); current = M.default }
+ let initial () = { board = Automata.initial (module M); n = None; pos = (0, 0); current = M.default; size = 16 }
- let render { board; current; pos = px, py; _ } =
- let w = (Graphics.size_x () / 16) + 1
- and h = (Graphics.size_y () / 16) + 1 in
+ let render { board; current; pos = px, py; size; _ } =
+ let w = (Graphics.size_x () / size) + 1
+ and h = (Graphics.size_y () / size) + 1 in
let wx = px - (w / 2)
and wy = py - (h / 2) in
for x = wx to wx + w 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 - wx) * 16) ((y - wy) * 16) 16 16;
+ Graphics.fill_rect ((x - wx) * size) ((y - wy) * size) size size;
Graphics.set_color (Graphics.rgb 127 127 127);
- Graphics.draw_rect ((x - wx) * 16) ((y - wy) * 16) 16 16
+ Graphics.draw_rect ((x - wx) * size) ((y - wy) * size) size size
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 - wx) * 16) + 5) (((py - wy) * 16) + 5) 6 6;
+ Graphics.fill_rect (((px - wx) * size) + 5) (((py - wy) * size) + 5) (max (size - 10) 1) (max (size - 10) 1);
Graphics.set_color (Graphics.rgb 127 127 127);
- Graphics.draw_rect (((px - wx) * 16) + 5) (((py - wy) * 16) + 5) 6 6
+ Graphics.draw_rect (((px - wx) * size) + 5) (((py - wy) * size) + 5) (max (size - 10) 1) (max (size - 10) 1)
let update st =
let set_current ({ board; pos = x, y; current; _ } as st) =
{ st with board = Automata.set x y current board }
in
let chpos dx dy ({ pos = x, y; _ } as st) = { st with pos = (x + dx, y + dy) } in
+ let chsize ds ({ size; _ } as st) = { st with size = max (size + ds) 1 } in
let chcur f st = { st with current = f st.current } in
let chnum d st = { st with n = Some ((Option.value st.n ~default:0 * 10) + d) } in
let rec ntimes f st =
| 'h' -> Either.left (ntimes (chpos (-1) 0) st)
| 'j' -> Either.left (ntimes (chpos 0 (-1)) st)
| 'l' -> Either.left (ntimes (chpos 1 0) st)
+ | 'i' -> Either.left (ntimes (chsize 1) st)
+ | 'o' -> Either.left (ntimes (chsize (-1)) st)
| _ -> Either.left st
end