X-Git-Url: https://git.xandkar.net/?p=cellular-automata.git;a=blobdiff_plain;f=polymorphism%2F001%2Fsrc%2Fpolymorphism.ml;h=af46bc59c2b730286bc6535dfcb2de15ae7b36e8;hp=c52df9338acb3fe610a43736212cc691502e784b;hb=21c4909c309089428292ce2850f2d4751da5634d;hpb=b91b5d786c3b94b51ccc8e1866c265eb58a86d53 diff --git a/polymorphism/001/src/polymorphism.ml b/polymorphism/001/src/polymorphism.ml index c52df93..af46bc5 100644 --- a/polymorphism/001/src/polymorphism.ml +++ b/polymorphism/001/src/polymorphism.ml @@ -197,6 +197,21 @@ module Conway : RULE = struct end +module Terminal : sig + val clear : unit -> unit + val reset : unit -> unit +end = struct + let ansi_code_clear = "\027[2J" (* Clear screen *) + let ansi_code_reset = "\027[1;1H" (* Reset cursor position *) + + let clear () = + print_string ansi_code_clear + + let reset () = + print_string ansi_code_reset +end + + module Automaton : sig type t @@ -227,6 +242,7 @@ end = struct ; data = Rule.create () } in + Terminal.clear (); { grid = Matrix.map ~f:init (Matrix.create ~rs ~ks ()) ; interval = Time.Span.of_float interval ; bar = String.make ks '-' @@ -236,6 +252,7 @@ end = struct cell.data.Cell.pheno let print t = + Terminal.reset (); print_endline t.bar; Matrix.print t.grid ~to_string:cell_to_string; print_endline t.bar