From 7707ff626c4066c181db2d8f301674a3af749e62 Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Fri, 27 Sep 2013 01:59:57 -0400 Subject: [PATCH] Loop indefinitely, in full screen. --- polymorphic-life/001/src/polymorphic_life.ml | 25 +++++++++++--------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/polymorphic-life/001/src/polymorphic_life.ml b/polymorphic-life/001/src/polymorphic_life.ml index a5e39c0..1b77a05 100644 --- a/polymorphic-life/001/src/polymorphic_life.ml +++ b/polymorphic-life/001/src/polymorphic_life.ml @@ -153,28 +153,31 @@ module Conway : CELL = struct end -let main rs ks () = - Random.self_init (); - let grid = Matrix.create ~rs ~ks ~data:() |> Matrix.map ~f:Conway.create in +let rec loop bar grid = + print_endline bar; Matrix.print grid ~to_string:Conway.to_string; - print_endline (String.make 80 '-'); + print_endline bar; let grid = Matrix.mapi grid ~f:(fun point ~data:cell -> let neighbors = Matrix.get_neighbors grid point in Conway.react cell ~states:(List.map neighbors ~f:Conway.state) ) in - Matrix.print grid ~to_string:Conway.to_string + Unix.sleep 1; + loop bar grid + + +let main () = + Random.self_init (); + let rs, ks = Or_error.ok_exn Linux_ext.get_terminal_size () in + Matrix.create ~rs:(rs - 3) ~ks ~data:() + |> Matrix.map ~f:Conway.create + |> loop (String.make ks '-') let spec = let summary = "Polymorphic Cellular Automata" in - let spec = - let open Command.Spec in - empty - +> flag "-rows" (optional_with_default 5 int) ~doc:"Height" - +> flag "-cols" (optional_with_default 5 int) ~doc:"Width" - in + let spec = Command.Spec.empty in Command.basic ~summary spec main -- 2.20.1