-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathframe.py
More file actions
57 lines (49 loc) · 1.89 KB
/
frame.py
File metadata and controls
57 lines (49 loc) · 1.89 KB
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
import pygame
class Frame:
"""
This class will be responsible for the sorting frame and blocks configuration
"""
BLOCK_COLORS = {
"BLUE" : (0, 0, 255),
"WHITE":"#faf0e6",
"GREEN" : (0, 255, 0),
"RED" : (255, 0, 0),
"ORANGE": (255,165,0)
}
def __init__(self, x, y, frame_width, frame_height):
self.GAP = 1
self.x = x
self.y = y
self.frame_width = frame_width
self.frame_height = frame_height
self.BACKGROUND_COLOR = (0,0,0)#(24,25,29)
def draw_frame(self, screen):
pygame.draw.rect(screen, self.BACKGROUND_COLOR, (self.x, self.y, self.frame_width, self.frame_height))
def draw_list(self, screen, lst, screen_height, colors={}, sorted_elements={}):
"""
Draw and coloring the blocks
:param screen -> pygame display
:param lst -> list()
:param screen_height -> int
:param colors -> dict: for getting the colors of sorting blocks
:param sorted_elements -> dict: for getting the orange color of sorted blocks
:return:
"""
self.block_width = (self.frame_width - ( (len(lst) - 1) * self.GAP) ) / len(lst)
self.block_height = self.frame_height // (len(lst))
for i, val in enumerate(lst):
if i > 0:
block_x += self.GAP + self.block_width
else:
block_x = self.x
if i in colors:
c = colors[i]
color = self.BLOCK_COLORS[c]
else:
color = self.BLOCK_COLORS["WHITE"]
if val in sorted_elements:
c = sorted_elements[val]
color = self.BLOCK_COLORS[c]
block_y = screen_height - self.block_height * val
pygame.draw.rect(screen, color,
(block_x, block_y, self.block_width, self.frame_height) , 0)