cocktail shaker sort line sketch

This commit is contained in:
Xevion
2019-11-08 14:53:35 -06:00
parent d77e987289
commit 77c332c260
3 changed files with 35 additions and 1 deletions

View File

@@ -4,4 +4,6 @@
Sketches that visualize sorting algorithms as they progress.
## Sketches
## Sketches
- **cocktail_shaker_line** - Sorting of a line using the cocktail shaker algorithm (double bouble sort I believe). Needs reworking as the colors and movement of the line is not as expected (colors shift, movement doesn't properly correlate).

View File

@@ -0,0 +1,30 @@
import random, time
def setup():
global array
size(1000, 1000)
array = list(range(height))
random.shuffle(array)
colorMode(HSB, height)
def draw():
background(height)
global array
done = True
for index in range(len(array)-1):
if array[index] < array[index + 1]:
array[index], array[index + 1] = array[index + 1], array[index]
done = False
for index in list(range(len(array)-1))[::-1]:
if array[index] < array[index + 1]:
array[index], array[index + 1] = array[index + 1], array[index]
done = False
for index, num in enumerate(array):
fill(num, height, height)
stroke(num, height, height)
ellipse(num, index, 5, 5)
if done:
time.sleep(0.5)
random.shuffle(array)

View File

@@ -0,0 +1,2 @@
mode=Python
mode.id=jycessing.mode.PythonMode