-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNode.py
32 lines (27 loc) · 1.18 KB
/
Node.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import pygame, sys, random
import pygame.locals as pl
import pygame.event as pe
from Graph import *
# Node class for creating and drawing new nodes
class Node:
def __init__(self, window, color, pos=(0, 0), text = '', data = 0,display = False):
self.window = window
self.color = color
self.pos = pos
self.text = text
self.data = data
self.display = display
def draw(self, outline_color = (0, 0, 0)):
if self.display:
pygame.draw.circle(self.window, outline_color, self.pos, 22, 3)
pygame.draw.circle(self.window, self.color, self.pos, 20)
if self.text != '':
font = pygame.font.SysFont('Times New Roman', 15)
text = font.render(self.text, 1, (0, 0, 0))
self.window.blit(text, (self.pos[0] - text.get_width() / 2, self.pos[1] - text.get_height() / 2))
def isOver(self, pos):
if pos[0] > (self.pos[0] - 45) and pos[0] < (self.pos[0] + 45):
if pos[1] > (self.pos[1] - 45) and pos[1] < (self.pos[1] + 45):
if (((pos[0] - self.pos[0]) ** 2 + (pos[1] - self.pos[1]) ** 2) ** 0.5) <= 45:
return True
return False