Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from 3b1b:master #15

Merged
merged 15 commits into from
Dec 30, 2022
Next Next commit
Interpolate colors using square of rgbs
  • Loading branch information
3b1b committed Dec 30, 2022
commit 04d3e6a47ca9960777754aa3abe77f5acc87b5a0
6 changes: 3 additions & 3 deletions manimlib/utils/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def color_gradient(
alphas_mod1[-1] = 1
floors[-1] = len(rgbs) - 2
return [
rgb_to_color(interpolate(rgbs[i], rgbs[i + 1], alpha))
rgb_to_color(np.sqrt(interpolate(rgbs[i]**2, rgbs[i + 1]**2, alpha)))
for i, alpha in zip(floors, alphas_mod1)
]

Expand All @@ -98,13 +98,13 @@ def interpolate_color(
color2: ManimColor,
alpha: float
) -> Color:
rgb = interpolate(color_to_rgb(color1), color_to_rgb(color2), alpha)
rgb = np.sqrt(interpolate(color_to_rgb(color1)**2, color_to_rgb(color2)**2, alpha))
return rgb_to_color(rgb)


def average_color(*colors: ManimColor) -> Color:
rgbs = np.array(list(map(color_to_rgb, colors)))
return rgb_to_color(rgbs.mean(0))
return rgb_to_color(np.sqrt((rgbs**2).mean(0)))


def random_color() -> Color:
Expand Down