Updating comments

This commit is contained in:
David Thurstenson 2022-10-19 18:09:35 -05:00
parent ab000a200f
commit 3b31ab8ef1
1 changed files with 21 additions and 6 deletions

View File

@ -45,7 +45,8 @@ pixels.show()
# red and yellow are both set to True depends on how the
# colormode is configured.
def colorizer(pxnum, colormode="fill", yellow=False, red=False):
# Every pixel from lowest to currently highest
# Fill every pixel from lowest to currently highest with
# the current color.
if colormode == "fill":
if red:
pixels[pxnum] = RED
@ -53,6 +54,8 @@ def colorizer(pxnum, colormode="fill", yellow=False, red=False):
pixels[pxnum] = YELLOW
else:
pixels[pxnum] = GREEN
# Only fill the next pixel with the current color if it's
# currently BLANK
elif colormode == "candybar":
if pixels[pxnum] == BLANK:
if red:
@ -67,6 +70,7 @@ def colorizer(pxnum, colormode="fill", yellow=False, red=False):
# Invalid colormodes end up here
raise Exception("Invalid colormode: " + colormode)
# Count down from the given total seconds, using the chosen
# colormode (how the colors are filled into each pixel),
# and the given yellowtime (seconds before timer has elapsed
@ -112,7 +116,11 @@ def countdown(
# Do update stuff
# Calculate the current position
# Calculate the current position.
# Takes the percentage of time elapsed, multiplied with
# the total numbers of pixels, and rounded to the nearest
# decimal. This results in a number of pixels proportional
# to the elapsed time
current_position = round(num_pixels * ((seconds - current_time) / seconds))
# Catch a couple of special cases
@ -124,7 +132,7 @@ def countdown(
# If current_position calls for *all*
# pixels to be lit, and the timer
# hasn't expired yet, don't do anything.
# This should delay the last pixel from
# This will delay the last pixel from
# lighting until the timer has fully elapsed
pass
else:
@ -132,6 +140,10 @@ def countdown(
# based on the elapsed time
for pixel in range(current_position):
# Set pixel color stuff
# If current_time has gone negative, don't
# change any pixels, just keep counting for
# user feedback
if current_time < 0:
pass
elif current_time <= redtime:
@ -141,14 +153,17 @@ def countdown(
else:
colorizer(pixel, colormode)
# Display the result IRL
# All the pixels have now been set based on the
# specified colormode, now display the result IRL.
pixels.show()
# Increment the elapsed time variable
current_time -= update_interval
# Massage the current_time seconds count into human-readable minutes:seconds
display_time = str(datetime.timedelta(seconds=abs(current_time)))[3:]
# Add a negative sign to the output when current_time is negative.
# prettytime() puts the given value through abs() because the way
# datetime.timedelta() represents negative values is kind of a PITA
# to deal with.
if current_time < 0:
display_time_sign = "-"
else: