Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Apply suggestions from code review

Mysaa88458475ff84
diff --git a/docs/source/examples/animations.rst b/docs/source/examples/animations.rst
index 9ba7123a4..8aeae5567 100644
--- a/docs/source/examples/animations.rst
+++ b/docs/source/examples/animations.rst
@@ -133,13 +133,11 @@ Updaters
class FadeInAndOut(Scene):
def construct(self):
- square = Square(color=BLUE).shift(2*UP)
-
- annotation = Text('Fade In', height=.8)
+ square = Square(color=BLUE).shift(2 * UP)
+ annotation = Text("Fade In", height=0.8)
self.add(annotation)
self.play(FadeIn(square))
-
- annotation.become(Text('Fade Out', height=.8))
+
+ annotation.become(Text("Fade Out", height=0.8))
self.add(annotation)
self.play(FadeOut(square))
-
diff --git a/docs/source/examples/camera_settings.rst b/docs/source/examples/camera_settings.rst
index f19a385b0..c41fb2f77 100644
--- a/docs/source/examples/camera_settings.rst
+++ b/docs/source/examples/camera_settings.rst
@@ -192,12 +192,12 @@ so one can use all functionality that were used before in the MovingCameraScene
frame_text.next_to(frame, DOWN)
- self.play(ShowCreation(frame), FadeInFrom(frame_text,direction=DOWN))
+ self.play(ShowCreation(frame), FadeInFrom(frame_text, direction=DOWN))
self.activate_zooming()
self.play(self.get_zoomed_display_pop_out_animation(), unfold_camera)
zoomed_camera_text.next_to(zoomed_display_frame, DOWN)
- self.play(FadeInFrom(zoomed_camera_text,direction=DOWN))
+ self.play(FadeInFrom(zoomed_camera_text, direction=DOWN))
# Scale in x y z
scale_factor = [0.5, 1.5, 0]
self.play(
diff --git a/docs/source/examples/shapes_images_positions.rst b/docs/source/examples/shapes_images_positions.rst
index 903aa0b21..bdad9b9f1 100644
--- a/docs/source/examples/shapes_images_positions.rst
+++ b/docs/source/examples/shapes_images_positions.rst
@@ -22,21 +22,18 @@ Shapes, Images and Positions
class PointMovingOnShapes(Scene):
def construct(self):
-
- circle = Circle(radius= 1, color=BLUE)
-
+ circle = Circle(radius=1, color=BLUE)
dot = Dot()
- dot2= dot.copy().shift(RIGHT)
+ dot2 = dot.copy().shift(RIGHT)
self.add(dot)
-
- line=Line(np.array([3,0,0]),np.array([5,0,0]))
+
+ line = Line([3, 0, 0], [5, 0, 0])
self.add(line)
-
-
+
self.play(GrowFromCenter(circle))
- self.play(Transform(dot,dot2))
- self.play(MoveAlongPath(dot,circle), run_time= 2, rate_func=linear)
- self.play(Rotating(dot, about_point=np.array((2, 0, 0.))), run_time=1.5)
+ self.play(Transform(dot, dot2))
+ self.play(MoveAlongPath(dot, circle), run_time=2, rate_func=linear)
+ self.play(Rotating(dot, about_point=[2, 0, 0]), run_time=1.5)
self.wait()
@@ -73,15 +70,14 @@ Shapes, Images and Positions
class ArcShapeIris(Scene):
def construct(self):
- colors = [DARK_BLUE , DARK_BROWN, BLUE_E, BLUE_D, BLUE_A, TEAL_B, GREEN_B, YELLOW_E]
- radius = [1+rad*0.1 for rad in range(len(colors))]
-
- circles_group=VGroup()
-
- # zip(radius,color) makes the iterator [(radius[i],color[i]) for i in range(radius)]
- circles_group.add( *[Circle(radius=rad,stroke_width=10, color = col)
- for rad,col in zip(radius,colors)])
-
+ colors = [DARK_BLUE, DARK_BROWN, BLUE_E, BLUE_D, BLUE_A, TEAL_B, GREEN_B, YELLOW_E]
+ radius = [1 + rad * 0.1 for rad in range(len(colors))]
+
+ circles_group = VGroup()
+
+ # zip(radius, color) makes the iterator [(radius[i], color[i]) for i in range(radius)]
+ circles_group.add(*[Circle(radius=rad, stroke_width=10, color=col)
+ for rad, col in zip(radius, colors)])
self.add(circles_group)
@@ -91,9 +87,9 @@ Shapes, Images and Positions
class DotInterpolation(Scene):
def construct(self):
dotL = Dot(color=DARK_GREY)
- dotL.shift(2*RIGHT)
+ dotL.shift(2 * RIGHT)
dotR = Dot(color=WHITE)
- dotR.shift(2*LEFT )
+ dotR.shift(2 * LEFT)
dotMiddle = VMobject().interpolate(dotL, dotR, alpha=0.3)
@@ -104,39 +100,39 @@ Shapes, Images and Positions
class MovingAround(Scene):
def construct(self):
- square = Square(color=BLUE,fill_opacity=1)
+ square = Square(color=BLUE, fill_opacity=1)
- self.play(square.shift,LEFT)
- self.play(square.set_fill,ORANGE)
- self.play(square.scale,0.3)
- self.play(square.rotate,0.4)
+ self.play(square.shift, LEFT)
+ self.play(square.set_fill, ORANGE)
+ self.play(square.scale, 0.3)
+ self.play(square.rotate, 0.4)
.. manim:: TextAlignement
:save_last_frame:
class TextAlignement(Scene):
- def construct(self):
- title=PangoText("K-means clustering and Logistic Regression", color=WHITE)
- title.scale_in_place(0.75)
- self.add(title.to_edge(UP))
-
- t1=PangoText("1. Measuring").set_color(WHITE)
- t1.next_to(ORIGIN,direction=RIGHT,aligned_edge=UP)
-
- t2=PangoText("2. Clustering").set_color(WHITE)
- t2.next_to(t1,direction=DOWN,aligned_edge=LEFT)
-
- t3=PangoText("3. Regression").set_color(WHITE)
- t3.next_to(t2,direction=DOWN,aligned_edge=LEFT)
-
- t4=PangoText("4. Prediction").set_color(WHITE)
- t4.next_to(t3,direction=DOWN,aligned_edge=LEFT)
-
- x=VGroup(t1,t2,t3,t4).scale_in_place(0.7)
- x.set_opacity(0.5)
- x.submobjects[1].set_opacity(1)
- self.add(x)
+ def construct(self):
+ title = PangoText("K-means clustering and Logistic Regression", color=WHITE)
+ title.scale_in_place(0.75)
+ self.add(title.to_edge(UP))
+
+ t1 = PangoText("1. Measuring").set_color(WHITE)
+ t1.next_to(ORIGIN, direction=RIGHT, aligned_edge=UP)
+
+ t2 = PangoText("2. Clustering").set_color(WHITE)
+ t2.next_to(t1, direction=DOWN, aligned_edge=LEFT)
+
+ t3 = PangoText("3. Regression").set_color(WHITE)
+ t3.next_to(t2, direction=DOWN, aligned_edge=LEFT)
+
+ t4 = PangoText("4. Prediction").set_color(WHITE)
+ t4.next_to(t3, direction=DOWN, aligned_edge=LEFT)
+
+ x = VGroup(t1, t2, t3, t4).scale_in_place(0.7)
+ x.set_opacity(0.5)
+ x.submobjects[1].set_opacity(1)
+ self.add(x)
.. manim:: BezierSpline
@@ -144,68 +140,78 @@ Shapes, Images and Positions
class BezierSpline(Scene):
def construct(self):
-
np.random.seed(42)
area = 4
-
- x1 = np.random.randint(-area,area)
- y1 = np.random.randint(-area,area)
- p1 = np.array([x1,y1,0])
+
+ x1 = np.random.randint(-area, area)
+ y1 = np.random.randint(-area, area)
+ p1 = np.array([x1, y1, 0])
destination_dot1 = Dot(point=p1).set_color(BLUE)
-
- x2 = np.random.randint(-area,area)
- y2 = np.random.randint(-area,area)
- p2 = np.array([x2,y2,0])
+
+ x2 = np.random.randint(-area, area)
+ y2 = np.random.randint(-area, area)
+ p2 = np.array([x2, y2, 0])
destination_dot2 = Dot(p2).set_color(RED)
-
-
- deltaP = p1-p2
- deltaPNormalized = deltaP/get_norm(deltaP)
-
+
+ deltaP = p1 - p2
+ deltaPNormalized = deltaP / get_norm(deltaP)
+
theta = np.radians(90)
- r = np.array(( (np.cos(theta), -np.sin(theta), 0 ),
- (np.sin(theta), np.cos(theta), 0 ),
- ( 0 , 0 , 0 ) ))
+ r = np.array(
+ (
+ (np.cos(theta), -np.sin(theta), 0),
+ (np.sin(theta), np.cos(theta), 0),
+ (0, 0, 0),
+ )
+ )
senk = r.dot(deltaPNormalized)
offset = 0.1
offset_along = 0.5
offset_connect = 0.25
-
- dest_line1_point1 = p1 + senk*offset - deltaPNormalized*offset_along
- dest_line1_point2 = p2 + senk*offset + deltaPNormalized*offset_along
- dest_line2_point1 = p1 - senk*offset - deltaPNormalized*offset_along
- dest_line2_point2 = p2 - senk*offset + deltaPNormalized*offset_along
- s1 = p1 - offset_connect*deltaPNormalized
- s2 = p2 + offset_connect*deltaPNormalized
+
+ dest_line1_point1 = p1 + senk * offset - deltaPNormalized * offset_along
+ dest_line1_point2 = p2 + senk * offset + deltaPNormalized * offset_along
+ dest_line2_point1 = p1 - senk * offset - deltaPNormalized * offset_along
+ dest_line2_point2 = p2 - senk * offset + deltaPNormalized * offset_along
+ s1 = p1 - offset_connect * deltaPNormalized
+ s2 = p2 + offset_connect * deltaPNormalized
dest_line1 = Line(dest_line1_point1, dest_line1_point2)
dest_line2 = Line(dest_line2_point1, dest_line2_point2)
-
+
Lp1s1 = Line(p1, s1)
-
- Lp1s1.add_cubic_bezier_curve(s1,
- s1-deltaPNormalized*0.1,
- dest_line2_point1+deltaPNormalized*0.1,
- dest_line2_point1-deltaPNormalized*0.01 )
- Lp1s1.add_cubic_bezier_curve(s1,
- s1-deltaPNormalized*0.1,
- dest_line1_point1+deltaPNormalized*0.1,
- dest_line1_point1 )
-
+
+ Lp1s1.add_cubic_bezier_curve(
+ s1,
+ s1 - deltaPNormalized * 0.1,
+ dest_line2_point1 + deltaPNormalized * 0.1,
+ dest_line2_point1 - deltaPNormalized * 0.01,
+ )
+ Lp1s1.add_cubic_bezier_curve(
+ s1,
+ s1 - deltaPNormalized * 0.1,
+ dest_line1_point1 + deltaPNormalized * 0.1,
+ dest_line1_point1,
+ )
+
Lp2s2 = Line(p2, s2)
-
- Lp2s2.add_cubic_bezier_curve(s2,
- s2+deltaPNormalized*0.1,
- dest_line2_point2-deltaPNormalized*0.1,
- dest_line2_point2 )
- Lp2s2.add_cubic_bezier_curve(s2,
- s2+deltaPNormalized*0.1,
- dest_line1_point2-deltaPNormalized*0.1,
- dest_line1_point2 )
-
-
- mobjects= VGroup(Lp1s1, Lp2s2,dest_line1,dest_line2,destination_dot1,destination_dot2)
-
+
+ Lp2s2.add_cubic_bezier_curve(
+ s2,
+ s2 + deltaPNormalized * 0.1,
+ dest_line2_point2 - deltaPNormalized * 0.1,
+ dest_line2_point2,
+ )
+ Lp2s2.add_cubic_bezier_curve(
+ s2,
+ s2 + deltaPNormalized * 0.1,
+ dest_line1_point2 - deltaPNormalized * 0.1,
+ dest_line1_point2,
+ )
+
+ mobjects = VGroup(
+ Lp1s1, Lp2s2, dest_line1, dest_line2, destination_dot1, destination_dot2
+ )
+
mobjects.scale(2)
self.add(mobjects)
-
diff --git a/manim/scene/scene.py b/manim/scene/scene.py
index 95e8b6fe8..5ccfcf79c 100644
--- a/manim/scene/scene.py
+++ b/manim/scene/scene.py
@@ -781,8 +781,10 @@ class Scene(Container):
Parameters
----------
- \*args : Animation or mobject with mobject method and params
- \*\*kwargs : named parameters affecting what was passed in \*args e.g run_time, lag_ratio etc.
+ args
+ Animation or mobject with mobject method and params
+ kwargs
+ named parameters affecting what was passed in ``args`` e.g. ``run_time``, ``lag_ratio`` etc.
"""
if len(args) == 0:
warnings.warn("Called Scene.play with no animations")