colors: More readable loop

This commit is contained in:
Dylan Araps 2018-01-01 11:31:46 +11:00
parent 7984fd40af
commit 3fc3b5e033

View File

@ -36,22 +36,22 @@ def gen_colors(img, color_count):
"error: wal requires imagemagick to function.") "error: wal requires imagemagick to function.")
sys.exit(1) sys.exit(1)
raw_colors = imagemagick(color_count, img, magick_command) for index in range(0, 20, 1):
index = 0
while len(raw_colors) - 1 < color_count:
index += 1
raw_colors = imagemagick(color_count + index, img, magick_command) raw_colors = imagemagick(color_count + index, img, magick_command)
print("colors: Imagemagick couldn't generate a", color_count, if len(raw_colors) > 16:
"color palette, trying a larger palette size", break
color_count + index)
if index > 20: elif index == 20:
print("colors: Imagemagick couldn't generate a suitable scheme", print("colors: Imagemagick couldn't generate a suitable scheme",
"for the image. Exiting...") "for the image. Exiting...")
sys.exit(1) sys.exit(1)
else:
print("colors: Imagemagick couldn't generate a", color_count,
"color palette, trying a larger palette size",
color_count + index)
# Remove the first element because it isn't a color code. # Remove the first element because it isn't a color code.
del raw_colors[0] del raw_colors[0]