@@ -46,6 +46,43 @@ class Code(VGroup):
46
46
`weird <https://github.com/3b1b/manim/issues/1067>`_. Consider using
47
47
:meth:`remove_invisible_chars` to resolve this issue.
48
48
49
+ Examples
50
+ --------
51
+
52
+ Normal usage::
53
+
54
+ listing = Code(
55
+ "helloworldcpp.cpp",
56
+ tab_width=4,
57
+ background_stroke_width=1,
58
+ background_stroke_color=WHITE,
59
+ insert_line_no=True,
60
+ style=Code.styles_list[15],
61
+ background="window",
62
+ language="cpp",
63
+ )
64
+
65
+ We can also render code passed as a string (but note that
66
+ the language has to be specified in this case):
67
+
68
+ .. manim:: CodeFromString
69
+ :save_last_frame:
70
+
71
+ class CodeFromString(Scene):
72
+ def construct(self):
73
+ code = '''from manim import Scene, Square
74
+
75
+ class FadeInSquare(Scene):
76
+ def construct(self):
77
+ s = Square()
78
+ self.play(FadeIn(s))
79
+ self.play(s.animate.scale(2))
80
+ self.wait()
81
+ '''
82
+ rendered_code = Code(code=code, tab_width=4, background="window",
83
+ language="Python", font="Monospace")
84
+ self.add(rendered_code)
85
+
49
86
Parameters
50
87
----------
51
88
file_name : :class:`str`
@@ -101,42 +138,6 @@ class Code(VGroup):
101
138
code : :class:`~.Paragraph`
102
139
The highlighted code.
103
140
104
- Examples
105
- --------
106
- Normal usage::
107
-
108
- listing = Code(
109
- "helloworldcpp.cpp",
110
- tab_width=4,
111
- background_stroke_width=1,
112
- background_stroke_color=WHITE,
113
- insert_line_no=True,
114
- style=Code.styles_list[15],
115
- background="window",
116
- language="cpp",
117
- )
118
-
119
- We can also render code passed as a string (but note that
120
- the language has to be specified in this case):
121
-
122
- .. manim:: CodeFromString
123
- :save_last_frame:
124
-
125
- class CodeFromString(Scene):
126
- def construct(self):
127
- code = '''from manim import Scene, Square
128
-
129
- class FadeInSquare(Scene):
130
- def construct(self):
131
- s = Square()
132
- self.play(FadeIn(s))
133
- self.play(s.animate.scale(2))
134
- self.wait()
135
- '''
136
- rendered_code = Code(code=code, tab_width=4, background="window",
137
- language="Python", font="Monospace")
138
- self.add(rendered_code)
139
-
140
141
"""
141
142
142
143
# tuples in the form (name, aliases, filetypes, mimetypes)
0 commit comments