Skip to content

Commit 8845847

Browse files
MysaaJavabehackl
andauthored
Apply suggestions from code review
Mostly reformatting in a more black-approved way Co-authored-by: Benjamin Hackl <[email protected]>
1 parent 83a2acd commit 8845847

File tree

4 files changed

+113
-107
lines changed

4 files changed

+113
-107
lines changed

docs/source/examples/animations.rst

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,11 @@ Updaters
133133

134134
class FadeInAndOut(Scene):
135135
def construct(self):
136-
square = Square(color=BLUE).shift(2*UP)
137-
138-
annotation = Text('Fade In', height=.8)
136+
square = Square(color=BLUE).shift(2 * UP)
137+
annotation = Text("Fade In", height=0.8)
139138
self.add(annotation)
140139
self.play(FadeIn(square))
141-
142-
annotation.become(Text('Fade Out', height=.8))
140+
141+
annotation.become(Text("Fade Out", height=0.8))
143142
self.add(annotation)
144143
self.play(FadeOut(square))
145-

docs/source/examples/camera_settings.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,12 @@ so one can use all functionality that were used before in the MovingCameraScene
192192

193193
frame_text.next_to(frame, DOWN)
194194

195-
self.play(ShowCreation(frame), FadeInFrom(frame_text,direction=DOWN))
195+
self.play(ShowCreation(frame), FadeInFrom(frame_text, direction=DOWN))
196196
self.activate_zooming()
197197

198198
self.play(self.get_zoomed_display_pop_out_animation(), unfold_camera)
199199
zoomed_camera_text.next_to(zoomed_display_frame, DOWN)
200-
self.play(FadeInFrom(zoomed_camera_text,direction=DOWN))
200+
self.play(FadeInFrom(zoomed_camera_text, direction=DOWN))
201201
# Scale in x y z
202202
scale_factor = [0.5, 1.5, 0]
203203
self.play(

docs/source/examples/shapes_images_positions.rst

Lines changed: 103 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,18 @@ Shapes, Images and Positions
2222
class PointMovingOnShapes(Scene):
2323

2424
def construct(self):
25-
26-
circle = Circle(radius= 1, color=BLUE)
27-
25+
circle = Circle(radius=1, color=BLUE)
2826
dot = Dot()
29-
dot2= dot.copy().shift(RIGHT)
27+
dot2 = dot.copy().shift(RIGHT)
3028
self.add(dot)
31-
32-
line=Line(np.array([3,0,0]),np.array([5,0,0]))
29+
30+
line = Line([3, 0, 0], [5, 0, 0])
3331
self.add(line)
34-
35-
32+
3633
self.play(GrowFromCenter(circle))
37-
self.play(Transform(dot,dot2))
38-
self.play(MoveAlongPath(dot,circle), run_time= 2, rate_func=linear)
39-
self.play(Rotating(dot, about_point=np.array((2, 0, 0.))), run_time=1.5)
34+
self.play(Transform(dot, dot2))
35+
self.play(MoveAlongPath(dot, circle), run_time=2, rate_func=linear)
36+
self.play(Rotating(dot, about_point=[2, 0, 0]), run_time=1.5)
4037
self.wait()
4138

4239

@@ -73,15 +70,14 @@ Shapes, Images and Positions
7370

7471
class ArcShapeIris(Scene):
7572
def construct(self):
76-
colors = [DARK_BLUE , DARK_BROWN, BLUE_E, BLUE_D, BLUE_A, TEAL_B, GREEN_B, YELLOW_E]
77-
radius = [1+rad*0.1 for rad in range(len(colors))]
78-
79-
circles_group=VGroup()
80-
81-
# zip(radius,color) makes the iterator [(radius[i],color[i]) for i in range(radius)]
82-
circles_group.add( *[Circle(radius=rad,stroke_width=10, color = col)
83-
for rad,col in zip(radius,colors)])
84-
73+
colors = [DARK_BLUE, DARK_BROWN, BLUE_E, BLUE_D, BLUE_A, TEAL_B, GREEN_B, YELLOW_E]
74+
radius = [1 + rad * 0.1 for rad in range(len(colors))]
75+
76+
circles_group = VGroup()
77+
78+
# zip(radius, color) makes the iterator [(radius[i], color[i]) for i in range(radius)]
79+
circles_group.add(*[Circle(radius=rad, stroke_width=10, color=col)
80+
for rad, col in zip(radius, colors)])
8581
self.add(circles_group)
8682
8783

@@ -91,9 +87,9 @@ Shapes, Images and Positions
9187
class DotInterpolation(Scene):
9288
def construct(self):
9389
dotL = Dot(color=DARK_GREY)
94-
dotL.shift(2*RIGHT)
90+
dotL.shift(2 * RIGHT)
9591
dotR = Dot(color=WHITE)
96-
dotR.shift(2*LEFT )
92+
dotR.shift(2 * LEFT)
9793

9894
dotMiddle = VMobject().interpolate(dotL, dotR, alpha=0.3)
9995

@@ -104,108 +100,118 @@ Shapes, Images and Positions
104100

105101
class MovingAround(Scene):
106102
def construct(self):
107-
square = Square(color=BLUE,fill_opacity=1)
103+
square = Square(color=BLUE, fill_opacity=1)
108104

109-
self.play(square.shift,LEFT)
110-
self.play(square.set_fill,ORANGE)
111-
self.play(square.scale,0.3)
112-
self.play(square.rotate,0.4)
105+
self.play(square.shift, LEFT)
106+
self.play(square.set_fill, ORANGE)
107+
self.play(square.scale, 0.3)
108+
self.play(square.rotate, 0.4)
113109

114110

115111
.. manim:: TextAlignement
116112
:save_last_frame:
117113

118114
class TextAlignement(Scene):
119-
def construct(self):
120-
title=PangoText("K-means clustering and Logistic Regression", color=WHITE)
121-
title.scale_in_place(0.75)
122-
self.add(title.to_edge(UP))
123-
124-
t1=PangoText("1. Measuring").set_color(WHITE)
125-
t1.next_to(ORIGIN,direction=RIGHT,aligned_edge=UP)
126-
127-
t2=PangoText("2. Clustering").set_color(WHITE)
128-
t2.next_to(t1,direction=DOWN,aligned_edge=LEFT)
129-
130-
t3=PangoText("3. Regression").set_color(WHITE)
131-
t3.next_to(t2,direction=DOWN,aligned_edge=LEFT)
132-
133-
t4=PangoText("4. Prediction").set_color(WHITE)
134-
t4.next_to(t3,direction=DOWN,aligned_edge=LEFT)
135-
136-
x=VGroup(t1,t2,t3,t4).scale_in_place(0.7)
137-
x.set_opacity(0.5)
138-
x.submobjects[1].set_opacity(1)
139-
self.add(x)
115+
def construct(self):
116+
title = PangoText("K-means clustering and Logistic Regression", color=WHITE)
117+
title.scale_in_place(0.75)
118+
self.add(title.to_edge(UP))
119+
120+
t1 = PangoText("1. Measuring").set_color(WHITE)
121+
t1.next_to(ORIGIN, direction=RIGHT, aligned_edge=UP)
122+
123+
t2 = PangoText("2. Clustering").set_color(WHITE)
124+
t2.next_to(t1, direction=DOWN, aligned_edge=LEFT)
125+
126+
t3 = PangoText("3. Regression").set_color(WHITE)
127+
t3.next_to(t2, direction=DOWN, aligned_edge=LEFT)
128+
129+
t4 = PangoText("4. Prediction").set_color(WHITE)
130+
t4.next_to(t3, direction=DOWN, aligned_edge=LEFT)
131+
132+
x = VGroup(t1, t2, t3, t4).scale_in_place(0.7)
133+
x.set_opacity(0.5)
134+
x.submobjects[1].set_opacity(1)
135+
self.add(x)
140136

141137

142138
.. manim:: BezierSpline
143139
:save_last_frame:
144140

145141
class BezierSpline(Scene):
146142
def construct(self):
147-
148143
np.random.seed(42)
149144
area = 4
150-
151-
x1 = np.random.randint(-area,area)
152-
y1 = np.random.randint(-area,area)
153-
p1 = np.array([x1,y1,0])
145+
146+
x1 = np.random.randint(-area, area)
147+
y1 = np.random.randint(-area, area)
148+
p1 = np.array([x1, y1, 0])
154149
destination_dot1 = Dot(point=p1).set_color(BLUE)
155-
156-
x2 = np.random.randint(-area,area)
157-
y2 = np.random.randint(-area,area)
158-
p2 = np.array([x2,y2,0])
150+
151+
x2 = np.random.randint(-area, area)
152+
y2 = np.random.randint(-area, area)
153+
p2 = np.array([x2, y2, 0])
159154
destination_dot2 = Dot(p2).set_color(RED)
160-
161-
162-
deltaP = p1-p2
163-
deltaPNormalized = deltaP/get_norm(deltaP)
164-
155+
156+
deltaP = p1 - p2
157+
deltaPNormalized = deltaP / get_norm(deltaP)
158+
165159
theta = np.radians(90)
166-
r = np.array(( (np.cos(theta), -np.sin(theta), 0 ),
167-
(np.sin(theta), np.cos(theta), 0 ),
168-
( 0 , 0 , 0 ) ))
160+
r = np.array(
161+
(
162+
(np.cos(theta), -np.sin(theta), 0),
163+
(np.sin(theta), np.cos(theta), 0),
164+
(0, 0, 0),
165+
)
166+
)
169167
senk = r.dot(deltaPNormalized)
170168
offset = 0.1
171169
offset_along = 0.5
172170
offset_connect = 0.25
173-
174-
dest_line1_point1 = p1 + senk*offset - deltaPNormalized*offset_along
175-
dest_line1_point2 = p2 + senk*offset + deltaPNormalized*offset_along
176-
dest_line2_point1 = p1 - senk*offset - deltaPNormalized*offset_along
177-
dest_line2_point2 = p2 - senk*offset + deltaPNormalized*offset_along
178-
s1 = p1 - offset_connect*deltaPNormalized
179-
s2 = p2 + offset_connect*deltaPNormalized
171+
172+
dest_line1_point1 = p1 + senk * offset - deltaPNormalized * offset_along
173+
dest_line1_point2 = p2 + senk * offset + deltaPNormalized * offset_along
174+
dest_line2_point1 = p1 - senk * offset - deltaPNormalized * offset_along
175+
dest_line2_point2 = p2 - senk * offset + deltaPNormalized * offset_along
176+
s1 = p1 - offset_connect * deltaPNormalized
177+
s2 = p2 + offset_connect * deltaPNormalized
180178
dest_line1 = Line(dest_line1_point1, dest_line1_point2)
181179
dest_line2 = Line(dest_line2_point1, dest_line2_point2)
182-
180+
183181
Lp1s1 = Line(p1, s1)
184-
185-
Lp1s1.add_cubic_bezier_curve(s1,
186-
s1-deltaPNormalized*0.1,
187-
dest_line2_point1+deltaPNormalized*0.1,
188-
dest_line2_point1-deltaPNormalized*0.01 )
189-
Lp1s1.add_cubic_bezier_curve(s1,
190-
s1-deltaPNormalized*0.1,
191-
dest_line1_point1+deltaPNormalized*0.1,
192-
dest_line1_point1 )
193-
182+
183+
Lp1s1.add_cubic_bezier_curve(
184+
s1,
185+
s1 - deltaPNormalized * 0.1,
186+
dest_line2_point1 + deltaPNormalized * 0.1,
187+
dest_line2_point1 - deltaPNormalized * 0.01,
188+
)
189+
Lp1s1.add_cubic_bezier_curve(
190+
s1,
191+
s1 - deltaPNormalized * 0.1,
192+
dest_line1_point1 + deltaPNormalized * 0.1,
193+
dest_line1_point1,
194+
)
195+
194196
Lp2s2 = Line(p2, s2)
195-
196-
Lp2s2.add_cubic_bezier_curve(s2,
197-
s2+deltaPNormalized*0.1,
198-
dest_line2_point2-deltaPNormalized*0.1,
199-
dest_line2_point2 )
200-
Lp2s2.add_cubic_bezier_curve(s2,
201-
s2+deltaPNormalized*0.1,
202-
dest_line1_point2-deltaPNormalized*0.1,
203-
dest_line1_point2 )
204-
205-
206-
mobjects= VGroup(Lp1s1, Lp2s2,dest_line1,dest_line2,destination_dot1,destination_dot2)
207-
197+
198+
Lp2s2.add_cubic_bezier_curve(
199+
s2,
200+
s2 + deltaPNormalized * 0.1,
201+
dest_line2_point2 - deltaPNormalized * 0.1,
202+
dest_line2_point2,
203+
)
204+
Lp2s2.add_cubic_bezier_curve(
205+
s2,
206+
s2 + deltaPNormalized * 0.1,
207+
dest_line1_point2 - deltaPNormalized * 0.1,
208+
dest_line1_point2,
209+
)
210+
211+
mobjects = VGroup(
212+
Lp1s1, Lp2s2, dest_line1, dest_line2, destination_dot1, destination_dot2
213+
)
214+
208215
mobjects.scale(2)
209216
self.add(mobjects)
210217

211-

manim/scene/scene.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,8 +781,10 @@ def play_internal(self, *args, **kwargs):
781781
782782
Parameters
783783
----------
784-
\*args : Animation or mobject with mobject method and params
785-
\*\*kwargs : named parameters affecting what was passed in \*args e.g run_time, lag_ratio etc.
784+
args
785+
Animation or mobject with mobject method and params
786+
kwargs
787+
named parameters affecting what was passed in ``args`` e.g. ``run_time``, ``lag_ratio`` etc.
786788
"""
787789
if len(args) == 0:
788790
warnings.warn("Called Scene.play with no animations")

0 commit comments

Comments
 (0)