Skip to content

Make colour aliases IDE-friendly #2050

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 4 commits into from
Oct 2, 2021
Merged
Changes from all commits
Commits
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
127 changes: 107 additions & 20 deletions manim/utils/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,25 +260,112 @@ def named_lines_group(length, colors, names, text_colors, align_to_block):
gray_brown = "#736357"


# Create constants from Colors enum
constants_names = []
for name, value in Colors.__members__.items():
name = name.upper()
value = value.value
constants_names.append(name)
locals()[name] = value
if "GRAY" in name:
name = name.replace("GRAY", "GREY")
locals()[name] = value
constants_names.append(name)

# Add constants to module exports. Simply adding constants_names would work fine, but
# would make it hard for IDEs to understand that colors are exported. Therefore the
# result of the following print statement is added instead.

# print(constants_names)

__all__ += [ # used to stop flake8 from complaining about undefined vars
def print_constant_definitions():
"""
A simple function used to generate the constant values below. To run it
paste this function and the Colors class into a file and run them.
"""
constants_names: list[str] = []
for name in Colors.__members__.keys():
name_upper = name.upper()

constants_names.append(name_upper)
print(f"{name_upper} = Colors.{name}")

if "GRAY" in name_upper:
name_upper = name_upper.replace("GRAY", "GREY")

constants_names.append(name_upper)
print(f"{name_upper} = Colors.{name}")

constants_names_repr = '[\n "' + '",\n "'.join(constants_names) + '",\n]'

print(f"\n__all__ += {constants_names_repr}")


WHITE = "#FFFFFF"
GRAY_A = "#DDDDDD"
GREY_A = "#DDDDDD"
GRAY_B = "#BBBBBB"
GREY_B = "#BBBBBB"
GRAY_C = "#888888"
GREY_C = "#888888"
GRAY_D = "#444444"
GREY_D = "#444444"
GRAY_E = "#222222"
GREY_E = "#222222"
BLACK = "#000000"
LIGHTER_GRAY = "#DDDDDD"
LIGHTER_GREY = "#DDDDDD"
LIGHT_GRAY = "#BBBBBB"
LIGHT_GREY = "#BBBBBB"
GRAY = "#888888"
GREY = "#888888"
DARK_GRAY = "#444444"
DARK_GREY = "#444444"
DARKER_GRAY = "#222222"
DARKER_GREY = "#222222"
BLUE_A = "#C7E9F1"
BLUE_B = "#9CDCEB"
BLUE_C = "#58C4DD"
BLUE_D = "#29ABCA"
BLUE_E = "#236B8E"
PURE_BLUE = "#0000FF"
BLUE = "#58C4DD"
DARK_BLUE = "#236B8E"
TEAL_A = "#ACEAD7"
TEAL_B = "#76DDC0"
TEAL_C = "#5CD0B3"
TEAL_D = "#55C1A7"
TEAL_E = "#49A88F"
TEAL = "#5CD0B3"
GREEN_A = "#C9E2AE"
GREEN_B = "#A6CF8C"
GREEN_C = "#83C167"
GREEN_D = "#77B05D"
GREEN_E = "#699C52"
PURE_GREEN = "#00FF00"
GREEN = "#83C167"
YELLOW_A = "#FFF1B6"
YELLOW_B = "#FFEA94"
YELLOW_C = "#FFFF00"
YELLOW_D = "#F4D345"
YELLOW_E = "#E8C11C"
YELLOW = "#FFFF00"
GOLD_A = "#F7C797"
GOLD_B = "#F9B775"
GOLD_C = "#F0AC5F"
GOLD_D = "#E1A158"
GOLD_E = "#C78D46"
GOLD = "#F0AC5F"
RED_A = "#F7A1A3"
RED_B = "#FF8080"
RED_C = "#FC6255"
RED_D = "#E65A4C"
RED_E = "#CF5044"
PURE_RED = "#FF0000"
RED = "#FC6255"
MAROON_A = "#ECABC1"
MAROON_B = "#EC92AB"
MAROON_C = "#C55F73"
MAROON_D = "#A24D61"
MAROON_E = "#94424F"
MAROON = "#C55F73"
PURPLE_A = "#CAA3E8"
PURPLE_B = "#B189C6"
PURPLE_C = "#9A72AC"
PURPLE_D = "#715582"
PURPLE_E = "#644172"
PURPLE = "#9A72AC"
PINK = "#D147BD"
LIGHT_PINK = "#DC75CD"
ORANGE = "#FF862F"
LIGHT_BROWN = "#CD853F"
DARK_BROWN = "#8B4513"
GRAY_BROWN = "#736357"
GREY_BROWN = "#736357"

__all__ += [
"WHITE",
"GRAY_A",
"GREY_A",
Expand Down Expand Up @@ -325,8 +412,8 @@ def named_lines_group(length, colors, names, text_colors, align_to_block):
"YELLOW_A",
"YELLOW_B",
"YELLOW_C",
"YELLOW_E",
"YELLOW_D",
"YELLOW_E",
"YELLOW",
"GOLD_A",
"GOLD_B",
Expand Down