diff --git a/a.out b/a.out index 6eb3c48..4711fa8 100755 Binary files a/a.out and b/a.out differ diff --git a/pretty_printing.cmi b/pretty_printing.cmi index e77d355..ac021a1 100644 Binary files a/pretty_printing.cmi and b/pretty_printing.cmi differ diff --git a/pretty_printing.cmo b/pretty_printing.cmo index 0d4d9be..805df6b 100644 Binary files a/pretty_printing.cmo and b/pretty_printing.cmo differ diff --git a/pretty_printing.ml b/pretty_printing.ml index 47ed0ae..863cc86 100644 --- a/pretty_printing.ml +++ b/pretty_printing.ml @@ -337,10 +337,75 @@ let fancy_dfs gr coords px bcls = (* --------------------------------------| TESTS |-------------------------------------- *) + +(* let gr = [|[|3; 5; 7|]; [|0|]; [|1; 7; 8|]; [|2; 6|]; [|0; 1; 3|]; [|6; 7|]; [|0; 1; 2|]; [|8|]; [|0; 7; 6|]; [||]; [||]; [|9|]|] ;; let (coords, map, blank_map, color_map, blank_color_map) = extremely_fancy_graph_printing gr 46 3 "SHOW" ;; fancy_dfs gr coords map blank_color_map ;; +*) -(* compilation command : ocamlfind ocamlc -linkpkg -package unix pretty_printing.ml *) \ No newline at end of file +(* --------------------------------------------------------------------------------------------------------- *) +(* --------------------------------------------------------------------------------------------------------- *) +(* --------------------------------------------------------------------------------------------------------- *) +(* --------------------------------------------------------------------------------------------------------- *) +open Graphics ;; + +type 'a tree = Leaf of 'a | Node of 'a * 'a tree * 'a tree ;; + +(* +STRUCT : (digit, xcoord, ycoord) +*) + +let rec pw x n = match n with + | 0 -> 1 + | 1 -> x + | k when k mod 2 = 0 -> let res = pw x (n/2) in res*res + | k -> let res = pw x (n/2) in res*res*x ;; + +let rec depth_of_tree t = match t with + | Leaf _ -> 1 + | Node (_, g, d) -> 1 + max (depth_of_tree g) (depth_of_tree d) ;; + +let fill_data te ystep sx sy r = + let depth = depth_of_tree te in + let res = Array.make (depth+1) [] in + let rec aux t cur_x cur_d spacing = match t with + | Node (x, g, d) -> begin + aux g (cur_x - spacing) (cur_d+1) (spacing/2); + res.(cur_d) <- ((x, (cur_x, sy - r - ystep * cur_d)))::(res.(cur_d)); + aux d (cur_x + spacing) (cur_d+1) (spacing/2); + end + | Leaf x -> begin + res.(cur_d) <- ((x, (cur_x, sy - r - ystep * cur_d)))::(res.(cur_d)); + end + in aux te (sx/2) 0 (r/2 + r * ((pw 2 (depth-1)) - 1)); res ;; + +let rec draw_list l d r = match l with + | [] -> () + | h::t -> draw_circle (fst (snd h)) (snd (snd h)) r; draw_list t d r ;; + +let even_more_pretty_printing t r ystep = + open_graph " 1600x800" ; + let sx = Graphics.size_x () in + let sy = Graphics.size_y () in + + let graphdata = fill_data t ystep sx sy r in + + print_int 3; + + for dpth = 0 to (Array.length graphdata -1) do + draw_list graphdata.(dpth) dpth r + done; + + ignore (Sys.command "sleep 1"); + + close_graph () ; + () ;; + +even_more_pretty_printing (Node (2, Node (3, Leaf 1, Leaf 6), Node (9, Leaf 0, Node (4, Leaf 0, Node (2, Leaf 5, Leaf 2))))) 25 100 ; + +(* compilation command : ocamlfind ocamlc -linkpkg -package unix -linkpkg -package graphics pretty_printing.ml *) +print_int 0 ;; +print_char '\n' ;; \ No newline at end of file