mirror of
https://github.com/Xevion/processing-projects.git
synced 2025-12-06 07:15:57 -06:00
cocktail shaker sort line sketch
This commit is contained in:
@@ -5,3 +5,5 @@
|
||||
Sketches that visualize sorting algorithms as they progress.
|
||||
|
||||
## 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).
|
||||
30
sorting/cocktail_shaker_line/cocktail_shaker_line.pyde
Normal file
30
sorting/cocktail_shaker_line/cocktail_shaker_line.pyde
Normal 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)
|
||||
2
sorting/cocktail_shaker_line/sketch.properties
Normal file
2
sorting/cocktail_shaker_line/sketch.properties
Normal file
@@ -0,0 +1,2 @@
|
||||
mode=Python
|
||||
mode.id=jycessing.mode.PythonMode
|
||||
Reference in New Issue
Block a user