Skip to content

Instantly share code, notes, and snippets.

@ranuzz
Created June 8, 2021 08:07
Show Gist options
  • Save ranuzz/e65b0afb7862a84f795b59cb6e8fd47d to your computer and use it in GitHub Desktop.
Save ranuzz/e65b0afb7862a84f795b59cb6e8fd47d to your computer and use it in GitHub Desktop.
Sorting Visualization using Processing with Python mode
"""
Sorting visualization
"""
from random import randint
def setup():
size(1080/2, 1920/2)
frameRate(2)
def is_sorted(l):
for i in range(1, len(l)):
if l[i-1] > l[i]:
return False
return True
def sort_iteration(l):
for i in range(len(l)-1, 0, -1):
if (l[i-1] > l[i]):
l[i-1], l[i] = l[i], l[i-1]
ll = []
for i in range(23):
ll.append(randint(1,15))
def draw():
background(255)
fill(0)
global ll
for i in range(len(ll)):
rect(10, 25+i*40, 30*ll[i], 30)
if not is_sorted(ll):
sort_iteration(ll)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment