A community-maintained Python framework for creating mathematical animations.
Added kolibril python examples to the docs, re-formatted to be readable
MysaaJava0000ec8acb5b
diff --git a/docs/source/examples/3d.rst b/docs/source/examples/3d.rstindex 5ffddca16..0964a4604 100644--- a/docs/source/examples/3d.rst+++ b/docs/source/examples/3d.rst@@ -79,3 +79,52 @@self.set_camera_orientation(phi=80 * DEGREES, theta=-60 * DEGREES)self.wait()+.. manim:: ThreeDPlane++ class ThreeDPlane(ThreeDScene):++ def construct(self):++ resolution_fa=22+ self.set_camera_orientation(phi=75 * DEGREES, theta=-30 * DEGREES)++ def param_plane(u,v):+ x=u+ y=v+ z=0+ return np.array([x,y,z])+ plane = ParametricSurface( param_plane,+ resolution = (resolution_fa,resolution_fa),+ v_min = -2,+ v_max = +2,+ u_min = -2,+ u_max = +2 )+ plane.scale_about_point(2,ORIGIN)++ def param_gauss(u,v):+ x=u+ y=v+ d = np.sqrt(x * x + y * y)+ sigma, mu = 0.4, 0.0+ z= np.exp(-((d - mu) ** 2 / (2.0 * sigma ** 2)))+ return np.array([x,y,z])++ gauss_plane = ParametricSurface( param_gauss,+ resolution = (resolution_fa, resolution_fa),+ v_min = -2,+ v_max = +2,+ u_min = -2,+ u_max = +2 )++ gauss_plane.scale_about_point(2,ORIGIN)+ gauss_plane.set_style(fill_opacity=1)+ gauss_plane.set_style(stroke_color=GREEN)+ gauss_plane.set_fill_by_checkerboard(GREEN,BLUE,opacity=0.1)++ axes = ThreeDAxes()++ self.add(axes)+ self.play(Write(plane))+ self.play(Transform(plane,gauss_plane))+ self.wait()+diff --git a/docs/source/examples/animations.rst b/docs/source/examples/animations.rstindex 33eab8e9c..9e35b39e8 100644--- a/docs/source/examples/animations.rst+++ b/docs/source/examples/animations.rst@@ -105,4 +105,43 @@ Updatersline_moving = Line(ORIGIN, LEFT).set_color(ORANGE)line_moving.add_updater(my_rotation_updater)self.add(line_reference, line_moving)- self.play(val_tracker.set_value, tick_end, run_time=PI)\ No newline at end of file+ self.play(val_tracker.set_value, tick_end, run_time=PI)++.. manim:: PlaneFadeOut++ class PlaneFadeOut(Scene):++ def construct(self):++ sq2= Square()++ sq1= Square()+ sq1.next_to(sq2,LEFT)++ sq3= Square()+ sq3.next_to(sq2,RIGHT)++ circ = Circle()+ circ.next_to(sq2,DOWN)++ self.add(sq1,sq2,sq3,circ)+ self.wait()++ self.play(FadeOut(sq1),FadeOut(sq2),FadeOut(sq3))+ self.wait()++.. manim:: AnimationFadeInAndOut++ class AnimationFadeInAndOut(Scene):+ def construct(self):+ square = Square(color=BLUE).shift(2*UP)++ annotation = Text('Fade In', height=.8)+ self.add(annotation)+ self.play(FadeIn(square))++ annotation.become(Text('Fade Out', height=.8))+ self.add(annotation)+ self.play(FadeOut(square))++diff --git a/docs/source/examples/shapes_images_positions.rst b/docs/source/examples/shapes_images_positions.rstindex 297b3d62a..8db7a3092 100644--- a/docs/source/examples/shapes_images_positions.rst+++ b/docs/source/examples/shapes_images_positions.rst@@ -16,6 +16,7 @@ Shapes, Images and Positionsself.add(d, c, s, t)self.wait(1)+.. manim:: Example1ImageFromArray:save_last_frame:@@ -26,6 +27,7 @@ Shapes, Images and Positionsimage.set_height(7)self.add(image)+.. manim:: Example2ImageFromFile:save_last_frame:@@ -43,4 +45,190 @@ Shapes, Images and Positionsself.add(img_mobject)-Note: Here can come the UnitDot Example.\ No newline at end of file+.. manim:: ArcShapeExample+ :save_last_frame:++ class ArcShapeExample(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)])++ self.add(circles_group)+ self.wait(2)+++.. manim:: ImageFromGradient+ :save_last_frame:++ class ImageFromGradient(Scene):+ def construct(self):+ n = 256+ imageArray = np.uint8([[i*256/n for i in range(0,n)] for j in range(0,n)])+ image = ImageMobject(imageArray).scale(2)+ image.next_to(ORIGIN,LEFT, SMALL_BUFF)+ self.add(image)+ self.wait(1)+++.. manim:: ShapesExample++ class ShapesExample(Scene):++ def construct(self):++ circle = Circle(radius= 1, color=BLUE)++ dot = Dot()+ dot2= dot.copy().shift(RIGHT)+ self.add(dot)++ line=Line(np.array([3,0,0]),np.array([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.wait()+++.. manim:: InterpolationExample+ :save_last_frame:++ class InterpolationExample(Scene):+ def construct(self):+ dotL = Dot(color=DARK_GREY)+ dotL.shift(2*RIGHT)+ dotR = Dot(color=WHITE)+ dotR.shift(2*LEFT )++ dotMiddle = VMobject().interpolate(dotL, dotR, alpha=0.3)++ self.add(dotL, dotR, dotMiddle)+++.. manim:: MoveAroundExample++ class MoveAroundExample(Scene):+ def construct(self):+ 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)+++.. manim:: TextAlignementExample+ :save_last_frame:++ class TextAlignementExample(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)+++.. manim:: SplineExample++ class SplineExample(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])+ 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])+ destination_dot2 = Dot(p2).set_color(RED)+++ 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 ) ))+ 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 = 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 )++ 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 )+++ start=VGroup(Line(destination_dot1.get_center(), destination_dot2.get_center()),+ destination_dot1.copy(),+ destination_dot2.copy())+ start.scale(0.5)++ end= VGroup(Lp1s1, Lp2s2,dest_line1,dest_line2,destination_dot1,destination_dot2)+ end.scale(2)++ self.add(start)+ self.wait()+ self.play(ClockwiseTransform(start,end), run_time=3)+ self.wait()++Note: Here can come the UnitDot Example.++