Skip to content

Commit

Permalink
18-2 now prints PNGs
Browse files Browse the repository at this point in the history
Make sure to set wantToPrint to True and make the screenshots folder if you want images!
  • Loading branch information
koosvary committed Dec 18, 2024
1 parent a03ca9e commit 36677c9
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions 2024/18/18-2.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
import sys
import networkx as nx
import matplotlib.pyplot as plt

testing = False
fewestSteps = sys.maxsize
wantToPrint = False

def printGraph():
def printGraph(filename, path = None):
if not wantToPrint:
return

pos = {point: point for point in map}
fig, ax = plt.subplots()
inches = width if testing else 30 # max 3000x3000px
fig.set_size_inches(inches, inches)
nx.draw(g, pos=pos, node_color='k', ax=ax)
nx.draw(g, pos=pos, node_size=750, ax=ax, with_labels=True) # draw nodes and edges
nx.draw(g, pos=pos, ax=ax, with_labels=testing, font_weight='bold') # draw nodes and edges
ax.set_xlim(-1,width)
ax.set_ylim(-1,height)
if path is not None:
path_edges = list(zip(path,path[1:]))
nx.draw_networkx_nodes(g, pos, nodelist=path, node_color='r')
nx.draw_networkx_edges(g, pos, edgelist=path_edges, edge_color='r')
ax.tick_params(left=True, bottom=True, labelleft=True, labelbottom=True)
plt.show()

if filename is not None:
prefix = 'test_' if testing else ''
plt.savefig(f'2024/18/screenshots/{prefix}img_{str(filename+1).zfill(4)}.png', format='PNG', bbox_inches='tight')
plt.close()


if testing:
Expand Down Expand Up @@ -50,7 +62,9 @@ def printGraph():
for i, corruptedNode in enumerate(fallingBytes):
try:
path = nx.shortest_path(g, (0,0), (width-1, height-1))
printGraph(i, path)
except:
printGraph(i, None)
print(fallingBytes[i-1])
break

Expand Down

0 comments on commit 36677c9

Please sign in to comment.