Skip to content

Instantly share code, notes, and snippets.

@ivand58
Last active February 5, 2018 12:03
Show Gist options
  • Save ivand58/8980ce82bc3240c4fe548b797c1e8cf9 to your computer and use it in GitHub Desktop.
Save ivand58/8980ce82bc3240c4fe548b797c1e8cf9 to your computer and use it in GitHub Desktop.
percentage progress bar
class CProgress:
"""Uses the Bresenham algorithm for line segments in the first octant."""
def __init__(self,title='', mx=100):
self.deltax = mx
self.deltay = 40
self.error, self.progress_y = 0, 0
sys.stdout.write(title + ": [" + "-"*40 + "]" + chr(8)*41)
sys.stdout.flush()
def progress(self):
if 2 * (self.error + self.deltay) < self.deltax:
self.error += self.deltay
else:
self.progress_y += 1
self.error += self.deltay - self.deltax
sys.stdout.write("#")
sys.stdout.flush()
def endProgress(self):
sys.stdout.write("#" * (self.deltay - self.progress_y)+ "]\n")
sys.stdout.flush()
@ivand58
Copy link
Author

ivand58 commented Feb 5, 2018

Uses a Bresenham algorithm for line segments in the first octant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment