width = 1000
height = width / 2
l = 10
num = width / l
h = []
gap = int(num * 0.7)
count = 0
def setup():
size(width,height)
for i in range(num):
h.append(map(i,0,num,0,height))
shuffl()
def draw():
global count,gap
background(0)
for i in range(num):
if count < num - gap:
if h[count] > h[count + gap]:
print("swap")
h[count],h[count + gap] = h[count + gap],h[count]
else:
count = 0
gap = gapper(gap)
if i == count or i == count + gap:
fill(255,0,0)
else:
fill(255)
rect(i*10,height - h[i],l,h[i])
count += 1
def gapper(gap):
gap = int(gap*0.7)
if gap > 0:
return gap
return 1
def shuffl():
for i in range(num):
for j in range(num):
a = int(random(num))
h[j],h[a] = h[a],h[j]
I simplified my code a lot, everything works, I believe, but I feel like something is wrong, my final part is worse than bubblesort, is this how the algorithm works or I lost something during the ‘coversion’ of the sort for Processing?