Created
May 12, 2021 11:16
-
-
Save writeblankspace/318c24c37786f822ee3edf8b630239c0 to your computer and use it in GitHub Desktop.
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
def progress_bar(current, goal): | |
""" **Creates a progress bar** \n | |
current = the progress done \n | |
goal = the total needed \n""" | |
""" current is the numerator | |
goal is the denominator """ | |
# configuration | |
conf = { # conf[key] | |
# these will make up the progress bar as strings | |
# 'c' is for anything completed (aka the green bits) | |
# 'i' is for anything incompletes (aka the grey bits) | |
# for example, a 5/10 progress bar with 'c' and 'i' would look like: | |
# ccccciiiii | |
# | |
# demos: | |
# il im im im im im im im im ir 00/10 | |
# cl cm cm cm cm im im im im ir 05/10 | |
# cl cm cm cm cm cm cm cm cm cr 10/10 | |
cl: "", # completed, left | |
cm: "", # completed, middle | |
cr: "", # completed, right | |
il: "", # incomplete, left | |
im: "", # incomplete, middle | |
ir: "", # incomplete, right | |
} | |
done = current / goal | |
percent_done = round(done * 100) | |
percent_left = round(100 - done) | |
# you can change the '10' to change the length of the bar | |
# for best results, use a factor of 100 | |
# eg. 2, 5, 10 | |
done_10 = round(percent_done / 10) | |
left_10 = round(percent_left / 10) | |
while done_10 + left_10 > 10: | |
left_10 -= 1 | |
string = "" | |
integ = 0 | |
for i in range(1, done_10 + 1): | |
if integ == 0: # if string is empty | |
string += conf[cl] | |
elif integ != 9: # if it's in the middle | |
string += conf[cm] | |
else: # if it's the last | |
string += conf[cr] | |
integ += 1 # add 1 to integ | |
for i in range(1, left_10 + 1): | |
if integ == 0: # if string is empty | |
string += conf[il] | |
elif i != (left_10): # if it's not the last | |
string += conf[im] | |
else: # if it's the last | |
string += conf[ir] | |
integ += 1 # add 1 to integ | |
return string |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment