From 427f50d3c93432ff85caac923fac10191d519d49 Mon Sep 17 00:00:00 2001 From: HactarCE <6060305+HactarCE@users.noreply.github.com> Date: Sun, 26 Nov 2023 22:01:00 -0500 Subject: Add graph visualization --- graphviz.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 graphviz.py (limited to 'graphviz.py') diff --git a/graphviz.py b/graphviz.py new file mode 100644 index 0000000..24ee41b --- /dev/null +++ b/graphviz.py @@ -0,0 +1,23 @@ +# Paste output into https://dreampuf.github.io/GraphvizOnline/ +# +# 'circo' or 'dot' tend to look best + +COLORS = ['#1E88E5', '#D81B60', '#FFC107', '#004D40'] +USE_EDGE_COLORS = False + +graph = [(0,1),(0,2),(0,3),(0,4),(1,2),(1,3),(2,3),(2,4),(3,4)] +coloring = '0011011011' + +node_count = len(coloring) // 2 +node_colors = [COLORS[int(coloring[i*2:i*2+2], 2)] for i in range(node_count)] + +print('graph G {') +print(' node [style="filled" label="" color="white" shape="circle"]') +for i in range(len(coloring) // 2): + print(f' {i} [fillcolor="{node_colors[i]}"];') +for a, b in graph: + if USE_EDGE_COLORS: + print(f' {a} -- {b} [color="{node_colors[a]};0.5:{node_colors[b]}"];') + else: + print(f' {a} -- {b};') +print('}') -- cgit v1.3