Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
bd4d123
first draft of color class + starting library conversion
MrDiver Nov 13, 2022
01e28fd
Merge branch 'main' into color_fix
MrDiver Nov 13, 2022
a0e85af
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 13, 2022
8af3f81
Merge branch 'main' into color_fix
MrDiver Nov 19, 2022
332d327
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 19, 2022
da0806a
changed everything to Manim color todo: figure out circular dependenc…
MrDiver Nov 19, 2022
73ffb51
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 19, 2022
157c504
first working draft of new color version
MrDiver Dec 10, 2022
a7e4a3e
Merge branch 'main' into color_fix
MrDiver Dec 10, 2022
d21583d
resolving conflicts
MrDiver Dec 11, 2022
074345e
resolving conflicts
MrDiver Dec 11, 2022
128b8ab
resolving conflicts
MrDiver Dec 11, 2022
31bcdac
resolving conflicts
MrDiver Dec 11, 2022
27c0ddb
resolving conflicts
MrDiver Dec 11, 2022
195512a
changed default internal value of ManimColor to np.ndarray[float]
MrDiver Dec 16, 2022
9823616
starting to fix tests
MrDiver Dec 16, 2022
e638643
fixed more tests and changed precision of manim color
MrDiver Dec 17, 2022
7867aa3
removed premature color conversion
MrDiver Dec 17, 2022
a12507a
fixed some more tests
MrDiver Dec 17, 2022
15c4998
final test changes
MrDiver Dec 17, 2022
76d7cda
fix doctests
MrDiver Dec 17, 2022
a27aff4
fix for 3.8
MrDiver Dec 17, 2022
1580c82
fixing ManimColor string representation
MrDiver Dec 17, 2022
b2cc282
removing some unneccesary conversions
MrDiver Dec 17, 2022
2baeff5
moved community constants to manim_colors.py and added more color sta…
MrDiver Dec 22, 2022
86c5d07
Merge branch 'main' into color_fix
MrDiver Dec 22, 2022
d1bc9fc
Merge branch 'experimental' into color_fix
MrDiver Jan 3, 2023
bd32291
broke some too long lines
behackl Mar 29, 2023
9dd9ba2
added fallback: check whether passed object has get_hex method
behackl Mar 29, 2023
d9c1d6f
actually fix _internal_from_string
behackl Mar 29, 2023
6499b86
added hsv support
behackl Mar 29, 2023
695373b
Merge remote-tracking branch 'origin/main' into color_fix
behackl Mar 29, 2023
bbef400
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 29, 2023
d32f0d5
remove dependency on colour
behackl Mar 29, 2023
f0297e6
fixed DARK_EARTH being assigned twice
behackl Mar 29, 2023
3eeeaf2
fixed double assignment
behackl Mar 29, 2023
b265091
remove more duplicated colour names
behackl Mar 29, 2023
f7db270
raise NotImplementedError for ManimColor.gradient
behackl Mar 29, 2023
2befc10
removed unused import
behackl Mar 29, 2023
d18a8dc
Merge branch 'color_fix' of github.com:MrDiver/manim into color_fix
behackl Mar 29, 2023
7a99a46
remove superfluous ManimColor import
behackl May 1, 2023
5bb6369
fix circular import, remove dependency of space_ops on config
behackl May 1, 2023
d4ffe5c
one more Color -> ParseableManimColor
behackl May 1, 2023
9085d79
removed one *-import
behackl May 1, 2023
03cdd78
somewhat unrelated fixed type hint
behackl May 1, 2023
5b990ca
-1 *-import
behackl May 1, 2023
c9f3311
fixed change of logic in CoordinateSystem.get_graph_label
behackl May 1, 2023
b144852
removed debug print; fixed type hint in mobject.py
behackl May 1, 2023
ed9de63
some fixes and improvements to text_mobject.py
behackl May 1, 2023
4099acd
update three_dimensions
behackl May 1, 2023
bd040e6
fixes for rendered documentation of utils.color.*
behackl May 1, 2023
77a2950
substantial improvements to documentation, including new Sphinx direc…
behackl May 1, 2023
9d97821
Rewrite of the sphinx directive to use docutils nodes and 2 column de…
MrDiver May 2, 2023
fe6d1c9
I just had to do it
MrDiver May 2, 2023
d8dfdb2
Improve the color table
naveen521kk May 2, 2023
9880f59
minor cleanup
behackl May 2, 2023
771113e
fixed ColorOverview example
behackl May 2, 2023
56ba61a
documentation improvements
behackl May 2, 2023
1e6be03
Merge remote-tracking branch 'origin/main' into color_fix
behackl May 2, 2023
3c1ca10
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 2, 2023
322249a
merge fix
MrDiver Jul 31, 2023
3282c75
Update manim/mobject/mobject.py
MrDiver Jul 31, 2023
884846e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 31, 2023
e1c8419
fix flake8 errors
behackl Jul 31, 2023
025cd3a
Removed test in test_text_mobject
MrDiver Aug 3, 2023
7b599f2
Improved Documentation of core.py and added private members in sphinx…
MrDiver Aug 4, 2023
1c6899f
Merge branch 'main' of github.com:ManimCommunity/manim into color_fix
MrDiver Aug 4, 2023
4388cce
Change color types of labeled.py
MrDiver Aug 4, 2023
f41bef3
removed some unused imports
behackl Aug 8, 2023
c3e7b99
turned docstring into comment
behackl Aug 8, 2023
112470d
_colors -> _all_manim_colors; move to manim_color module
behackl Aug 8, 2023
38d3c3f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 8, 2023
3576be6
fixed typing
behackl Aug 8, 2023
7da5946
rewrite import
behackl Aug 8, 2023
6651ab9
Merge branch 'main' into color_fix
MrDiver Aug 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion manim/mobject/geometry/shape_matchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from manim.mobject.geometry.polygram import RoundedRectangle
from manim.mobject.mobject import Mobject
from manim.mobject.types.vectorized_mobject import VGroup
from manim.utils.color import BLACK, RED, YELLOW, Color, Colors
from manim.utils.color import BLACK, RED, YELLOW


class SurroundingRectangle(RoundedRectangle):
Expand Down
39 changes: 21 additions & 18 deletions manim/mobject/mobject.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Base classes for objects that can be displayed."""

from __future__ import annotations

__all__ = ["Mobject", "Group", "override_animate"]
Expand Down Expand Up @@ -29,7 +30,6 @@
)

import numpy as np
from colour import Color

from manim.mobject.opengl.opengl_compatibility import ConvertToOpenGL

Expand All @@ -39,7 +39,8 @@
BLACK,
WHITE,
YELLOW_C,
Colors,
ManimColor,
ParsableManimColor,
color_gradient,
interpolate_color,
)
Expand Down Expand Up @@ -91,7 +92,9 @@ def __init_subclass__(cls, **kwargs):
cls._add_intrinsic_animation_overrides()
cls._original__init__ = cls.__init__

def __init__(self, color=WHITE, name=None, dim=3, target=None, z_index=0):
def __init__(
self, color: ManimColor = WHITE, name=None, dim=3, target=None, z_index=0
):
self.name = self.__class__.__name__ if name is None else name
self.dim = dim
self.target = target
Expand All @@ -100,7 +103,7 @@ def __init__(self, color=WHITE, name=None, dim=3, target=None, z_index=0):
self.submobjects = []
self.updaters = []
self.updating_suspended = False
self.color = Color(color) if color else None
self.color: ManimColor = color

self.reset_points()
self.generate_points()
Expand Down Expand Up @@ -1684,7 +1687,7 @@ def put_start_and_end_on(self, start, end):

# Background rectangle
def add_background_rectangle(
self, color: Colors | None = None, opacity: float = 0.75, **kwargs
self, color: ParsableManimColor | None = None, opacity: float = 0.75, **kwargs
):
"""Add a BackgroundRectangle as submobject.

Expand Down Expand Up @@ -1736,7 +1739,7 @@ def add_background_rectangle_to_family_members_with_points(self, **kwargs):

# Color functions

def set_color(self, color: Color = YELLOW_C, family: bool = True):
def set_color(self, color: ParsableManimColor = YELLOW_C, family: bool = True):
"""Condition is function which takes in one arguments, (x, y, z).
Here it just recurses to submobjects, but in subclasses this
should be further implemented based on the the inner workings
Expand All @@ -1745,19 +1748,19 @@ def set_color(self, color: Color = YELLOW_C, family: bool = True):
if family:
for submob in self.submobjects:
submob.set_color(color, family=family)
self.color = Color(color)
self.color = ManimColor.parse(color)
return self

def set_color_by_gradient(self, *colors):
def set_color_by_gradient(self, *colors: Iterable[ParsableManimColor]):
self.set_submobject_colors_by_gradient(*colors)
return self

def set_colors_by_radial_gradient(
self,
center=None,
radius=1,
inner_color=WHITE,
outer_color=BLACK,
radius: float = 1,
inner_color: ParsableManimColor = WHITE,
outer_color: ParsableManimColor = BLACK,
):
self.set_submobject_colors_by_radial_gradient(
center,
Expand All @@ -1767,7 +1770,7 @@ def set_colors_by_radial_gradient(
)
return self

def set_submobject_colors_by_gradient(self, *colors):
def set_submobject_colors_by_gradient(self, *colors: Iterable[ParsableManimColor]):
if len(colors) == 0:
raise ValueError("Need at least one color")
elif len(colors) == 1:
Expand All @@ -1783,9 +1786,9 @@ def set_submobject_colors_by_gradient(self, *colors):
def set_submobject_colors_by_radial_gradient(
self,
center=None,
radius=1,
inner_color=WHITE,
outer_color=BLACK,
radius: float = 1,
inner_color: ParsableManimColor = WHITE,
outer_color: ParsableManimColor = BLACK,
):
if center is None:
center = self.get_center()
Expand All @@ -1802,7 +1805,7 @@ def to_original_color(self):
self.set_color(self.color)
return self

def fade_to(self, color, alpha, family=True):
def fade_to(self, color: ParsableManimColor, alpha: float, family: bool = True):
if self.get_num_points() > 0:
new_color = interpolate_color(self.get_color(), color, alpha)
self.set_color(new_color, family=False)
Expand All @@ -1811,13 +1814,13 @@ def fade_to(self, color, alpha, family=True):
submob.fade_to(color, alpha)
return self

def fade(self, darkness=0.5, family=True):
def fade(self, darkness: float = 0.5, family: bool = True):
if family:
for submob in self.submobjects:
submob.fade(darkness, family)
return self

def get_color(self):
def get_color(self) -> ManimColor:
"""Returns the color of the :class:`~.Mobject`"""
return self.color

Expand Down
5 changes: 2 additions & 3 deletions manim/mobject/opengl/opengl_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from manim.constants import *
from manim.utils.bezier import integer_interpolate, interpolate
from manim.utils.color import *
from manim.utils.color import Colors
from manim.utils.config_ops import _Data, _Uniforms

# from ..utils.iterables import batch_by_property
Expand Down Expand Up @@ -2035,7 +2034,7 @@ def set_shadow(self, shadow, recurse=True):
# Background rectangle

def add_background_rectangle(
self, color: Colors | None = None, opacity: float = 0.75, **kwargs
self, color: ParsableManimColor | None = None, opacity: float = 0.75, **kwargs
):
# TODO, this does not behave well when the mobject has points,
# since it gets displayed on top
Expand Down Expand Up @@ -2069,7 +2068,7 @@ def add_background_rectangle(
from manim.mobject.geometry.shape_matchers import BackgroundRectangle

self.background_rectangle = BackgroundRectangle(
self, color=color, fill_opacity=opacity, **kwargs
self, color=ManimColor.parse(color), fill_opacity=opacity, **kwargs
)
self.add_to_back(self.background_rectangle)
return self
Expand Down
47 changes: 27 additions & 20 deletions manim/mobject/types/vectorized_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import typing
from typing import Optional, Sequence, Union

import colour
import numpy as np
from PIL.Image import Image

Expand All @@ -37,7 +36,7 @@
partial_bezier_points,
proportions_along_bezier_curve_for_point,
)
from ...utils.color import BLACK, WHITE, color_to_rgba
from ...utils.color import BLACK, WHITE, ManimColor, ParsableManimColor, color_to_rgba
from ...utils.deprecation import deprecated
from ...utils.iterables import make_even, stretch_array_to_length, tuplify
from ...utils.space_ops import rotate_vector, shoelace_direction
Expand Down Expand Up @@ -76,12 +75,12 @@ class VMobject(Mobject):

def __init__(
self,
fill_color=None,
fill_color: ParsableManimColor | None = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears that if fill_color or stroke color is a list of colors, it will be converted to a gradient in camera.py.

We should probably introduce a gradient object to make that explicit and less magical.

fill_opacity=0.0,
stroke_color=None,
stroke_color: ParsableManimColor | None = None,
stroke_opacity=1.0,
stroke_width=DEFAULT_STROKE_WIDTH,
background_stroke_color=BLACK,
background_stroke_color: ParsableManimColor | None = BLACK,
background_stroke_opacity=1.0,
background_stroke_width=0,
sheen_factor=0.0,
Expand All @@ -99,7 +98,10 @@ def __init__(
self.fill_opacity = fill_opacity
self.stroke_opacity = stroke_opacity
self.stroke_width = stroke_width
self.background_stroke_color = background_stroke_color
if background_stroke_color is not None:
self.background_stroke_color: ManimColor = ManimColor.parse(
background_stroke_color
)
self.background_stroke_opacity = background_stroke_opacity
self.background_stroke_width = background_stroke_width
self.sheen_factor = sheen_factor
Expand All @@ -114,11 +116,12 @@ def __init__(
self.tolerance_for_point_equality = tolerance_for_point_equality
self.n_points_per_cubic_curve = n_points_per_cubic_curve
super().__init__(**kwargs)
self.submobjects: list[VMobject]

if fill_color:
self.fill_color = fill_color
self.fill_color: ManimColor = ManimColor.parse(fill_color)
if stroke_color:
self.stroke_color = stroke_color
self.stroke_color: ManimColor = ManimColor.parse(stroke_color)

def get_group_class(self):
return VGroup
Expand Down Expand Up @@ -158,7 +161,7 @@ def init_colors(self, propagate_colors=True):

return self

def generate_rgbas_array(self, color, opacity):
def generate_rgbas_array(self, color: ManimColor | list[ManimColor], opacity):
"""
First arg can be either a color, or a tuple/list of colors.
Likewise, opacity can either be a float, or a tuple of floats.
Expand All @@ -169,7 +172,7 @@ def generate_rgbas_array(self, color, opacity):
colors = [c if (c is not None) else BLACK for c in tuplify(color)]
opacities = [o if (o is not None) else 0 for o in tuplify(opacity)]
rgbas = np.array(
[color_to_rgba(c, o) for c, o in zip(*make_even(colors, opacities))],
[c.to_rgb_with_alpha(o) for c, o in zip(*make_even(colors, opacities))],
)

sheen_factor = self.get_sheen_factor()
Expand All @@ -180,7 +183,9 @@ def generate_rgbas_array(self, color, opacity):
rgbas = np.append(rgbas, light_rgbas, axis=0)
return rgbas

def update_rgbas_array(self, array_name, color=None, opacity=None):
def update_rgbas_array(
self, array_name, color: ManimColor | None = None, opacity=None
):
rgbas = self.generate_rgbas_array(color, opacity)
if not hasattr(self, array_name):
setattr(self, array_name, rgbas)
Expand All @@ -203,7 +208,7 @@ def update_rgbas_array(self, array_name, color=None, opacity=None):

def set_fill(
self,
color: Optional[str] = None,
color: ParsableManimColor = None,
opacity: Optional[float] = None,
family: bool = True,
):
Expand Down Expand Up @@ -252,7 +257,7 @@ def construct(self):

def set_stroke(
self,
color=None,
color: ParsableManimColor = None,
width=None,
opacity=None,
background=False,
Expand All @@ -275,7 +280,7 @@ def set_stroke(
if opacity is not None:
setattr(self, opacity_name, opacity)
if color is not None and background:
self.background_stroke_color = color
self.background_stroke_color = ManimColor.parse(color)
return self

def set_background_stroke(self, **kwargs):
Expand All @@ -285,12 +290,12 @@ def set_background_stroke(self, **kwargs):

def set_style(
self,
fill_color=None,
fill_color: ParsableManimColor = None,
fill_opacity=None,
stroke_color=None,
stroke_color: ParsableManimColor = None,
stroke_width=None,
stroke_opacity=None,
background_stroke_color=None,
background_stroke_color: ParsableManimColor = None,
background_stroke_width=None,
background_stroke_opacity=None,
sheen_factor=None,
Expand Down Expand Up @@ -327,10 +332,11 @@ def get_style(self, simple=False):
"stroke_width": self.get_stroke_width(),
}

# TODO: FIX COLORS HERE
if simple:
ret["fill_color"] = colour.rgb2hex(self.get_fill_color().get_rgb())
ret["fill_color"] = self.get_fill_color().to_hex()
ret["fill_opacity"] = self.get_fill_opacity()
ret["stroke_color"] = colour.rgb2hex(self.get_stroke_color().get_rgb())
ret["stroke_color"] = self.get_stroke_color().to_hex()
else:
ret["fill_color"] = self.get_fill_colors()
ret["fill_opacity"] = self.get_fill_opacities()
Expand Down Expand Up @@ -359,7 +365,8 @@ def match_style(self, vmobject, family=True):
sm1.match_style(sm2)
return self

def set_color(self, color, family=True):
def set_color(self, color: ParsableManimColor, family=True):
color = ManimColor.parse(color)
self.set_fill(color, family=family)
self.set_stroke(color, family=family)
return self
Expand Down
Loading