forked from brockellefson/IntrospectiveSortResearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BubbleSort.py
42 lines (32 loc) · 973 Bytes
/
BubbleSort.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
import pygame
from random import randint
import time
pygame.init()
size = (500, 500)
window = pygame.display.set_mode((size))
pygame.display.set_caption("BubbleSort")
black = pygame.Color(0, 0, 0)
white = pygame.Color(255, 255, 255)
ourlist = []
listLength = 100
xList, y, w = [], 0, 5
tmpX = 0
for i in range(listLength):
ourlist.append(randint(0, 500))
xList.append(tmpX)
tmpX += w
def draw():
global xList, y, ourlist
for i in range(listLength):
pygame.draw.rect(window, white, (xList[i], y, w, ourlist[i]), 0)
for i in range(listLength):
for j in range(0, listLength - i - 1):
if ourlist[j] > ourlist[j + 1]:
ourlist[j], ourlist[j + 1] = ourlist[j + 1], ourlist[j]
window.fill(black)
draw()
pygame.display.update()
time.sleep(.1)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()