Если у кого-то возник такой же вопрос, то я порекомендую бибилиотку pygame. Она вообще для создания игр, но отлично подходит для визуализации любых алгоритмов сортировки. Пример сортировки пузырьком.
import pygame
from random import randint
def swap(list, i, j):
list[i], list[j] = list[j], list[i]
return list
def buble_sort(list, i):
if list[i-1] > list[i]:
list = swap(list, i-1, i)
return list
pygame.init()
screen_width, screen_height = 1600, 900
screen = pygame.display.set_mode((screen_width, screen_height), pygame.FULLSCREEN)
clock = pygame.time.Clock()
run = True
y = screen_height
fps = 10
n = 10#4 #length of list
x0 = 1
xn = screen_height
distance = screen_width/n
width = distance - 1
list = [randint(1, screen_height) for p in range(0, n)]
white = (255, 255, 255)
red = (255, 0, 0)
blue = (0, 0, 255)
j = 1
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
run = False
screen.fill((0, 0, 0))
for i in range(len(list)):
if i == j - 1:
pygame.draw.rect(screen, red, pygame.Rect(i * distance, y, width, -list[i]))
else:
pygame.draw.rect(screen, white, pygame.Rect(i * distance, y, width, -list[i]))
list = buble_sort(list, j)
j += 1
if j == len(list):
j = 1
pygame.display.flip()
clock.tick(fps)