Some changes regarding diplay functions

This commit is contained in:
Alexandre 2024-05-19 23:16:03 +02:00
parent fea1fa9e0a
commit 3afa3e7e87
4 changed files with 46 additions and 9 deletions

BIN
a.out

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -146,6 +146,23 @@ let display mat cls =
print_char '\n'
done;;
let display_specific mat cls digit =
let colors = [|"\027[0m"; "\027[41m"; "\027[42m"; "\027[43m"; "\027[44m"; "\027[45m"; "\027[46m"; "\027[47m"; "\027[100m"; "\027[101m"; "\027[102m"; "\027[103m"; "\027[104m"; "\027[105m"; "\027[106m"; "\027[107m"|] in
for i = 0 to (Array.length mat -1) do
for j = 0 to (Array.length mat.(i) -1) do
if cls.(i).(j) <> digit then
print_string colors.(0)
else
print_string colors.(max 1 (cls.(i).(j) mod (Array.length colors)));
if mat.(i).(j) = '&' then
print_char ' '
else
print_char mat.(i).(j)
done;
print_string "\027[0m";
print_char '\n'
done;;
let extend mat cls i0 j0 dst =
let ni = Array.length mat in
let nj = Array.length mat.(0) in
@ -165,17 +182,19 @@ let extend mat cls i0 j0 dst =
done
done ;;
let extremely_fancy_graph_printing g size =
let identity x = x ;;
let extremely_fancy_graph_printing g size wmult mode =
(* creation of the image *)
let px = Array.make (size) [||] in
for i = 0 to (size-1) do
px.(i) <- Array.make (3*size) ' '
px.(i) <- Array.make (wmult*size) ' '
done;
(* color matrix *)
let cls = Array.make (size) [||] in
for i = 0 to (size-1) do
cls.(i) <- Array.make (3*size) 0
cls.(i) <- Array.make (wmult*size) 0
done;
let coords = Array.make size (0, 0) in
@ -189,9 +208,9 @@ let extremely_fancy_graph_printing g size =
if !j < 0 then j := 0 else ();
if !i >= size then i := size-1 else ();
if !j >= size then j := size-1 else ();
px.(!i).(3* !j) <- Char.chr (k + 48);
extend px cls !i (3* !j) 2;
coords.(k) <- (!i, 3* !j);
px.(!i).(wmult* !j) <- Char.chr (k + 48);
extend px cls !i (wmult* !j) 2;
coords.(k) <- (!i, wmult* !j);
done;
(* draw the connections *)
@ -202,11 +221,29 @@ let extremely_fancy_graph_printing g size =
done;
(* show the image *)
display px cls ;;
ignore (Sys.command "clear");
if mode = "SPECIFIC" then begin
Printf.printf "Enter the node you want to highlight (type -1 to show all; or -2 to exit)\n";
ignore (Sys.command "clear");
let nd = ref (-2) in
nd := Scanf.bscanf Scanf.Scanning.stdin "%d\n" identity;
if !nd >= 0 && !nd < Array.length g then
display_specific px cls (!nd+1)
else if !nd = -1 then
display px cls
else
()
end
else
display px cls ;;
let gr = [|[|1; 2|]; [|2; 3|]; [|0; 1; 3|]; [|0; 1; 4|]; [|2; 3|]; [||]; [||]|] ;;
let gr = [|[|3; 5; 7|]; [|0|]; [|1; 7; 8|]; [|2; 6|]; [|0; 1; 3|]; [|6; 7|]; [|0; 1; 2|]; [|8|]; [|0; 7; 6|]|] ;;
(*print_mat gr ;;*)
extremely_fancy_graph_printing gr 44 ;
extremely_fancy_graph_printing gr 44 4 "EVERYTHING" ;
(* ocamlfind ocamlc -linkpkg -package unix pretty_printing.ml *)