MCPcopy
hub / github.com/ManimCommunity/manim / index_labels

Function index_labels

manim/utils/debug.py:25–82  ·  view source on GitHub ↗

r"""Returns a :class:`~.VGroup` of :class:`~.Integer` mobjects that shows the index of each submobject. Useful for working with parts of complicated mobjects. Parameters ---------- mobject The mobject that will have its submobjects labelled. label_height The

(
    mobject: Mobject,
    label_height: float = 0.15,
    background_stroke_width: float = 5,
    background_stroke_color: ManimColor = BLACK,
    **kwargs: Any,
)

Source from the content-addressed store, hash-verified

23
24
25def index_labels(
26 mobject: Mobject,
27 label_height: float = 0.15,
28 background_stroke_width: float = 5,
29 background_stroke_color: ManimColor = BLACK,
30 **kwargs: Any,
31) -> VGroup:
32 r"""Returns a :class:`~.VGroup` of :class:`~.Integer` mobjects
33 that shows the index of each submobject.
34
35 Useful for working with parts of complicated mobjects.
36
37 Parameters
38 ----------
39 mobject
40 The mobject that will have its submobjects labelled.
41 label_height
42 The height of the labels, by default 0.15.
43 background_stroke_width
44 The stroke width of the outline of the labels, by default 5.
45 background_stroke_color
46 The stroke color of the outline of labels.
47 kwargs
48 Additional parameters to be passed into the :class`~.Integer`
49 mobjects used to construct the labels.
50
51 Examples
52 --------
53 .. manim:: IndexLabelsExample
54 :save_last_frame:
55
56 class IndexLabelsExample(Scene):
57 def construct(self):
58 text = MathTex(
59 "\\frac{d}{dx}f(x)g(x)=",
60 "f(x)\\frac{d}{dx}g(x)",
61 "+",
62 "g(x)\\frac{d}{dx}f(x)",
63 )
64
65 #index the fist term in the MathTex mob
66 indices = index_labels(text[0])
67
68 text[0][1].set_color(PURPLE_B)
69 text[0][8:12].set_color(DARK_BLUE)
70
71 self.add(text, indices)
72 """
73 labels = VGroup()
74 for n, submob in enumerate(mobject):
75 label = Integer(n, **kwargs)
76 label.set_stroke(
77 background_stroke_color, background_stroke_width, background=True
78 )
79 label.height = label_height
80 label.move_to(submob)
81 labels.add(label)
82 return labels

Callers

nothing calls this directly

Calls 5

addMethod · 0.95
IntegerClass · 0.90
VGroupClass · 0.85
set_strokeMethod · 0.45
move_toMethod · 0.45

Tested by

no test coverage detected