You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pblcks.py 900B

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