-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprintfuncs.py
102 lines (79 loc) · 2.69 KB
/
printfuncs.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
99
100
101
102
import os
os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
import pygame
import time
#visualizer popup screen dimensions must be divisible by 20
SCREEN_WIDTH = 600
SCREEN_HEIGHT = 600
#define array sizes based on screen size
SMALL = int(SCREEN_WIDTH/20)
MEDIUM = int(SCREEN_WIDTH/10)
LARGE = int(SCREEN_WIDTH/5)
#colors for pygame screen
background = (76, 86, 106)
foreground = (46, 52, 64)
red = (191, 97, 106)
green = (163, 190, 140)
#start function definitions
#check if a variable is an array list
def isList(l):
return type(l) == list
#draw the whole bar array
def drawBarArr(screen, arr, color, interval):
if isList(arr):
size = len(arr)
maxW, maxH = screen.get_width(), screen.get_height()
barWidth = int(maxW)/size
for j in range(size):
i = arr[j]
r = pygame.Rect(j*barWidth, maxH-i, barWidth, i)
drawBar(screen, r, color)
pygame.display.flip()
pygame.time.delay(interval)
#erase and redraw two specific bars
def drawSwap(screen, arr, x, y):
#get maximum screen dimensions
maxW, maxH = screen.get_width(), screen.get_height()
barWidth = int(maxW)/len(arr)
#create bars as tall as can be that are blank
r_min = pygame.Rect(x*barWidth, 0, barWidth, maxH)
r_i = pygame.Rect(y*barWidth, 0, barWidth, maxH)
#draw the blank bars
drawBar(screen, r_min, background)
drawBar(screen, r_i, background)
#create the updated bars post swap
r_min = pygame.Rect(x*barWidth, maxH-arr[x], barWidth, arr[x])
r_i = pygame.Rect(y*barWidth, maxH-arr[y], barWidth, arr[y])
#draw the updated bars
drawBar(screen, r_min, foreground)
drawBar(screen, r_i, foreground)
#update the screen
pygame.display.flip()
#draw a single bar
def drawBar(screen, r, color):
pygame.draw.rect(screen, color, r)
#print the starting menu
def printMenu():
validInput = False
while validInput == False:
#for input choice validation
validInput = True
#get input choice
sortChoice = int(input('\nChoose type of sort\n1) Quick\n2) Merge\n3) Bubble\n4) Selection\n5) Insertion Sort\n'))
#sort choice has to be 1-5
if sortChoice < 1 or sortChoice > 5:
validInput = False
#process input for array size
sizeChoice = int(input('\nChoose an array size\n1) Small\n2) Medium\n3) Large\n'))
size = MEDIUM
if sizeChoice == 1:
size = SMALL
elif sizeChoice == 2:
size = MEDIUM
elif sizeChoice == 3:
size = LARGE
else:
validInput = False
if validInput == False:
print('\nPlease enter valid input')
return sortChoice, size