prettier weighted graph display
This commit is contained in:
parent
fab702b4a5
commit
5b24934b4f
BIN
graphs.cmi
BIN
graphs.cmi
Binary file not shown.
BIN
graphs.cmo
BIN
graphs.cmo
Binary file not shown.
25
graphs.ml
25
graphs.ml
|
@ -31,9 +31,9 @@ let draw_integer x0 y n0 r =
|
||||||
let n = ref n0 in
|
let n = ref n0 in
|
||||||
let size = ln10 n0 in
|
let size = ln10 n0 in
|
||||||
let len = r/3 in
|
let len = r/3 in
|
||||||
let offset = (size-1)*(len/2) in
|
let offset = size*(len*11/7)/2 in
|
||||||
for i = 0 to size do
|
for i = 0 to size do
|
||||||
let x = x0 - (-(1 - delta size 0)*8 - offset + i * (len+8)) in
|
let x = x0 + offset - i*(len*11/7) in
|
||||||
if Array.mem (!n mod 10) [|0; 4; 5; 6; 7; 8; 9|] then
|
if Array.mem (!n mod 10) [|0; 4; 5; 6; 7; 8; 9|] then
|
||||||
draw_poly_line [|(x-len/2, y+len); (x-len/2, y)|];
|
draw_poly_line [|(x-len/2, y+len); (x-len/2, y)|];
|
||||||
|
|
||||||
|
@ -222,7 +222,8 @@ let another_type_of_graph_printing (gr : type2graph) r d is_weighted =
|
||||||
let roff = (6*r)/5 in
|
let roff = (6*r)/5 in
|
||||||
let roff2 = (7*r)/5 in
|
let roff2 = (7*r)/5 in
|
||||||
let rsize = (3*r)/4 in
|
let rsize = (3*r)/4 in
|
||||||
let wcolor = rgb 32 255 32 in
|
let wcolor = rgb 255 255 255 in
|
||||||
|
let bcolor = rgb 0 0 0 in
|
||||||
|
|
||||||
set_line_width 8;
|
set_line_width 8;
|
||||||
for i = 0 to gr.width -1 do
|
for i = 0 to gr.width -1 do
|
||||||
|
@ -230,7 +231,7 @@ let another_type_of_graph_printing (gr : type2graph) r d is_weighted =
|
||||||
let node_xy = ((r + (2*r + d)*i), (r + (2*r + d)*j)) in
|
let node_xy = ((r + (2*r + d)*i), (r + (2*r + d)*j)) in
|
||||||
if (i > 0 && j > 0) && gr.g.(i).(j).edges.(0) <> (-1) then begin (* SO *)
|
if (i > 0 && j > 0) && gr.g.(i).(j).edges.(0) <> (-1) then begin (* SO *)
|
||||||
if is_weighted then begin
|
if is_weighted then begin
|
||||||
set_color white;
|
set_color bcolor;
|
||||||
fill_circle (fst node_xy - roff) (snd node_xy - roff) (3*rsize/4) ;
|
fill_circle (fst node_xy - roff) (snd node_xy - roff) (3*rsize/4) ;
|
||||||
set_color wcolor;
|
set_color wcolor;
|
||||||
set_line_width 3;
|
set_line_width 3;
|
||||||
|
@ -245,7 +246,7 @@ let another_type_of_graph_printing (gr : type2graph) r d is_weighted =
|
||||||
|
|
||||||
if (i > 0) && gr.g.(i).(j).edges.(1) <> (-1) then begin (* O *)
|
if (i > 0) && gr.g.(i).(j).edges.(1) <> (-1) then begin (* O *)
|
||||||
if is_weighted then begin
|
if is_weighted then begin
|
||||||
set_color white;
|
set_color bcolor;
|
||||||
fill_circle (fst node_xy - roff2) (snd node_xy) (3*rsize/4) ;
|
fill_circle (fst node_xy - roff2) (snd node_xy) (3*rsize/4) ;
|
||||||
set_color wcolor;
|
set_color wcolor;
|
||||||
set_line_width 3;
|
set_line_width 3;
|
||||||
|
@ -260,7 +261,7 @@ let another_type_of_graph_printing (gr : type2graph) r d is_weighted =
|
||||||
|
|
||||||
if (i > 0 && j < gr.height -1) && gr.g.(i).(j).edges.(2) <> (-1) then begin (* NO *)
|
if (i > 0 && j < gr.height -1) && gr.g.(i).(j).edges.(2) <> (-1) then begin (* NO *)
|
||||||
if is_weighted then begin
|
if is_weighted then begin
|
||||||
set_color white;
|
set_color bcolor;
|
||||||
fill_circle (fst node_xy - roff) (snd node_xy + roff) (3*rsize/4) ;
|
fill_circle (fst node_xy - roff) (snd node_xy + roff) (3*rsize/4) ;
|
||||||
set_color wcolor;
|
set_color wcolor;
|
||||||
set_line_width 3;
|
set_line_width 3;
|
||||||
|
@ -275,7 +276,7 @@ let another_type_of_graph_printing (gr : type2graph) r d is_weighted =
|
||||||
|
|
||||||
if (j < gr.height -1) && gr.g.(i).(j).edges.(3) <> (-1) then begin (* N *)
|
if (j < gr.height -1) && gr.g.(i).(j).edges.(3) <> (-1) then begin (* N *)
|
||||||
if is_weighted then begin
|
if is_weighted then begin
|
||||||
set_color white;
|
set_color bcolor;
|
||||||
fill_circle (fst node_xy) (snd node_xy + roff2) (3*rsize/4) ;
|
fill_circle (fst node_xy) (snd node_xy + roff2) (3*rsize/4) ;
|
||||||
set_color wcolor;
|
set_color wcolor;
|
||||||
set_line_width 3;
|
set_line_width 3;
|
||||||
|
@ -290,7 +291,7 @@ let another_type_of_graph_printing (gr : type2graph) r d is_weighted =
|
||||||
|
|
||||||
if (i < gr.width-1 && j < gr.height -1) && gr.g.(i).(j).edges.(4) <> (-1) then begin (* NE *)
|
if (i < gr.width-1 && j < gr.height -1) && gr.g.(i).(j).edges.(4) <> (-1) then begin (* NE *)
|
||||||
if is_weighted then begin
|
if is_weighted then begin
|
||||||
set_color white;
|
set_color bcolor;
|
||||||
fill_circle (fst node_xy + roff) (snd node_xy + roff) (3*rsize/4) ;
|
fill_circle (fst node_xy + roff) (snd node_xy + roff) (3*rsize/4) ;
|
||||||
set_color wcolor;
|
set_color wcolor;
|
||||||
set_line_width 3;
|
set_line_width 3;
|
||||||
|
@ -305,7 +306,7 @@ let another_type_of_graph_printing (gr : type2graph) r d is_weighted =
|
||||||
|
|
||||||
if (i < gr.width-1) && gr.g.(i).(j).edges.(5) <> (-1) then begin (* E *)
|
if (i < gr.width-1) && gr.g.(i).(j).edges.(5) <> (-1) then begin (* E *)
|
||||||
if is_weighted then begin
|
if is_weighted then begin
|
||||||
set_color white;
|
set_color bcolor;
|
||||||
fill_circle (fst node_xy + roff2) (snd node_xy) (3*rsize/4) ;
|
fill_circle (fst node_xy + roff2) (snd node_xy) (3*rsize/4) ;
|
||||||
set_color wcolor;
|
set_color wcolor;
|
||||||
set_line_width 3;
|
set_line_width 3;
|
||||||
|
@ -320,7 +321,7 @@ let another_type_of_graph_printing (gr : type2graph) r d is_weighted =
|
||||||
|
|
||||||
if (i < gr.width-1 && j > 0) && gr.g.(i).(j).edges.(6) <> (-1) then begin (* SE *)
|
if (i < gr.width-1 && j > 0) && gr.g.(i).(j).edges.(6) <> (-1) then begin (* SE *)
|
||||||
if is_weighted then begin
|
if is_weighted then begin
|
||||||
set_color white;
|
set_color bcolor;
|
||||||
fill_circle (fst node_xy + roff) (snd node_xy - roff) (3*rsize/4) ;
|
fill_circle (fst node_xy + roff) (snd node_xy - roff) (3*rsize/4) ;
|
||||||
set_color wcolor;
|
set_color wcolor;
|
||||||
set_line_width 3;
|
set_line_width 3;
|
||||||
|
@ -335,7 +336,7 @@ let another_type_of_graph_printing (gr : type2graph) r d is_weighted =
|
||||||
|
|
||||||
if (j > 0) && gr.g.(i).(j).edges.(7) <> (-1) then begin (* S *)
|
if (j > 0) && gr.g.(i).(j).edges.(7) <> (-1) then begin (* S *)
|
||||||
if is_weighted then begin
|
if is_weighted then begin
|
||||||
set_color white;
|
set_color bcolor;
|
||||||
fill_circle (fst node_xy) (snd node_xy - roff2) (3*rsize/4) ;
|
fill_circle (fst node_xy) (snd node_xy - roff2) (3*rsize/4) ;
|
||||||
set_color wcolor;
|
set_color wcolor;
|
||||||
set_line_width 3;
|
set_line_width 3;
|
||||||
|
@ -832,7 +833,7 @@ let another_type_of_bfs (gr : type2graph) r d =
|
||||||
open_graph " 1200x800" ;;
|
open_graph " 1200x800" ;;
|
||||||
set_window_title "Graphs" ;;
|
set_window_title "Graphs" ;;
|
||||||
|
|
||||||
let type2 = generate_type2_graph 7 5 40 1 10 ;;
|
let type2 = generate_type2_graph 7 5 40 1 100 ;;
|
||||||
|
|
||||||
another_type_of_graph_printing type2 35 100 true ;;
|
another_type_of_graph_printing type2 35 100 true ;;
|
||||||
(*another_type_of_dfs type2 35 75 ;;*)
|
(*another_type_of_dfs type2 35 75 ;;*)
|
||||||
|
|
Loading…
Reference in New Issue