summaryrefslogtreecommitdiff
path: root/src/builder.py
diff options
context:
space:
mode:
authorSimponic <loganthebean222@gmail.com>2020-12-10 18:10:51 -0700
committerSimponic <loganthebean222@gmail.com>2020-12-10 18:10:51 -0700
commit0ea46a3d721bdefab70f24c4c5573ff568a56cab (patch)
treeb2d1ef05fefc1ab5a7464929127a37064a58eccd /src/builder.py
parent7868c17358f3014e6d9203250083f407419f5c46 (diff)
downloadgraph-explorer-0ea46a3d721bdefab70f24c4c5573ff568a56cab.tar.gz
graph-explorer-0ea46a3d721bdefab70f24c4c5573ff568a56cab.zip
Added files
Diffstat (limited to 'src/builder.py')
-rw-r--r--src/builder.py77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/builder.py b/src/builder.py
new file mode 100644
index 0000000..3c79d1b
--- /dev/null
+++ b/src/builder.py
@@ -0,0 +1,77 @@
+import pygame
+from Graph import Graph
+from Node import Node
+from globals import *
+
+def main():
+ pygame.init()
+ screen = pygame.display.set_mode((WIDTH, HEIGHT))
+ clock = pygame.time.Clock()
+
+ running = True
+# graph = Graph(screen, file="copy.txt")
+# graph.fromFile(False)
+ graph = Graph(screen)
+ isNodeUnderMouse = False
+ node1 = None
+ node2 = None
+
+ while (running):
+ isNodeUnderMouse = False
+ for event in pygame.event.get():
+ if event.type == pygame.QUIT:
+ file = open(input("Where would you like to save the graph: "),"w")
+ for i in graph.links:
+ file.write(i[0].text + " " + i[1].text + " " + str(i[2]) + " " + i[3] + "\n")
+ file.close()
+ running = False
+ if event.type == pygame.KEYDOWN:
+ if event.key == pygame.K_f:
+ find = input("Name of node: ")
+ for i in graph.nodes:
+ if i.text == find:
+ i.color = BLUE
+ if event.type == pygame.MOUSEBUTTONUP:
+ mouseX, mouseY = pygame.mouse.get_pos()
+ for i in graph.nodes:
+ if(mouseX > i.pos[0] - i.radius and \
+ mouseY > i.pos[1] - i.radius and \
+ mouseX < i.pos[0] + i.radius and \
+ mouseY < i.pos[1] + i.radius):
+ graph.drawLinks(i)
+ if (node1):
+ node2 = i
+ description = input("Description of link between " + node1.text + " and " + node2.text + ": ")
+ if (description != "no"):
+ graph.links.append([node1, node2, 1.0, description])
+ node2 = None
+ node1 = None
+ elif (not node1 and not node2):
+ node1 = i
+ isNodeUnderMouse = True
+ if (not isNodeUnderMouse):
+ newNode = Node(pos=(mouseX, mouseY), vel=(0,0), text = input("New node text: "))
+ graph.nodes.append(newNode)
+ node1 , node2 = (None, None)
+ screen.fill(BLACK)
+
+ graph.draw()
+ mouseX, mouseY = pygame.mouse.get_pos()
+ for i in graph.nodes:
+ if(mouseX > i.pos[0] - i.radius and \
+ mouseY > i.pos[1] - i.radius and \
+ mouseX < i.pos[0] + i.radius and \
+ mouseY < i.pos[1] + i.radius):
+ i.color = GREEN
+ if (i not in graph.nodesUnderMouse):
+ graph.nodesUnderMouse.append(i)
+ graph.drawLinks(i)
+ else:
+ if i in graph.nodesUnderMouse:
+ graph.nodesUnderMouse.remove(i)
+ if (i.color != BLUE):
+ i.color = RED
+ pygame.display.flip()
+ clock.tick(60)
+if __name__ == "__main__":
+ main()