From ae4eaf90a74c1a79d29eeb896da99fc78e72eb93 Mon Sep 17 00:00:00 2001 From: Iced-Tea3 <83535735+icedcoffeeee@users.noreply.github.com> Date: Sun, 5 Sep 2021 17:01:01 +0800 Subject: [PATCH 01/17] Add theme variable to config background color be set by theme --- manim/_config/default.cfg | 7 +++++-- manim/_config/utils.py | 29 ++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/manim/_config/default.cfg b/manim/_config/default.cfg index d62dc0defb..b44bea42d2 100644 --- a/manim/_config/default.cfg +++ b/manim/_config/default.cfg @@ -15,7 +15,7 @@ # generate a movie file. Note all of the following accept boolean values. # --notify_outdated_version -notify_outdated_version = True +notify_outdated_version = False # -w, --write_to_movie write_to_movie = True @@ -57,7 +57,10 @@ output_file = log_to_file = False # -c, --background_color -background_color = BLACK +background_color = None + +# theme +theme = dark_mode # --background_opacity background_opacity = 1 diff --git a/manim/_config/utils.py b/manim/_config/utils.py index fdbc5e3f0e..ae611311f1 100644 --- a/manim/_config/utils.py +++ b/manim/_config/utils.py @@ -279,6 +279,7 @@ class MyScene(Scene): "tex_dir", "tex_template_file", "text_dir", + "theme", "upto_animation_number", "renderer", "use_opengl_renderer", @@ -569,6 +570,7 @@ def digest_parser(self, parser: configparser.ConfigParser) -> "ManimConfig": "input_file", "output_file", "movie_file_extension", + "theme", "background_color", "renderer", "webgl_renderer_path", @@ -679,6 +681,7 @@ def digest_args(self, args: argparse.Namespace) -> "ManimConfig": "scene_names", "verbosity", "renderer", + "theme", "background_color", "use_opengl_renderer", "use_webgl_renderer", @@ -1004,10 +1007,34 @@ def format(self, val: str) -> None: background_color = property( lambda self: self._d["background_color"], - lambda self, val: self._d.__setitem__("background_color", colour.Color(val)), doc="Background color of the scene (-c).", ) + @background_color.setter + def background_color(self, val): + if val != "None": + self._d.__setitem__("background_color", colour.Color(val)) + else: + pass + + theme = property( + lambda self: self._d["theme"], + doc="Color theme of the scene (-c).", + ) + + @theme.setter + def theme(self, th: typing.Union[dict[str, dict[str]], str]) -> None: + if type(th) == str: + if th not in constants.THEMES: + raise KeyError(f"themes must be one of {list(constants.THEMES.keys())}") + t = constants.THEMES[th] + elif type(th) == dict: + t = constants.THEMES["dark_mode"] + t.update(th) + self._d["theme"] = t + self.mobject_color = t["mobject_color"] + self.background_color = t["background_color"] + from_animation_number = property( lambda self: self._d["from_animation_number"], lambda self, val: self._d.__setitem__("from_animation_number", val), From a7e9382af703321c41a966428f7f5f4a75e50c46 Mon Sep 17 00:00:00 2001 From: Iced-Tea3 <83535735+icedcoffeeee@users.noreply.github.com> Date: Sun, 5 Sep 2021 17:01:30 +0800 Subject: [PATCH 02/17] set premade themes --- manim/constants.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/manim/constants.py b/manim/constants.py index 8200ffdca1..466328f668 100644 --- a/manim/constants.py +++ b/manim/constants.py @@ -271,3 +271,22 @@ CONTEXT_SETTINGS = {"help_option_names": HELP_OPTIONS} SHIFT_VALUE = 65505 CTRL_VALUE = 65507 + +THEMES: dict[str, dict[str, str]] = { + "dark_mode": { + "mobject_color": "#fff", + "background_color": "#000", + }, + "light_mode": { + "mobject_color": "#000", + "background_color": "#fff", + }, + "sepia": { + "mobject_color": "#bcac80", + "background_color": "#704214", + }, + "seagreen": { + "mobject_color": "#fff", + "background_color": "#0f7d63", + }, +} From dcfd050d299f2c2d522f0ac98e392074f29abc03 Mon Sep 17 00:00:00 2001 From: Iced-Tea3 <83535735+icedcoffeeee@users.noreply.github.com> Date: Sun, 5 Sep 2021 17:18:53 +0800 Subject: [PATCH 03/17] redifine colors - placed functions on top - if a theme is used, greyscale is take as gradient --- manim/utils/color.py | 221 ++++++++++++++++++++++--------------------- 1 file changed, 113 insertions(+), 108 deletions(-) diff --git a/manim/utils/color.py b/manim/utils/color.py index d531f4bcbb..f00857c67d 100644 --- a/manim/utils/color.py +++ b/manim/utils/color.py @@ -25,11 +25,113 @@ import numpy as np from colour import Color +from .. import config, constants from ..utils.bezier import interpolate from ..utils.simple_functions import clip_in_place from ..utils.space_ops import normalize +def color_to_rgb(color: Union[Color, str]) -> np.ndarray: + if isinstance(color, str): + return hex_to_rgb(color) + elif isinstance(color, Color): + return np.array(color.get_rgb()) + else: + raise ValueError("Invalid color type: " + str(color)) + + +def color_to_rgba(color: Union[Color, str], alpha: float = 1) -> np.ndarray: + return np.array([*color_to_rgb(color), alpha]) + + +def rgb_to_color(rgb: Iterable[float]) -> Color: + return Color(rgb=rgb) + + +def rgba_to_color(rgba: Iterable[float]) -> Color: + return rgb_to_color(rgba[:3]) + + +def rgb_to_hex(rgb: Iterable[float]) -> str: + return "#" + "".join("%02x" % int(255 * x) for x in rgb) + + +def hex_to_rgb(hex_code: str) -> np.ndarray: + hex_part = hex_code[1:] + if len(hex_part) == 3: + hex_part = "".join([2 * c for c in hex_part]) + return np.array([int(hex_part[i : i + 2], 16) / 255 for i in range(0, 6, 2)]) + + +def invert_color(color: Color) -> Color: + return rgb_to_color(1.0 - color_to_rgb(color)) + + +def color_to_int_rgb(color: Color) -> np.ndarray: + return (255 * color_to_rgb(color)).astype("uint8") + + +def color_to_int_rgba(color: Color, opacity: float = 1.0) -> np.ndarray: + alpha = int(255 * opacity) + return np.append(color_to_int_rgb(color), alpha) + + +def color_gradient( + reference_colors: Iterable[Color], + length_of_output: int, +) -> List[Color]: + if length_of_output == 0: + return reference_colors[0] + rgbs = list(map(color_to_rgb, reference_colors)) + alphas = np.linspace(0, (len(rgbs) - 1), length_of_output) + floors = alphas.astype("int") + alphas_mod1 = alphas % 1 + # End edge case + alphas_mod1[-1] = 1 + floors[-1] = len(rgbs) - 2 + return [ + rgb_to_color(interpolate(rgbs[i], rgbs[i + 1], alpha)) + for i, alpha in zip(floors, alphas_mod1) + ] + + +def interpolate_color(color1: Color, color2: Color, alpha: float) -> Color: + rgb = interpolate(color_to_rgb(color1), color_to_rgb(color2), alpha) + return rgb_to_color(rgb) + + +def average_color(*colors: Color) -> Color: + rgbs = np.array(list(map(color_to_rgb, colors))) + mean_rgb = np.apply_along_axis(np.mean, 0, rgbs) + return rgb_to_color(mean_rgb) + + +def random_bright_color() -> Color: + color = random_color() + curr_rgb = color_to_rgb(color) + new_rgb = interpolate(curr_rgb, np.ones(len(curr_rgb)), 0.5) + return Color(rgb=new_rgb) + + +def random_color() -> Color: + return random.choice([c.value for c in list(Colors)]) + + +def get_shaded_rgb( + rgb: np.ndarray, + point: np.ndarray, + unit_normal_vect: np.ndarray, + light_source: np.ndarray, +) -> np.ndarray: + to_sun = normalize(light_source - point) + factor = 0.5 * np.dot(unit_normal_vect, to_sun) ** 3 + if factor < 0: + factor *= 0.5 + result = rgb + factor + clip_in_place(rgb + factor, 0, 1) + return result + + class Colors(Enum): """A list of pre-defined colors. @@ -178,13 +280,17 @@ def named_lines_group(length, colors, names, text_colors, align_to_block): """ - white = "#FFFFFF" - gray_a = "#DDDDDD" - gray_b = "#BBBBBB" - gray_c = "#888888" - gray_d = "#444444" - gray_e = "#222222" - black = "#000000" + white = config["mobject_color"] + black = config["background_color"] + + if config["theme"] != constants.THEMES["dark_mode"]: + gray_a, gray_b, gray_c, gray_d, gray_e = color_gradient([white, black], 7)[1:6] + else: + gray_a = "#DDDDDD" + gray_b = "#BBBBBB" + gray_c = "#888888" + gray_d = "#444444" + gray_e = "#222222" lighter_gray = gray_a light_gray = gray_b gray = gray_c @@ -361,104 +467,3 @@ def named_lines_group(length, colors, names, text_colors, align_to_block): "GRAY_BROWN", "GREY_BROWN", ] - - -def color_to_rgb(color: Union[Color, str]) -> np.ndarray: - if isinstance(color, str): - return hex_to_rgb(color) - elif isinstance(color, Color): - return np.array(color.get_rgb()) - else: - raise ValueError("Invalid color type: " + str(color)) - - -def color_to_rgba(color: Union[Color, str], alpha: float = 1) -> np.ndarray: - return np.array([*color_to_rgb(color), alpha]) - - -def rgb_to_color(rgb: Iterable[float]) -> Color: - return Color(rgb=rgb) - - -def rgba_to_color(rgba: Iterable[float]) -> Color: - return rgb_to_color(rgba[:3]) - - -def rgb_to_hex(rgb: Iterable[float]) -> str: - return "#" + "".join("%02x" % int(255 * x) for x in rgb) - - -def hex_to_rgb(hex_code: str) -> np.ndarray: - hex_part = hex_code[1:] - if len(hex_part) == 3: - hex_part = "".join([2 * c for c in hex_part]) - return np.array([int(hex_part[i : i + 2], 16) / 255 for i in range(0, 6, 2)]) - - -def invert_color(color: Color) -> Color: - return rgb_to_color(1.0 - color_to_rgb(color)) - - -def color_to_int_rgb(color: Color) -> np.ndarray: - return (255 * color_to_rgb(color)).astype("uint8") - - -def color_to_int_rgba(color: Color, opacity: float = 1.0) -> np.ndarray: - alpha = int(255 * opacity) - return np.append(color_to_int_rgb(color), alpha) - - -def color_gradient( - reference_colors: Iterable[Color], - length_of_output: int, -) -> List[Color]: - if length_of_output == 0: - return reference_colors[0] - rgbs = list(map(color_to_rgb, reference_colors)) - alphas = np.linspace(0, (len(rgbs) - 1), length_of_output) - floors = alphas.astype("int") - alphas_mod1 = alphas % 1 - # End edge case - alphas_mod1[-1] = 1 - floors[-1] = len(rgbs) - 2 - return [ - rgb_to_color(interpolate(rgbs[i], rgbs[i + 1], alpha)) - for i, alpha in zip(floors, alphas_mod1) - ] - - -def interpolate_color(color1: Color, color2: Color, alpha: float) -> Color: - rgb = interpolate(color_to_rgb(color1), color_to_rgb(color2), alpha) - return rgb_to_color(rgb) - - -def average_color(*colors: Color) -> Color: - rgbs = np.array(list(map(color_to_rgb, colors))) - mean_rgb = np.apply_along_axis(np.mean, 0, rgbs) - return rgb_to_color(mean_rgb) - - -def random_bright_color() -> Color: - color = random_color() - curr_rgb = color_to_rgb(color) - new_rgb = interpolate(curr_rgb, np.ones(len(curr_rgb)), 0.5) - return Color(rgb=new_rgb) - - -def random_color() -> Color: - return random.choice([c.value for c in list(Colors)]) - - -def get_shaded_rgb( - rgb: np.ndarray, - point: np.ndarray, - unit_normal_vect: np.ndarray, - light_source: np.ndarray, -) -> np.ndarray: - to_sun = normalize(light_source - point) - factor = 0.5 * np.dot(unit_normal_vect, to_sun) ** 3 - if factor < 0: - factor *= 0.5 - result = rgb + factor - clip_in_place(rgb + factor, 0, 1) - return result From 5be28dcaf286e2e71294a2a8e635cc03a2b72ed5 Mon Sep 17 00:00:00 2001 From: Iced-Tea3 <83535735+icedcoffeeee@users.noreply.github.com> Date: Sun, 5 Sep 2021 17:19:27 +0800 Subject: [PATCH 04/17] pre-commit --- docs/source/conduct.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/conduct.md b/docs/source/conduct.md index a3613c99f0..9c7b4f37b8 120000 --- a/docs/source/conduct.md +++ b/docs/source/conduct.md @@ -1 +1 @@ -../../CODE_OF_CONDUCT.md \ No newline at end of file +../../CODE_OF_CONDUCT.md From c7d7f55aaf43bd2c9fa9c91aab4000815cd2dac5 Mon Sep 17 00:00:00 2001 From: Iced-Tea3 <83535735+icedcoffeeee@users.noreply.github.com> Date: Sun, 5 Sep 2021 17:41:55 +0800 Subject: [PATCH 05/17] typing typo --- manim/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/constants.py b/manim/constants.py index 466328f668..815e88494f 100644 --- a/manim/constants.py +++ b/manim/constants.py @@ -272,7 +272,7 @@ SHIFT_VALUE = 65505 CTRL_VALUE = 65507 -THEMES: dict[str, dict[str, str]] = { +THEMES: typing.Dict[str, typing.Dict[str, str]] = { "dark_mode": { "mobject_color": "#fff", "background_color": "#000", From 21e606f19281c9f9609d0b899e90835f0ad270d3 Mon Sep 17 00:00:00 2001 From: Iced-Tea3 <83535735+icedcoffeeee@users.noreply.github.com> Date: Sun, 5 Sep 2021 17:46:58 +0800 Subject: [PATCH 06/17] typing :/ --- manim/_config/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/_config/utils.py b/manim/_config/utils.py index 05c469b943..f40b596fcd 100644 --- a/manim/_config/utils.py +++ b/manim/_config/utils.py @@ -1025,7 +1025,7 @@ def background_color(self, val): ) @theme.setter - def theme(self, th: typing.Union[dict[str, dict[str]], str]) -> None: + def theme(self, th: typing.Union[typing.Dict[str, typing.Dict[str, str]], str]) -> None: if type(th) == str: if th not in constants.THEMES: raise KeyError(f"themes must be one of {list(constants.THEMES.keys())}") From d9d1bdd8353ec9c1e6579dd5cae1e6f76fa29324 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 5 Sep 2021 09:47:53 +0000 Subject: [PATCH 07/17] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- manim/_config/utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/manim/_config/utils.py b/manim/_config/utils.py index f40b596fcd..a41b39a4a1 100644 --- a/manim/_config/utils.py +++ b/manim/_config/utils.py @@ -1025,7 +1025,9 @@ def background_color(self, val): ) @theme.setter - def theme(self, th: typing.Union[typing.Dict[str, typing.Dict[str, str]], str]) -> None: + def theme( + self, th: typing.Union[typing.Dict[str, typing.Dict[str, str]], str] + ) -> None: if type(th) == str: if th not in constants.THEMES: raise KeyError(f"themes must be one of {list(constants.THEMES.keys())}") From 39af829d37e235436fc72730b2624f316843d0b3 Mon Sep 17 00:00:00 2001 From: Iced-Tea3 <83535735+icedcoffeeee@users.noreply.github.com> Date: Sun, 5 Sep 2021 17:55:44 +0800 Subject: [PATCH 08/17] pre-commit --- manim/_config/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/manim/_config/utils.py b/manim/_config/utils.py index a41b39a4a1..0f0c98e18d 100644 --- a/manim/_config/utils.py +++ b/manim/_config/utils.py @@ -1026,7 +1026,8 @@ def background_color(self, val): @theme.setter def theme( - self, th: typing.Union[typing.Dict[str, typing.Dict[str, str]], str] + self, + th: typing.Union[typing.Dict[str, typing.Dict[str, str]], str], ) -> None: if type(th) == str: if th not in constants.THEMES: From e26b02f4c7262e5ee67d76d24578309c589c097c Mon Sep 17 00:00:00 2001 From: icedcoffeeee <83535735+icedcoffeeee@users.noreply.github.com> Date: Sun, 5 Sep 2021 21:02:24 +0800 Subject: [PATCH 09/17] Update conduct.md From 6bbe163c8cfd1c34e007a3ef8111bea1cf8700c4 Mon Sep 17 00:00:00 2001 From: Iced-Tea3 <83535735+icedcoffeeee@users.noreply.github.com> Date: Sun, 5 Sep 2021 21:06:51 +0800 Subject: [PATCH 10/17] allow custom dict --- manim/_config/utils.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/manim/_config/utils.py b/manim/_config/utils.py index 0f0c98e18d..709cbbdc0a 100644 --- a/manim/_config/utils.py +++ b/manim/_config/utils.py @@ -1015,7 +1015,7 @@ def format(self, val: str) -> None: @background_color.setter def background_color(self, val): if val != "None": - self._d.__setitem__("background_color", colour.Color(val)) + self._d.__setitem__("background_color", val) else: pass @@ -1027,15 +1027,19 @@ def background_color(self, val): @theme.setter def theme( self, - th: typing.Union[typing.Dict[str, typing.Dict[str, str]], str], + th: str, ) -> None: - if type(th) == str: + if th.startswith("{"): # a custom dictionary + try: + th = eval(th) + except: + raise + t = constants.THEMES["dark_mode"] + t.update(th) + else: # predefined theme if th not in constants.THEMES: raise KeyError(f"themes must be one of {list(constants.THEMES.keys())}") t = constants.THEMES[th] - elif type(th) == dict: - t = constants.THEMES["dark_mode"] - t.update(th) self._d["theme"] = t self.mobject_color = t["mobject_color"] self.background_color = t["background_color"] From d2720714767ab221475949d02451c5a70e195566 Mon Sep 17 00:00:00 2001 From: Iced-Tea3 <83535735+icedcoffeeee@users.noreply.github.com> Date: Sun, 5 Sep 2021 21:11:39 +0800 Subject: [PATCH 11/17] uniform hex format --- manim/constants.py | 14 +++++++------- manim/utils/color.py | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manim/constants.py b/manim/constants.py index 815e88494f..054a4a9845 100644 --- a/manim/constants.py +++ b/manim/constants.py @@ -274,19 +274,19 @@ THEMES: typing.Dict[str, typing.Dict[str, str]] = { "dark_mode": { - "mobject_color": "#fff", - "background_color": "#000", + "mobject_color": "#FFFFFF", + "background_color": "#000000", }, "light_mode": { - "mobject_color": "#000", - "background_color": "#fff", + "mobject_color": "#000000", + "background_color": "#FFFFFF", }, "sepia": { - "mobject_color": "#bcac80", + "mobject_color": "#BCAC80", "background_color": "#704214", }, "seagreen": { - "mobject_color": "#fff", - "background_color": "#0f7d63", + "mobject_color": "#FFFFFF", + "background_color": "#0F7D63", }, } diff --git a/manim/utils/color.py b/manim/utils/color.py index f00857c67d..0b92fcda37 100644 --- a/manim/utils/color.py +++ b/manim/utils/color.py @@ -283,7 +283,7 @@ def named_lines_group(length, colors, names, text_colors, align_to_block): white = config["mobject_color"] black = config["background_color"] - if config["theme"] != constants.THEMES["dark_mode"]: + if [white, black] != ["#FFFFFF", "#000000"]: gray_a, gray_b, gray_c, gray_d, gray_e = color_gradient([white, black], 7)[1:6] else: gray_a = "#DDDDDD" From 5529fc668d45e6af24763a7f021a92ae9dfb3ded Mon Sep 17 00:00:00 2001 From: Iced-Tea3 <83535735+icedcoffeeee@users.noreply.github.com> Date: Sun, 5 Sep 2021 21:29:06 +0800 Subject: [PATCH 12/17] accidental change --- manim/_config/default.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/_config/default.cfg b/manim/_config/default.cfg index 6a9a960030..3a60397337 100644 --- a/manim/_config/default.cfg +++ b/manim/_config/default.cfg @@ -15,7 +15,7 @@ # generate a movie file. Note all of the following accept boolean values. # --notify_outdated_version -notify_outdated_version = False +notify_outdated_version = True # -w, --write_to_movie write_to_movie = True From ec78a7b831cb3714cef1685b8ff8ad6887fc6618 Mon Sep 17 00:00:00 2001 From: icedcoffeeee <83535735+icedcoffeeee@users.noreply.github.com> Date: Sun, 5 Sep 2021 21:37:58 +0800 Subject: [PATCH 13/17] Revert "pre-commit" This reverts commit 5be28dcaf286e2e71294a2a8e635cc03a2b72ed5. --- docs/source/conduct.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/conduct.md b/docs/source/conduct.md index 9c7b4f37b8..a3613c99f0 120000 --- a/docs/source/conduct.md +++ b/docs/source/conduct.md @@ -1 +1 @@ -../../CODE_OF_CONDUCT.md +../../CODE_OF_CONDUCT.md \ No newline at end of file From 893e8368c60862caaea2bdddcb6dfba845370510 Mon Sep 17 00:00:00 2001 From: icedcoffeeee <83535735+icedcoffeeee@users.noreply.github.com> Date: Sun, 5 Sep 2021 22:20:25 +0800 Subject: [PATCH 14/17] Update utils.py --- manim/_config/utils.py | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/manim/_config/utils.py b/manim/_config/utils.py index 709cbbdc0a..589f914950 100644 --- a/manim/_config/utils.py +++ b/manim/_config/utils.py @@ -1027,22 +1027,25 @@ def background_color(self, val): @theme.setter def theme( self, - th: str, + th: typing.Union[str, typing.Dict[str, str]], ) -> None: - if th.startswith("{"): # a custom dictionary - try: - th = eval(th) - except: - raise - t = constants.THEMES["dark_mode"] - t.update(th) - else: # predefined theme - if th not in constants.THEMES: - raise KeyError(f"themes must be one of {list(constants.THEMES.keys())}") - t = constants.THEMES[th] - self._d["theme"] = t - self.mobject_color = t["mobject_color"] - self.background_color = t["background_color"] + if type(th) == str: + if th.startswith("{"): # a custom dictionary + try: + t = eval(th) + except: + raise + th = constants.THEMES["dark_mode"] + th.update(t) + else: # predefined theme + if th not in constants.THEMES: + raise KeyError( + f"themes must be one of {list(constants.THEMES.keys())}", + ) + th = constants.THEMES[th] + self._d["theme"] = th + self.mobject_color = th["mobject_color"] + self.background_color = th["background_color"] from_animation_number = property( lambda self: self._d["from_animation_number"], From 5cd918b94fb217bfd181486a0690dac62c2fc490 Mon Sep 17 00:00:00 2001 From: icedcoffeeee <83535735+icedcoffeeee@users.noreply.github.com> Date: Mon, 6 Sep 2021 00:07:51 +0800 Subject: [PATCH 15/17] added test --- tests/test_config.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/test_config.py b/tests/test_config.py index 607dff5976..e0e5880f06 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -64,6 +64,15 @@ def test_background_color(): assert np.allclose(frame[0, 0], [255, 255, 255, 255]) +def test_theme(): + """Test the 'theme' config option.""" + with tempconfig({"theme": "seagreen"}): + scene = MyScene() + scene.render() + frame = scene.renderer.get_frame() + assert np.allclose(frame[0, 0], [15, 125, 99, 255]) + + def test_digest_file(tmp_path): """Test that a config file can be digested programmatically.""" with tempconfig({}): From c538b8bdb0005dc3e81aa34d6dc245c03c21277a Mon Sep 17 00:00:00 2001 From: icedcoffeeee <83535735+icedcoffeeee@users.noreply.github.com> Date: Mon, 6 Sep 2021 00:08:15 +0800 Subject: [PATCH 16/17] added documentation --- manim/_config/utils.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/manim/_config/utils.py b/manim/_config/utils.py index 589f914950..66681f218a 100644 --- a/manim/_config/utils.py +++ b/manim/_config/utils.py @@ -236,6 +236,41 @@ class MyScene(Scene): the background color will be set to RED, regardless of the contents of ``manim.cfg`` or the CLI arguments used when invoking manim. + Themes + ------ + There are options to set manim to follow a specific color scheme. You need to + make a ``.cfg`` file with which contains the line: + .. code-block:: cfg + + [CLI] + + theme = light_mode + + The options of the themes include + - dark_mode (default) + - light_mode (white background and black mobjects) + - sepia (brown-esque) + - seagreen + + .. important:: + The theme cannot be stated from within your manim script. + + You could also pass your own theme: + + .. code-block:: cfg + + [CLI] + + theme = {"mobject_color": "#000", "background_color": "#555"} + + .. note:: + The theme changes the definition of some colors, namely the greyscale + family. ``WHITE`` will refer to the newly set "mobject_color" and + ``BLACK`` will refer to the new "background_color". Every grey in between + (GREY_A, GREY_B and so on) will be a gradient between the two ``WHITE`` + and ``BLACK``. If you wish to refer to the pure colors, you may pass + their hex codes instead. + """ _OPTS = { From 87cdbffcdd6e3d5f195fc20eab514e34794f60a7 Mon Sep 17 00:00:00 2001 From: icedcoffeeee <83535735+icedcoffeeee@users.noreply.github.com> Date: Mon, 6 Sep 2021 13:33:28 +0800 Subject: [PATCH 17/17] Updated documentation --- manim/_config/utils.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/manim/_config/utils.py b/manim/_config/utils.py index 66681f218a..e436defefb 100644 --- a/manim/_config/utils.py +++ b/manim/_config/utils.py @@ -239,18 +239,20 @@ class MyScene(Scene): Themes ------ There are options to set manim to follow a specific color scheme. You need to - make a ``.cfg`` file with which contains the line: + make a ``.cfg`` file with which contains the lines: + .. code-block:: cfg [CLI] theme = light_mode - The options of the themes include - - dark_mode (default) - - light_mode (white background and black mobjects) - - sepia (brown-esque) - - seagreen + The options of the themes include: + + * dark_mode (default) + * light_mode (white background and black mobjects) + * sepia (brown-esque) + * seagreen .. important:: The theme cannot be stated from within your manim script. @@ -267,9 +269,9 @@ class MyScene(Scene): The theme changes the definition of some colors, namely the greyscale family. ``WHITE`` will refer to the newly set "mobject_color" and ``BLACK`` will refer to the new "background_color". Every grey in between - (GREY_A, GREY_B and so on) will be a gradient between the two ``WHITE`` - and ``BLACK``. If you wish to refer to the pure colors, you may pass - their hex codes instead. + (``GREY_A``, ``GREY_B`` and so on) will be a gradient between the two + ``WHITE`` and ``BLACK``. If you wish to refer to the pure colors, + you may pass their hex codes instead. """