Skip to content

Commit dd16347

Browse files
Make colour aliases IDE-friendly (ManimCommunity#2050)
* Make colour aliases IDE-friendly Fixes ManimCommunity#2049 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 4f6852c commit dd16347

File tree

1 file changed

+107
-20
lines changed

1 file changed

+107
-20
lines changed

manim/utils/color.py

Lines changed: 107 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -260,25 +260,112 @@ def named_lines_group(length, colors, names, text_colors, align_to_block):
260260
gray_brown = "#736357"
261261

262262

263-
# Create constants from Colors enum
264-
constants_names = []
265-
for name, value in Colors.__members__.items():
266-
name = name.upper()
267-
value = value.value
268-
constants_names.append(name)
269-
locals()[name] = value
270-
if "GRAY" in name:
271-
name = name.replace("GRAY", "GREY")
272-
locals()[name] = value
273-
constants_names.append(name)
274-
275-
# Add constants to module exports. Simply adding constants_names would work fine, but
276-
# would make it hard for IDEs to understand that colors are exported. Therefore the
277-
# result of the following print statement is added instead.
278-
279-
# print(constants_names)
280-
281-
__all__ += [ # used to stop flake8 from complaining about undefined vars
263+
def print_constant_definitions():
264+
"""
265+
A simple function used to generate the constant values below. To run it
266+
paste this function and the Colors class into a file and run them.
267+
"""
268+
constants_names: list[str] = []
269+
for name in Colors.__members__.keys():
270+
name_upper = name.upper()
271+
272+
constants_names.append(name_upper)
273+
print(f"{name_upper} = Colors.{name}")
274+
275+
if "GRAY" in name_upper:
276+
name_upper = name_upper.replace("GRAY", "GREY")
277+
278+
constants_names.append(name_upper)
279+
print(f"{name_upper} = Colors.{name}")
280+
281+
constants_names_repr = '[\n "' + '",\n "'.join(constants_names) + '",\n]'
282+
283+
print(f"\n__all__ += {constants_names_repr}")
284+
285+
286+
WHITE = "#FFFFFF"
287+
GRAY_A = "#DDDDDD"
288+
GREY_A = "#DDDDDD"
289+
GRAY_B = "#BBBBBB"
290+
GREY_B = "#BBBBBB"
291+
GRAY_C = "#888888"
292+
GREY_C = "#888888"
293+
GRAY_D = "#444444"
294+
GREY_D = "#444444"
295+
GRAY_E = "#222222"
296+
GREY_E = "#222222"
297+
BLACK = "#000000"
298+
LIGHTER_GRAY = "#DDDDDD"
299+
LIGHTER_GREY = "#DDDDDD"
300+
LIGHT_GRAY = "#BBBBBB"
301+
LIGHT_GREY = "#BBBBBB"
302+
GRAY = "#888888"
303+
GREY = "#888888"
304+
DARK_GRAY = "#444444"
305+
DARK_GREY = "#444444"
306+
DARKER_GRAY = "#222222"
307+
DARKER_GREY = "#222222"
308+
BLUE_A = "#C7E9F1"
309+
BLUE_B = "#9CDCEB"
310+
BLUE_C = "#58C4DD"
311+
BLUE_D = "#29ABCA"
312+
BLUE_E = "#236B8E"
313+
PURE_BLUE = "#0000FF"
314+
BLUE = "#58C4DD"
315+
DARK_BLUE = "#236B8E"
316+
TEAL_A = "#ACEAD7"
317+
TEAL_B = "#76DDC0"
318+
TEAL_C = "#5CD0B3"
319+
TEAL_D = "#55C1A7"
320+
TEAL_E = "#49A88F"
321+
TEAL = "#5CD0B3"
322+
GREEN_A = "#C9E2AE"
323+
GREEN_B = "#A6CF8C"
324+
GREEN_C = "#83C167"
325+
GREEN_D = "#77B05D"
326+
GREEN_E = "#699C52"
327+
PURE_GREEN = "#00FF00"
328+
GREEN = "#83C167"
329+
YELLOW_A = "#FFF1B6"
330+
YELLOW_B = "#FFEA94"
331+
YELLOW_C = "#FFFF00"
332+
YELLOW_D = "#F4D345"
333+
YELLOW_E = "#E8C11C"
334+
YELLOW = "#FFFF00"
335+
GOLD_A = "#F7C797"
336+
GOLD_B = "#F9B775"
337+
GOLD_C = "#F0AC5F"
338+
GOLD_D = "#E1A158"
339+
GOLD_E = "#C78D46"
340+
GOLD = "#F0AC5F"
341+
RED_A = "#F7A1A3"
342+
RED_B = "#FF8080"
343+
RED_C = "#FC6255"
344+
RED_D = "#E65A4C"
345+
RED_E = "#CF5044"
346+
PURE_RED = "#FF0000"
347+
RED = "#FC6255"
348+
MAROON_A = "#ECABC1"
349+
MAROON_B = "#EC92AB"
350+
MAROON_C = "#C55F73"
351+
MAROON_D = "#A24D61"
352+
MAROON_E = "#94424F"
353+
MAROON = "#C55F73"
354+
PURPLE_A = "#CAA3E8"
355+
PURPLE_B = "#B189C6"
356+
PURPLE_C = "#9A72AC"
357+
PURPLE_D = "#715582"
358+
PURPLE_E = "#644172"
359+
PURPLE = "#9A72AC"
360+
PINK = "#D147BD"
361+
LIGHT_PINK = "#DC75CD"
362+
ORANGE = "#FF862F"
363+
LIGHT_BROWN = "#CD853F"
364+
DARK_BROWN = "#8B4513"
365+
GRAY_BROWN = "#736357"
366+
GREY_BROWN = "#736357"
367+
368+
__all__ += [
282369
"WHITE",
283370
"GRAY_A",
284371
"GREY_A",
@@ -325,8 +412,8 @@ def named_lines_group(length, colors, names, text_colors, align_to_block):
325412
"YELLOW_A",
326413
"YELLOW_B",
327414
"YELLOW_C",
328-
"YELLOW_E",
329415
"YELLOW_D",
416+
"YELLOW_E",
330417
"YELLOW",
331418
"GOLD_A",
332419
"GOLD_B",

0 commit comments

Comments
 (0)