Updating comments
This commit is contained in:
parent
ab000a200f
commit
3b31ab8ef1
|
@ -45,7 +45,8 @@ pixels.show()
|
||||||
# red and yellow are both set to True depends on how the
|
# red and yellow are both set to True depends on how the
|
||||||
# colormode is configured.
|
# colormode is configured.
|
||||||
def colorizer(pxnum, colormode="fill", yellow=False, red=False):
|
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 colormode == "fill":
|
||||||
if red:
|
if red:
|
||||||
pixels[pxnum] = RED
|
pixels[pxnum] = RED
|
||||||
|
@ -53,6 +54,8 @@ def colorizer(pxnum, colormode="fill", yellow=False, red=False):
|
||||||
pixels[pxnum] = YELLOW
|
pixels[pxnum] = YELLOW
|
||||||
else:
|
else:
|
||||||
pixels[pxnum] = GREEN
|
pixels[pxnum] = GREEN
|
||||||
|
# Only fill the next pixel with the current color if it's
|
||||||
|
# currently BLANK
|
||||||
elif colormode == "candybar":
|
elif colormode == "candybar":
|
||||||
if pixels[pxnum] == BLANK:
|
if pixels[pxnum] == BLANK:
|
||||||
if red:
|
if red:
|
||||||
|
@ -67,6 +70,7 @@ def colorizer(pxnum, colormode="fill", yellow=False, red=False):
|
||||||
# Invalid colormodes end up here
|
# Invalid colormodes end up here
|
||||||
raise Exception("Invalid colormode: " + colormode)
|
raise Exception("Invalid colormode: " + colormode)
|
||||||
|
|
||||||
|
|
||||||
# Count down from the given total seconds, using the chosen
|
# Count down from the given total seconds, using the chosen
|
||||||
# colormode (how the colors are filled into each pixel),
|
# colormode (how the colors are filled into each pixel),
|
||||||
# and the given yellowtime (seconds before timer has elapsed
|
# and the given yellowtime (seconds before timer has elapsed
|
||||||
|
@ -112,7 +116,11 @@ def countdown(
|
||||||
|
|
||||||
# Do update stuff
|
# 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))
|
current_position = round(num_pixels * ((seconds - current_time) / seconds))
|
||||||
|
|
||||||
# Catch a couple of special cases
|
# Catch a couple of special cases
|
||||||
|
@ -124,7 +132,7 @@ def countdown(
|
||||||
# If current_position calls for *all*
|
# If current_position calls for *all*
|
||||||
# pixels to be lit, and the timer
|
# pixels to be lit, and the timer
|
||||||
# hasn't expired yet, don't do anything.
|
# 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
|
# lighting until the timer has fully elapsed
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
@ -132,6 +140,10 @@ def countdown(
|
||||||
# based on the elapsed time
|
# based on the elapsed time
|
||||||
for pixel in range(current_position):
|
for pixel in range(current_position):
|
||||||
# Set pixel color stuff
|
# 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:
|
if current_time < 0:
|
||||||
pass
|
pass
|
||||||
elif current_time <= redtime:
|
elif current_time <= redtime:
|
||||||
|
@ -141,14 +153,17 @@ def countdown(
|
||||||
else:
|
else:
|
||||||
colorizer(pixel, colormode)
|
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()
|
pixels.show()
|
||||||
|
|
||||||
# Increment the elapsed time variable
|
# Increment the elapsed time variable
|
||||||
current_time -= update_interval
|
current_time -= update_interval
|
||||||
|
|
||||||
# Massage the current_time seconds count into human-readable minutes:seconds
|
# Add a negative sign to the output when current_time is negative.
|
||||||
display_time = str(datetime.timedelta(seconds=abs(current_time)))[3:]
|
# 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:
|
if current_time < 0:
|
||||||
display_time_sign = "-"
|
display_time_sign = "-"
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue