Last active
February 5, 2018 12:03
-
-
Save ivand58/8980ce82bc3240c4fe548b797c1e8cf9 to your computer and use it in GitHub Desktop.
percentage progress bar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uses a Bresenham algorithm for line segments in the first octant.