Skip to content

SauravC99/VisualSort

Repository files navigation

Visual Sort

A program that visualizes sorting algorithms with python

Visual Sort is a program will let you visualize different sorting algorithms and generate beautiful videos with sound. You can view some examples in the videos folder.

merge quickR

Supported Algorithms

Algorithm Name
Bogo Sort
Bubble Sort
Cocktail Shaker Sort
Comb Sort
Counting Sort
Gnome Sort
Insertion Sort and alternate
Merge Sort (subarrays and in place)
Pigeonhole Sort
Quick Sort and alternate
Radix Sort
Selection Sort
Shell Sort
Tim Sort

Requires ffmpeg to generate video from frames and add sound.

Video files are named following this schema:

"{algorithmName} {elements}-{fps} video.mp4"

And this for rainbow mode videos:

"{algorithmName} R {elements}-{fps} video.mp4"

Installation

Clone the repository to your computer:

git clone https://github.com/SauravC99/VisualSort.git

Usage

Run with -h to see the list of commands:

$ python3 visualSort.py -h
usage: visualSort.py [-h] [-l] [-lv] [-a ALGORITHM] [-n NUMBER] [-f FPS] [-r]

options:
  -h, --help            show this help message and exit
  -l, --list            Display the list of sorting algorithms avaliable.
  -lv, --listverb       Display a verbose list of sorting algorithms.
  -a ALGORITHM, --algorithm ALGORITHM
                        Specify which sorting algorithm to use. Run with '-l' to see the list.
  -n NUMBER, --number NUMBER
                        Specify the number of elements you want to animate sorting. Default 10.
  -f FPS, --fps FPS     Specify how many frames per second the animation will run. Default 60.
  -r, --rainbow         Use this flag to make the graph colorful.

Run with -l to see the list of algorithms:

python3 visualSort.py -l

Quickstart

Run with no flags or variables to use the default options:

  • 10 elements
  • 60 frames per second
  • Insertion sort algorithm
python3 visualSort.py

Flags and Variables

There are a number of flags and variables you can add or change to generate different types of videos.

-h - Displays the help menu.

-l - Displays the list of sorting algorithms.

-lv - Displays the list of sorting algorithms with more detail.

-a ALGORITHM - Specify which sorting algorithm you want to visualize. Default is insertion sort.

-n NUMBER - Specify the number of elements you want to visualize sorting. Default is 10.

-f FPS - Specify how many frames per second the video will run at. Default is 60. Lower numbers will make the video slower. Higher numbers will make the video faster.

-r - Visualize in rainbow mode.

Rainbow mode

You can run any algorithm with the -r flag to sort the colors of the rainbow. mergeR radixR shellR countingR quickR2

Examples

python3 visualSort.py -n 30 -a quicksort

Will generate a video of 30 elements being sorted using quicksort at the default 60 fps.

python3 visualSort.py -n 30 -a quicksort -r

Will generate the same video as above but the graph will be colorful like a rainbow.

python3 visualSort.py -n 20 -a selectionsort -f 90

Will generate a video of 20 elements being sorted using selection sort at 90 fps. This will speed up the video.


tim bubble selection insertion bogo shell radix quick

About

Visualize sorting algorithms and generate beautiful videos with sound.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages