-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Adding :class: ManimColor to manim and converting all types #3020
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
Merged
Merged
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 01e28fd
Merge branch 'main' into color_fix
MrDiver a0e85af
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 8af3f81
Merge branch 'main' into color_fix
MrDiver 332d327
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] da0806a
changed everything to Manim color todo: figure out circular dependenc…
MrDiver 73ffb51
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 157c504
first working draft of new color version
MrDiver a7e4a3e
Merge branch 'main' into color_fix
MrDiver d21583d
resolving conflicts
MrDiver 074345e
resolving conflicts
MrDiver 128b8ab
resolving conflicts
MrDiver 31bcdac
resolving conflicts
MrDiver 27c0ddb
resolving conflicts
MrDiver 195512a
changed default internal value of ManimColor to np.ndarray[float]
MrDiver 9823616
starting to fix tests
MrDiver e638643
fixed more tests and changed precision of manim color
MrDiver 7867aa3
removed premature color conversion
MrDiver a12507a
fixed some more tests
MrDiver 15c4998
final test changes
MrDiver 76d7cda
fix doctests
MrDiver a27aff4
fix for 3.8
MrDiver 1580c82
fixing ManimColor string representation
MrDiver b2cc282
removing some unneccesary conversions
MrDiver 2baeff5
moved community constants to manim_colors.py and added more color sta…
MrDiver 86c5d07
Merge branch 'main' into color_fix
MrDiver d1bc9fc
Merge branch 'experimental' into color_fix
MrDiver bd32291
broke some too long lines
behackl 9dd9ba2
added fallback: check whether passed object has get_hex method
behackl d9c1d6f
actually fix _internal_from_string
behackl 6499b86
added hsv support
behackl 695373b
Merge remote-tracking branch 'origin/main' into color_fix
behackl bbef400
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] d32f0d5
remove dependency on colour
behackl f0297e6
fixed DARK_EARTH being assigned twice
behackl 3eeeaf2
fixed double assignment
behackl b265091
remove more duplicated colour names
behackl f7db270
raise NotImplementedError for ManimColor.gradient
behackl 2befc10
removed unused import
behackl d18a8dc
Merge branch 'color_fix' of github.com:MrDiver/manim into color_fix
behackl 7a99a46
remove superfluous ManimColor import
behackl 5bb6369
fix circular import, remove dependency of space_ops on config
behackl d4ffe5c
one more Color -> ParseableManimColor
behackl 9085d79
removed one *-import
behackl 03cdd78
somewhat unrelated fixed type hint
behackl 5b990ca
-1 *-import
behackl c9f3311
fixed change of logic in CoordinateSystem.get_graph_label
behackl b144852
removed debug print; fixed type hint in mobject.py
behackl ed9de63
some fixes and improvements to text_mobject.py
behackl 4099acd
update three_dimensions
behackl bd040e6
fixes for rendered documentation of utils.color.*
behackl 77a2950
substantial improvements to documentation, including new Sphinx direc…
behackl 9d97821
Rewrite of the sphinx directive to use docutils nodes and 2 column de…
MrDiver fe6d1c9
I just had to do it
MrDiver d8dfdb2
Improve the color table
naveen521kk 9880f59
minor cleanup
behackl 771113e
fixed ColorOverview example
behackl 56ba61a
documentation improvements
behackl 1e6be03
Merge remote-tracking branch 'origin/main' into color_fix
behackl 3c1ca10
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 322249a
merge fix
MrDiver 3282c75
Update manim/mobject/mobject.py
MrDiver 884846e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] e1c8419
fix flake8 errors
behackl 025cd3a
Removed test in test_text_mobject
MrDiver 7b599f2
Improved Documentation of core.py and added private members in sphinx…
MrDiver 1c6899f
Merge branch 'main' of github.com:ManimCommunity/manim into color_fix
MrDiver 4388cce
Change color types of labeled.py
MrDiver f41bef3
removed some unused imports
behackl c3e7b99
turned docstring into comment
behackl 112470d
_colors -> _all_manim_colors; move to manim_color module
behackl 38d3c3f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 3576be6
fixed typing
behackl 7da5946
rewrite import
behackl 6651ab9
Merge branch 'main' into color_fix
MrDiver File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,6 @@ | |
| import typing | ||
| from typing import Optional, Sequence, Union | ||
|
|
||
| import colour | ||
| import numpy as np | ||
| from PIL.Image import Image | ||
|
|
||
|
|
@@ -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 | ||
|
|
@@ -76,12 +75,12 @@ class VMobject(Mobject): | |
|
|
||
| def __init__( | ||
| self, | ||
| fill_color=None, | ||
| fill_color: ParsableManimColor | None = None, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
|
@@ -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 | ||
|
|
@@ -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 | ||
|
|
@@ -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. | ||
|
|
@@ -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() | ||
|
|
@@ -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) | ||
|
|
@@ -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, | ||
| ): | ||
|
|
@@ -252,7 +257,7 @@ def construct(self): | |
|
|
||
| def set_stroke( | ||
| self, | ||
| color=None, | ||
| color: ParsableManimColor = None, | ||
| width=None, | ||
| opacity=None, | ||
| background=False, | ||
|
|
@@ -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): | ||
|
|
@@ -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, | ||
|
|
@@ -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() | ||
|
|
@@ -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 | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.