From 31b2bcd9e6ca8714accea22b0ddea2acea496650 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Thu, 8 Feb 2024 14:37:30 -0600 Subject: [PATCH] Add interpolate_color_by_hsl --- manimlib/utils/color.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/manimlib/utils/color.py b/manimlib/utils/color.py index 6bd49522..c712c3e6 100644 --- a/manimlib/utils/color.py +++ b/manimlib/utils/color.py @@ -102,6 +102,16 @@ def interpolate_color( return rgb_to_color(rgb) +def interpolate_color_by_hsl( + color1: ManimColor, + color2: ManimColor, + alpha: float +) -> Color: + hsl1 = np.array(Color(color1).get_hsl()) + hsl2 = np.array(Color(color2).get_hsl()) + return Color(hsl=interpolate(hsl1, hsl2, alpha)) + + def average_color(*colors: ManimColor) -> Color: rgbs = np.array(list(map(color_to_rgb, colors))) return rgb_to_color(np.sqrt((rgbs**2).mean(0)))