Add width parameter to bar blend function
This commit is contained in:
parent
1089c3941d
commit
e225716f52
1 changed files with 19 additions and 10 deletions
|
@ -53,17 +53,22 @@ class Filling(Enum):
|
|||
EXTREMA = 2 # Repeat both extrema values
|
||||
GREATEST = 3 # Repeat the longest color streaks
|
||||
|
||||
def blendLedBar(colors: List[Color],
|
||||
res_length: Optional[int] = LedBarLen,
|
||||
blending: Optional[InterpType] = InterpType.NEAREST,
|
||||
filling: Optional[Filling] = Filling.GREATEST,
|
||||
void_color: Optional[Color] = Color("black")) -> List[Color]:
|
||||
def widen(colors: List[Color], width: int):
|
||||
L = []
|
||||
map(L.extend, [[e] * width for e in colors])
|
||||
return L
|
||||
|
||||
def blendLedBar_simple(colors: List[Color],
|
||||
res_length: int,
|
||||
blending: InterpType,
|
||||
filling: Filling,
|
||||
void_color: Color) -> List[Color]:
|
||||
total_len = len(colors)
|
||||
(deduped, rep_nb) = remove_duplicates(colors)
|
||||
if len(deduped) > res_length:
|
||||
# After dedup, there are still too many colors. Only show the first ones
|
||||
logging.warning(f"LED bar interpolation: More than {res_length} colors. Dropping colors")
|
||||
return deduped[:res_length]
|
||||
return widen(deduped[:res_length], width)
|
||||
|
||||
if len(colors) > res_length:
|
||||
# TODO: Try and dedup some colors to save space
|
||||
|
@ -105,7 +110,11 @@ def blendLedBar(colors: List[Color],
|
|||
if gap == 0:
|
||||
return reduplicate(deduped, rep_nb)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def blendLedBar(colors: List[Color],
|
||||
res_length: Optional[int] = LedBarLen,
|
||||
width: Optional[int] = 1,
|
||||
blending: Optional[InterpType] = InterpType.NEAREST,
|
||||
filling: Optional[Filling] = Filling.GREATEST,
|
||||
void_color: Optional[Color] = Color("black")) -> List[Color]:
|
||||
return widen(blendLedBar(colors, res_length, blending, filling, void_color),
|
||||
width)
|
||||
|
|
Loading…
Reference in a new issue