Add width parameter to bar blend function

This commit is contained in:
Constantin Gierczak--Galle 2023-12-15 10:54:42 +01:00
parent 1089c3941d
commit e225716f52

View file

@ -53,17 +53,22 @@ class Filling(Enum):
EXTREMA = 2 # Repeat both extrema values EXTREMA = 2 # Repeat both extrema values
GREATEST = 3 # Repeat the longest color streaks GREATEST = 3 # Repeat the longest color streaks
def blendLedBar(colors: List[Color], def widen(colors: List[Color], width: int):
res_length: Optional[int] = LedBarLen, L = []
blending: Optional[InterpType] = InterpType.NEAREST, map(L.extend, [[e] * width for e in colors])
filling: Optional[Filling] = Filling.GREATEST, return L
void_color: Optional[Color] = Color("black")) -> List[Color]:
def blendLedBar_simple(colors: List[Color],
res_length: int,
blending: InterpType,
filling: Filling,
void_color: Color) -> List[Color]:
total_len = len(colors) total_len = len(colors)
(deduped, rep_nb) = remove_duplicates(colors) (deduped, rep_nb) = remove_duplicates(colors)
if len(deduped) > res_length: if len(deduped) > res_length:
# After dedup, there are still too many colors. Only show the first ones # 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") 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: if len(colors) > res_length:
# TODO: Try and dedup some colors to save space # TODO: Try and dedup some colors to save space
@ -105,7 +110,11 @@ def blendLedBar(colors: List[Color],
if gap == 0: if gap == 0:
return reduplicate(deduped, rep_nb) 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)