Skip to content

Commit

Permalink
PyPi Build
Browse files Browse the repository at this point in the history
  • Loading branch information
debdutgoswami committed Jun 3, 2020
1 parent 9e21199 commit 9671c38
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 44 deletions.
60 changes: 48 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,72 @@
[![HitCount](http://hits.dwyl.com/debdutgoswami/sorting-visualizer.svg)](http://hits.dwyl.com/debdutgoswami/sorting-visualizer)

<p align="center">
<a href="https://pypi.org/project/sorting-visualizer/" rel="nofollow"><img src="" alt="image" style="max-width:100%;"></a>
<img src="https://img.shields.io/github/license/debdutgoswami/sorting-visualizer" alt="image" style="max-width:100%;">
<img src="https://img.shields.io/github/stars/debdutgoswami/sorting-visualizer" alt="image" style="max-width:100%">
</p>

# Sorting Visualizer

A simple python project which visualizes various sorting algorithms.
A simple python project which visualizes various sorting algorithms.

---

## How to setup

1. Install the necessary packages using the command `pip instal -r requirements.txt`.
Simply open up your terminal and type

2. Run the `main.py` file using the command `python3 main.py`.
```
pip3 install sorting-visualizer
```

---

## Algorithms Implemented

- [x] Bubble Sort
- [x] Selection Sort
- [x] Insertion Sort
- [x] Merge Sort
- [x] Bubble Sort (bubblesort)
- [x] Selection Sort (selectionsort)
- [x] Insertion Sort (insertionsort)
- [x] Merge Sort (mergesort)
- [ ] Quick Sort
- [ ] Heap Sort

---

## Technologies Used
## Prerequisite

1. Python 3.7
1. [ffmpeg](https://www.ffmpeg.org/download.html)

---

## Libraries Used
## How to use

1. matplotlib
1. Show the plot

---
```
from sorting_visualizer import visualizer
visualizer.visualize('bubblesort')
```
2. Show and save the plot
```
from sorting_visualizer import visualizer
visualizer.visualize('bubblesort', save=True)
```
3. Only save the plot and not show it
```
from sorting_visualizer import visualizer
visualizer.visualize('bubblesort', save=True, show=False)
```
4. Saving in a particular location
```
from sorting_visualizer import visualizer
visualizer.visualize('bubblesort', save=True, path='path/to/directory')
```
The default saving location is your current working directory.
8 changes: 0 additions & 8 deletions main.py

This file was deleted.

4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

# Inside of setup.cfg
[metadata]
description-file = README.md
27 changes: 27 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import setuptools

with open("README.md", "r") as fh:
long_description = fh.read()

setuptools.setup(
name="sorting_visualizer",
version="1.0",
author="Debdut Goswami",
author_email="[email protected]",
description="A package to visualize various sorting algorithms.",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/debdutgoswami/sorting-visualizer",
download_url = 'https://github.com/debdutgoswami/sorting-visualizer/archive/v1.0.tar.gz',
keywords = ['SORT', 'ALGORITHM', 'VISUALIZE'],
packages=setuptools.find_packages(),
install_requires=[
'matplotlib'
],
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
python_requires='>=3.7',
)
Empty file added sorting_visualizer/__init__.py
Empty file.
File renamed without changes.
5 changes: 5 additions & 0 deletions sorting_visualizer/variables.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
sortname = {
'bubblesort': f'Bubble Sort O(n\N{SUPERSCRIPT TWO})', 'insertionsort': f'Insertion Sort O(n\N{SUPERSCRIPT TWO})',
'selectionsort': f'Selection Sort O(n\N{SUPERSCRIPT TWO})', 'mergesort': 'Merge Sort O(n log n)',
'quicksort': 'Quick Sort O(n log n)', 'heapsort': 'Heap Sort O(n log n)'
}
38 changes: 25 additions & 13 deletions visualizer.py → sorting_visualizer/visualizer.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import variables, sort
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import random
import matplotlib, random, os
from matplotlib import pyplot as plt, animation
try:
from sorting_visualizer import sort, variables
except ModuleNotFoundError:
import sort, variables

def visualize(data: dict):
N = data['size']
func = data['sort']
def visualize(algo: str, *args, **kwargs):
func = algo

N = kwargs.get('size', 100)
path = kwargs.get('path', os.getcwd())
show = kwargs.get('show', True)
save = kwargs.get('save', False)

A = list(range(1,N+1))
random.shuffle(A)

generator = getattr(sort, variables.sortfunc[func])(A)
generator = getattr(sort, func)(A)

fig, ax = plt.subplots() #creates a figure and subsequent subplots
ax.set_title(variables.sortname[func])
Expand All @@ -35,10 +40,17 @@ def update(A, rects, iteration):

text.set_text("# of operations: {}".format(iteration[0]))

#print(len(list(generator)))
anim = animation.FuncAnimation(fig, func=update, fargs=(bar_sub, iteration), frames=generator, repeat=True, blit=False, interval=15, save_count=90000)

#saves the animation
anim.save("{}.mp4".format(variables.sortname[func]), writer=writer)
if save:
# setting up path
_filename = "{}.mp4".format(variables.sortname[func])

path = os.path.join(path, _filename)
#saves the animation
anim.save(path, writer=writer)

if show and not save:
plt.show() #for showing the animation on screen

#plt.show() #for showing the animation on screen
plt.close()
11 changes: 0 additions & 11 deletions variables.py

This file was deleted.

0 comments on commit 9671c38

Please sign in to comment.