Browse Source

added

master
John 2 months ago
parent
commit
596a19b9d4
3 changed files with 34 additions and 0 deletions
  1. 3
    0
      README.md
  2. BIN
      font.ttf
  3. 31
    0
      pblcks.py

+ 3
- 0
README.md View File

@@ -1,2 +1,5 @@
# pblcks

I wanted to make a vaguely cool looking visualization for a sorting algo. So I did.
I don't remember what this repo was for but I figured, hey, why make a new repo?
Now including, cool font!

BIN
font.ttf View File


+ 31
- 0
pblcks.py View File

@@ -0,0 +1,31 @@
import pygame as pg, pygame.draw as pgd, pygame.locals, pygame.font as pgf, random, time

pg.init()
scrw = 1200
scrh = 720
screen = pg.display.set_mode((scrw, scrh))
pgf.init()
font = pgf.Font("font.ttf", 16)
list = [19, 13, 9, 12, 10, 11, 18, 1, 7, 4, 2, 15, 6, 5, 0, 3, 17, 16, 8, 14]
bound = len(list)-1
clean = False
while True:
if clean != True:
clean = True
for i in range(len(list)):
if i+1 <= bound:
if list[i] > list[i+1]:
tmp = list[i+1]
list[i+1] = list[i]
list[i] = tmp
clean = False
time.sleep(0.05)
screen.fill((16.5, 12.9, 11.0))
for j in range(len(list)):
pgd.rect(screen, (255, 255, 255), (15*j+5, 26, 10, list[j]*10))
screen.blit(font.render("Bubble Sort", False, (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))), (0, 0))
pg.display.flip()
else:
break
while pg.event.wait().type != pg.locals.QUIT:
pass

Loading…
Cancel
Save