Skip to content

Commit 82e55b5

Browse files
MrDiverpre-commit-ci[bot]behacklnaveen521kk
authored
Adding :class: ManimColor to manim and converting all types (#3020)
* first draft of color class + starting library conversion * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * changed everything to Manim color todo: figure out circular dependency in utils * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * first working draft of new color version * resolving conflicts * resolving conflicts * resolving conflicts * resolving conflicts * resolving conflicts * changed default internal value of ManimColor to np.ndarray[float] * starting to fix tests * fixed more tests and changed precision of manim color * removed premature color conversion * fixed some more tests * final test changes * fix doctests * fix for 3.8 * fixing ManimColor string representation * removing some unneccesary conversions * moved community constants to manim_colors.py and added more color standards * broke some too long lines * added fallback: check whether passed object has get_hex method * actually fix _internal_from_string * added hsv support * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * remove dependency on colour * fixed DARK_EARTH being assigned twice * fixed double assignment * remove more duplicated colour names * raise NotImplementedError for ManimColor.gradient * removed unused import * remove superfluous ManimColor import * fix circular import, remove dependency of space_ops on config * one more Color -> ParseableManimColor * removed one *-import * somewhat unrelated fixed type hint * -1 *-import * fixed change of logic in CoordinateSystem.get_graph_label * removed debug print; fixed type hint in mobject.py * some fixes and improvements to text_mobject.py * update three_dimensions * fixes for rendered documentation of utils.color.* * substantial improvements to documentation, including new Sphinx directive Co-authored-by: MrDiver <[email protected]> * Rewrite of the sphinx directive to use docutils nodes and 2 column design * I just had to do it * Improve the color table * minor cleanup * fixed ColorOverview example * documentation improvements * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update manim/mobject/mobject.py Co-authored-by: Benjamin Hackl <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix flake8 errors * Removed test in test_text_mobject * Improved Documentation of core.py and added private members in sphinx so that internal methods can be documented * Change color types of labeled.py * removed some unused imports * turned docstring into comment * _colors -> _all_manim_colors; move to manim_color module * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fixed typing * rewrite import --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Benjamin Hackl <[email protected]> Co-authored-by: Naveen M K <[email protected]>
1 parent 59ff327 commit 82e55b5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+4730
-1710
lines changed

.mypy.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ ignore_errors = True
2323
[mypy-manim.utils.*]
2424
ignore_errors = True
2525

26+
[mypy-manim.utils.color]
27+
ignore_errors = False
28+
2629
[mypy-manim.animation.*]
2730
ignore_errors = True
2831

docs/source/_templates/autosummary/class.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Qualified name: ``{{ fullname | escape }}``
77
.. autoclass:: {{ objname }}
88
:show-inheritance:
99
:members:
10+
:private-members:
11+
1012

1113
{% block methods %}
1214
{%- if methods %}

docs/source/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"sphinx.ext.viewcode",
4444
"sphinxext.opengraph",
4545
"manim.utils.docbuild.manim_directive",
46+
"manim.utils.docbuild.autocolor_directive",
4647
"sphinx.ext.graphviz",
4748
"sphinx.ext.inheritance_diagram",
4849
"sphinxcontrib.programoutput",

manim/_config/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
from pathlib import Path
2424
from typing import Any, Iterable, Iterator
2525

26-
import colour
2726
import numpy as np
2827

2928
from .. import constants
3029
from ..constants import RendererType
30+
from ..utils.color import ManimColor
3131
from ..utils.tex import TexTemplate, TexTemplateFromFile
3232
from ..utils.tex_templates import TexTemplateLibrary
3333

@@ -1096,7 +1096,7 @@ def format(self, val: str) -> None:
10961096

10971097
background_color = property(
10981098
lambda self: self._d["background_color"],
1099-
lambda self, val: self._d.__setitem__("background_color", colour.Color(val)),
1099+
lambda self, val: self._d.__setitem__("background_color", ManimColor(val)),
11001100
doc="Background color of the scene (-c).",
11011101
)
11021102

manim/animation/changing.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@
66

77
from typing import Callable
88

9-
from colour import Color
10-
119
from manim._config import config
1210
from manim.mobject.opengl.opengl_compatibility import ConvertToOpenGL
1311
from manim.mobject.types.vectorized_mobject import VGroup, VMobject
14-
from manim.utils.color import BLUE_B, BLUE_D, BLUE_E, GREY_BROWN, WHITE
12+
from manim.utils.color import (
13+
BLUE_B,
14+
BLUE_D,
15+
BLUE_E,
16+
GREY_BROWN,
17+
WHITE,
18+
ParsableManimColor,
19+
)
1520
from manim.utils.rate_functions import smooth
1621

1722

@@ -140,7 +145,7 @@ def __init__(
140145
self,
141146
traced_point_func: Callable,
142147
stroke_width: float = 2,
143-
stroke_color: Color = WHITE,
148+
stroke_color: ParsableManimColor | None = WHITE,
144149
dissipating_time: float | None = None,
145150
**kwargs,
146151
):

manim/animation/creation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ def construct(self):
7777
from typing import TYPE_CHECKING, Callable, Iterable, Sequence
7878

7979
import numpy as np
80-
from colour import Color
8180

8281
if TYPE_CHECKING:
8382
from manim.mobject.text.text_mobject import Text
8483

8584
from manim.mobject.opengl.opengl_surface import OpenGLSurface
8685
from manim.mobject.opengl.opengl_vectorized_mobject import OpenGLVMobject
86+
from manim.utils.color import ManimColor
8787

8888
from .. import config
8989
from ..animation.animation import Animation
@@ -259,7 +259,7 @@ def get_outline(self) -> Mobject:
259259
sm.set_stroke(color=self.get_stroke_color(sm), width=self.stroke_width)
260260
return outline
261261

262-
def get_stroke_color(self, vmobject: VMobject | OpenGLVMobject) -> Color:
262+
def get_stroke_color(self, vmobject: VMobject | OpenGLVMobject) -> ManimColor:
263263
if self.stroke_color:
264264
return self.stroke_color
265265
elif vmobject.get_stroke_width() > 0:

manim/animation/indication.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ def construct(self):
4040
from typing import Callable, Iterable, Optional, Tuple, Type, Union
4141

4242
import numpy as np
43-
from colour import Color
4443

4544
from manim.mobject.geometry.arc import Circle, Dot
4645
from manim.mobject.geometry.line import Line
@@ -58,7 +57,7 @@ def construct(self):
5857
from ..mobject.mobject import Mobject
5958
from ..mobject.types.vectorized_mobject import VGroup, VMobject
6059
from ..utils.bezier import interpolate, inverse_interpolate
61-
from ..utils.color import GREY, YELLOW
60+
from ..utils.color import GREY, YELLOW, ParsableManimColor
6261
from ..utils.deprecation import deprecated
6362
from ..utils.rate_functions import smooth, there_and_back, wiggle
6463
from ..utils.space_ops import normalize
@@ -609,7 +608,7 @@ def __init__(
609608
fade_out=False,
610609
time_width=0.3,
611610
buff: float = SMALL_BUFF,
612-
color: Color = YELLOW,
611+
color: ParsableManimColor = YELLOW,
613612
run_time=1,
614613
stroke_width=DEFAULT_STROKE_WIDTH,
615614
**kwargs

manim/camera/camera.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from ..mobject.types.image_mobject import AbstractImageMobject
2525
from ..mobject.types.point_cloud_mobject import PMobject
2626
from ..mobject.types.vectorized_mobject import VMobject
27-
from ..utils.color import color_to_int_rgba
27+
from ..utils.color import ManimColor, ParsableManimColor, color_to_int_rgba
2828
from ..utils.family import extract_mobject_family_members
2929
from ..utils.images import get_full_raster_image_path
3030
from ..utils.iterables import list_difference_update
@@ -75,6 +75,8 @@ def __init__(
7575
frame_height: float | None = None,
7676
frame_width: float | None = None,
7777
frame_rate: float | None = None,
78+
background_color: ParsableManimColor | None = None,
79+
background_opacity: float | None = None,
7880
**kwargs,
7981
):
8082
self.background_image = background_image
@@ -106,9 +108,14 @@ def __init__(
106108
frame_rate = config["frame_rate"]
107109
self.frame_rate = frame_rate
108110

109-
# TODO: change this to not use kwargs.get
110-
for attr in ["background_color", "background_opacity"]:
111-
setattr(self, f"_{attr}", kwargs.get(attr, config[attr]))
111+
if background_color is None:
112+
self._background_color = ManimColor.parse(config["background_color"])
113+
else:
114+
self._background_color = ManimColor.parse(background_color)
115+
if background_opacity is None:
116+
self._background_opacity = config["background_opacity"]
117+
else:
118+
self._background_opacity = background_opacity
112119

113120
# This one is in the same boat as the above, but it doesn't have the
114121
# same name as the corresponding key so it has to be handled on its own

manim/communitycolors.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

manim/mobject/geometry/arc.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ def construct(self):
4848
from typing import TYPE_CHECKING, Sequence
4949

5050
import numpy as np
51-
from colour import Color
5251

5352
from manim.constants import *
5453
from manim.mobject.opengl.opengl_compatibility import ConvertToOpenGL
@@ -492,7 +491,7 @@ def construct(self):
492491
def __init__(
493492
self,
494493
radius: float | None = None,
495-
color: Color | str = RED,
494+
color: ParsableManimColor = RED,
496495
**kwargs,
497496
):
498497
super().__init__(
@@ -658,7 +657,7 @@ def __init__(
658657
radius: float = DEFAULT_DOT_RADIUS,
659658
stroke_width: float = 0,
660659
fill_opacity: float = 1.0,
661-
color: Color | str = WHITE,
660+
color: ParsableManimColor = WHITE,
662661
**kwargs,
663662
):
664663
super().__init__(

0 commit comments

Comments
 (0)