-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodelib.py
98 lines (86 loc) · 2.68 KB
/
nodelib.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# pylint: disable=no-member
from typing import Tuple
import pygame
import pygame.gfxdraw
class MetaNode:
"""Boilerplate class for creating nodes"""
def __init__(
self,
label: str,
coord_x: int,
coord_y: int,
node_size: int,
node_inner_color: Tuple[int, int, int],
node_border_color: Tuple[int, int, int],
) -> None:
self.label = label
self.rel_coord_x = coord_x
self.rel_coord_y = coord_y
self.node_size = node_size
self.node_inner_color = node_inner_color
self.node_border_color = node_border_color
self.surf = pygame.Surface(
(self.node_size + 2, self.node_size + 2), pygame.SRCALPHA
)
# pygame.draw.circle(
# self.surf,
# self.node_inner_color,
# (self.node_size / 2, self.node_size / 2),
# self.node_size / 2,
# 0,
# )
pygame.gfxdraw.filled_circle(
self.surf,
self.node_size // 2,
self.node_size // 2,
self.node_size // 2,
self.node_inner_color,
)
# pygame.draw.circle(
# self.surf,
# (255, 255, 255),
# (self.node_size / 2, self.node_size / 2),
# self.node_size / 5,
# 0,
# )
pygame.gfxdraw.filled_circle(
self.surf,
self.node_size // 2,
self.node_size // 2,
self.node_size // 5,
(255, 255, 255),
)
# pygame.draw.circle(
# self.surf,
# self.node_border_color,
# (self.node_size // 2, self.node_size // 2),
# self.node_size // 2,
# 2,
# )
pygame.gfxdraw.circle(
self.surf,
self.node_size // 2,
self.node_size // 2,
self.node_size // 2,
self.node_border_color,
)
def draw(self) -> pygame.Surface:
"""Draws the node on the screen"""
return self.surf
class Node(MetaNode):
"""Class for creating nodes"""
node_size: int = 14
node_inner_color: Tuple[int, int, int] = (255, 0, 0)
node_border_color: Tuple[int, int, int] = (0, 0, 0)
def __init__(self, label: str, coord_x: int, coord_y: int) -> None:
self.label = label
self.rel_coord_x = coord_x
self.rel_coord_y = coord_y
super().__init__(
label,
coord_x,
coord_y,
self.node_size,
self.node_inner_color,
self.node_border_color,
)