Added method to generate a list of hex color values between a start
color and end color.
This commit is contained in:
parent
a77b06a25e
commit
3901aa43f1
@ -3,6 +3,7 @@ import functools
|
||||
import re
|
||||
import socket
|
||||
import string
|
||||
from colour import Color
|
||||
|
||||
|
||||
def lchop(string, prefix):
|
||||
@ -423,3 +424,29 @@ def user_open(url_or_command):
|
||||
import subprocess
|
||||
subprocess.Popen(url_or_command, shell=True)
|
||||
|
||||
|
||||
def get_hex_color_range(start_color, end_color, quantity):
|
||||
"""
|
||||
Generates a list of quantity Hex colors from start_color to end_color.
|
||||
|
||||
:param start_color: Hex or plain English color for start of range
|
||||
:param end_color: Hex or plain English color for end of range
|
||||
:param quantity: Number of colours to return
|
||||
:return: A list of Hex color values
|
||||
"""
|
||||
raw_colors = [c.hex for c in list(Color(start_color).range_to(Color(end_color), quantity))]
|
||||
colors = []
|
||||
for color in raw_colors:
|
||||
|
||||
# i3bar expects the full Hex value but for some colors the colour
|
||||
# module only returns partial values. So we need to convert these colors to the full
|
||||
# Hex value.
|
||||
if len(color) == 4:
|
||||
fixed_color = "#"
|
||||
for c in color[1:]:
|
||||
fixed_color += c * 2
|
||||
colors.append(fixed_color)
|
||||
else:
|
||||
colors.append(color)
|
||||
return colors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user