def interpolate_mobject(self, alpha): ApplyMethod.interpolate_mobject(self, alpha) if alpha == 0: return radians = alpha * self.total_tire_radians for tire in self.mobject.get_tires(): tire.rotate_in_place(radians)
def move_camera(self, phi=None, theta=None, distance=None, gamma=None, frame_center=None, added_anims=[], **kwargs): anims = [] value_tracker_pairs = [ (phi, self.camera.phi_tracker), (theta, self.camera.theta_tracker), (distance, self.camera.distance_tracker), (gamma, self.camera.gamma_tracker), ] for value, tracker in value_tracker_pairs: if value is not None: anims.append(ApplyMethod(tracker.set_value, value, **kwargs)) if frame_center is not None: anims.append( ApplyMethod(self.camera.frame_center.move_to, frame_center)) is_camera_rotating = self.ambient_camera_rotation in self.continual_animations if is_camera_rotating: self.remove(self.ambient_camera_rotation) self.play(*anims + added_anims) if is_camera_rotating: self.add(self.ambient_camera_rotation)
def move_camera(self, phi=None, theta=None, distance=None, gamma=None, frame_center=None, added_anims=[], **kwargs): anims = [] value_tracker_pairs = [ (phi, self.camera.phi_tracker), (theta, self.camera.theta_tracker), (distance, self.camera.distance_tracker), (gamma, self.camera.gamma_tracker), ] for value, tracker in value_tracker_pairs: if value is not None: anims.append( ApplyMethod(tracker.set_value, value, **kwargs) ) if frame_center is not None: anims.append(ApplyMethod( self.camera.frame_center.move_to, frame_center )) self.play(*anims + added_anims)
def construct(self): quote = TextMobject("Imagination is more important than knowledge") quote.set_color(RED) quote.to_edge(UP) quote2 = TextMobject( "A person who never made a mistake never tried anything new") quote2.set_color(YELLOW) author = TextMobject("- Albert Einstein") author.scale(0.75) corner = quote.get_corner(DOWN + RIGHT) print("corner", corner) author.next_to(corner, ORIGIN) self.add(quote, author) self.wait(2) self.play( Transform(quote, quote2), ApplyMethod(author.move_to, quote2.get_corner(DOWN + RIGHT) + DOWN + 2 * LEFT)) self.play(ApplyMethod(author.scale, 1.5)) author.match_color(quote2) self.play(FadeOut(quote), FadeOut(author)) self.wait()
def __init__(self, car, target_point, **kwargs): assert isinstance(car, Car) ApplyMethod.__init__(self, car.move_to, target_point, **kwargs) displacement = self.target_mobject.get_right( ) - self.starting_mobject.get_right() distance = get_norm(displacement) if not self.moving_forward: distance *= -1 tire_radius = car.get_tires()[0].get_width() / 2 self.total_tire_radians = -distance / tire_radius
def move_camera(self, phi=None, theta=None, distance=None, gamma=None, frame_center=None, added_anims=[], **kwargs): """ This method animates the movement of the camera to the given spherical coordinates. Parameters ---------- phi : (int,float) The polar angle i.e the angle between Z_AXIS and Camera through ORIGIN in radians. theta : (int,float) The azimuthal angle i.e the angle that spins the camera around the Z_AXIS. distance : (int, float) The radial distance between ORIGIN and Camera. gamma : (int, float) The rotation of the camera about the vector from the ORIGIN to the Camera. frame_center : Union[list,tuple,array] The new center of the camera frame. added_anims : list Any other animations to be played at the same time? """ anims = [] value_tracker_pairs = [ (phi, self.camera.phi_tracker), (theta, self.camera.theta_tracker), (distance, self.camera.distance_tracker), (gamma, self.camera.gamma_tracker), ] for value, tracker in value_tracker_pairs: if value is not None: anims.append( ApplyMethod(tracker.set_value, value, **kwargs) ) if frame_center is not None: anims.append(ApplyMethod( self.camera.frame_center.move_to, frame_center )) self.play(*anims + added_anims)
def construct(self): number_line = NumberLine(x_min=-2, x_max=2) triangle = RegularPolygon(3, start_angle=-PI / 2) \ .scale(0.2) \ .next_to(number_line.get_left(), UP, buff=SMALL_BUFF) numbers = VGroup( *[TextMobject("%s" % i) \ .next_to(number_line.get_tick(i - 2), DOWN) for i in range(1, 5)] ) self.add(number_line) self.play(ShowCreation(triangle)) self.wait(0.3) self.play( ApplyMethod(triangle.shift, RIGHT * 4, rate_func=linear, run_time=4), *[ AnimationGroup(Animation(Mobject(), run_time=i + 1), Write(numbers[i]), lag_ratio=1) for i in range(4) ], ) self.wait()
def _main_title(self): paper_name_a = TextMobject( "Simulating human interactions in supermarkets to") paper_name_b = TextMobject( "measure the risk of COVID-19 contagion at scale") author_list_a = TextMobject( "Serge Plata\\quad Sumanas Sarma\\quad Melvin Lancelot") author_list_b = TextMobject( "Kristine Bagrova\\quad David Romano-Critchley") arxiv = TextMobject("arXiv:2006.15213") paper_name_a.shift(UP) paper_name_b.next_to(paper_name_a, DOWN) author_list_a.scale(0.8) author_list_b.scale(0.8) author_list_a.next_to(paper_name_b, DOWN + DOWN) author_list_b.next_to(author_list_a, DOWN) arxiv.scale(0.6) arxiv.next_to(author_list_b, DOWN + DOWN) self.play(FadeIn(paper_name_a), FadeIn(paper_name_b)) self.wait() self.play(FadeIn(author_list_a), FadeIn(author_list_b)) self.play(FadeIn(arxiv)) self.wait(4) self.play(FadeOut(paper_name_a), FadeOut(paper_name_b), FadeOut(author_list_a), FadeOut(author_list_b), ApplyMethod(arxiv.move_to, BOTTOM + (UP * 0.5)))
def compile_play_args_to_animation_list(self, *args, **kwargs): """ Add animations so that all pi creatures look at the first mobject being animated with each .play call """ animations = Scene.compile_play_args_to_animation_list( self, *args, **kwargs) anim_mobjects = Group(*[a.mobject for a in animations]) all_movers = anim_mobjects.get_family() if not self.any_pi_creatures_on_screen(): return animations pi_creatures = self.get_on_screen_pi_creatures() non_pi_creature_anims = [ anim for anim in animations if len( set(anim.mobject.get_family()).intersection(pi_creatures)) == 0 ] if len(non_pi_creature_anims) == 0: return animations # Get pi creatures to look at whatever # is being animated first_anim = non_pi_creature_anims[0] main_mobject = first_anim.mobject for pi_creature in pi_creatures: if pi_creature not in all_movers: animations.append( ApplyMethod( pi_creature.look_at, main_mobject, )) return animations
def get_zoom_in_animation(self, run_time=2, **kwargs): """ Returns the animation of camera zooming in. Parameters ---------- run_time (Union[int,float=2]) The run_time of the animation of the camera zooming in. **kwargs Any valid keyword arguments of ApplyMethod() Returns ------- ApplyMethod The animation of the camera zooming in. """ frame = self.zoomed_camera.frame full_frame_height = self.camera.get_frame_height() full_frame_width = self.camera.get_frame_width() frame.save_state() frame.stretch_to_fit_width(full_frame_width) frame.stretch_to_fit_height(full_frame_height) frame.center() frame.set_stroke(width=0) return ApplyMethod(frame.restore, run_time=run_time, **kwargs)
def tex(self, latex): eq = TextMobject(latex) anims = [] anims.append(Write(eq)) for mobject in self.mobjects: anims.append(ApplyMethod(mobject.shift, 2 * UP)) self.play(*anims)
def get_zoomed_display_pop_out_animation(self, **kwargs): apply_methods = [] for zoomed_camera, zoomed_display in zip(self.zoomed_cameras,self.zoomed_displays): zoomed_display.save_state(use_deepcopy=True) zoomed_display.replace(zoomed_camera.frame, stretch=True) apply_method = ApplyMethod(zoomed_display.restore) apply_methods.append(apply_method) return apply_methods
def play_zooming_animation(self, center, scaling_factor, **kwargs): self.play( ApplyMethod( VGroup(self.axes, self.circles, self.labels).scale, scaling_factor, {"about_point" : self.axes.coords_to_point(center, 0)} ), lag_ratio = 0, **kwargs, )
def __init__(self, mobjs1, mobjs2, run_time=1, transpose=1, lag_ratio=0, **kwargs): kwargs = merge_config_kwargs(self, kwargs) animations = AGroup() if transpose: #[a, b, c], [x, y, z] mobjects = list(map(list, zip(mobjs1, mobjs2))) #[a, x], [b, y], [c, z] [animations.add(ApplyMethod(self.func(each[0]), each[1], **kwargs)) for each in mobjects] super().__init__(*animations, lag_ratio=lag_ratio, run_time=run_time, **kwargs)
def get_zoom_in_animation(self, run_time=2, **kwargs): frame = self.zoomed_camera.frame full_frame_height = self.camera.get_frame_height() full_frame_width = self.camera.get_frame_width() frame.save_state() frame.stretch_to_fit_width(full_frame_width) frame.stretch_to_fit_height(full_frame_height) frame.center() frame.set_stroke(width=0) return ApplyMethod(frame.restore, run_time=run_time, **kwargs)
def play_farey_sum_animation(self, p1, q1, p2, q2): c1, c2, c3, l1, l2, l3 = self.get_farey_sum_key_mobjects(p1, q1, p2, q2) l3.set_color(PINK) self.wait() self.play( ShowCreation(c1), ApplyMethod(l1.set_color, YELLOW), ShowCreation(c2), ApplyMethod(l2.set_color, YELLOW), ) self.play( ReplacementTransform(l1.numer.deepcopy(), l3.numer), ReplacementTransform(l1.line.deepcopy(), l3.line), ReplacementTransform(l1.denom.deepcopy(), l3.denom), ReplacementTransform(l2.numer.deepcopy(), l3.numer), ReplacementTransform(l2.line.deepcopy(), l3.line), ReplacementTransform(l2.denom.deepcopy(), l3.denom), ReplacementTransform(c1.deepcopy(), c3), ReplacementTransform(c2.deepcopy(), c3), ) self.wait() self.play(FadeOut(VGroup(c1, c2, c3, l1, l2, l3)))
def animate_product(self, left, right, result): l_matrix = left.get_mob_matrix() r_matrix = right.get_mob_matrix() result_matrix = result.get_mob_matrix() circle = Circle( radius=l_matrix[0][0].get_height(), color=GREEN ) circles = VGroup(*[ entry.get_point_mobject() for entry in (l_matrix[0][0], r_matrix[0][0]) ]) (m, k), n = l_matrix.shape, r_matrix.shape[1] for mob in result_matrix.flatten(): mob.set_color(BLACK) lagging_anims = [] for a in range(m): for b in range(n): for c in range(k): l_matrix[a][c].set_color(YELLOW) r_matrix[c][b].set_color(YELLOW) for c in range(k): start_parts = VGroup( l_matrix[a][c].copy(), r_matrix[c][b].copy() ) result_entry = result_matrix[a][b].split()[c] new_circles = VGroup(*[ circle.copy().shift(part.get_center()) for part in start_parts.split() ]) self.play(Transform(circles, new_circles)) self.play( Transform( start_parts, result_entry.copy().set_color(YELLOW), path_arc=-np.pi / 2, submobject_mode="all_at_once", ), *lagging_anims ) result_entry.set_color(YELLOW) self.remove(start_parts) lagging_anims = [ ApplyMethod(result_entry.set_color, WHITE) ] for c in range(k): l_matrix[a][c].set_color(WHITE) r_matrix[c][b].set_color(WHITE) self.play(FadeOut(circles), *lagging_anims) self.wait()
def __init__(self, mobject, color=YELLOW, width=10, opacity=None, scale_factor=1, run_time=1, highlight=1, func=None, rate_func=linear, pause_ratio=4./5, f_color=None, f_width=None, f_opacity=None, lag_ratio=1, copy=False, fadeout=None,offset=4, ratio=[0.95, 0.05], name="mobject", **kwargs): #for each in ["zrate_func", "scale_factor", "color", "stroke_opacity", "width"]: # try: # if locals()[each]: # kwargs[each] = locals()[each] # except: # pass #kwargs = merge_config_kwargs(self, kwargs,self.CONFIG) if copy: mobject=mobject.copy() if isinstance(color, (int, float)): if color < 0: run_time = -color color = None animations = AGroup() if f_color is not None or f_width is not None or f_opacity is not None: animations.add( ApplyMethod(mobject.set_stroke, f_color,f_width, f_opacity, rate_func=funz(step,0.05),run_time=run_time*ratio[1])) run_time = run_time*ratio[0] elif (copy and fadeout is None) or fadeout: animations.add(FadeOut(mobject,run_time=0.001)) if highlight: kws=dict() if color is not None: kws['color']=color if width is not None: kws['width']=width if opacity is not None: kws['opacity']=opacity animations.add_to_back(Highlight( mobject,scale_factor=scale_factor, run_time=run_time,**kws)) else: animations.add_to_back( ApplyMethod(mobject.set_stroke, color, width, opacity, rate_func=funz(linear_pulse,0.05,0.9), run_time=run_time)) #Transform(mobject,mobject.copy().set_stroke(color, width, opacity), rate_func=funz(linear_pulse,0.05,0.9), run_time=run_time)) #ShowCreation(mobject.copy().set_stroke(color, width, opacity), rate_func=funz(linear_pulse,0.05,0.9), run_time=run_time)) super().__init__(*animations, **kwargs)
def get_zoomed_display_pop_out_animation(self, **kwargs): """ This is the animation of the popping out of the mini-display that shows the content of the zoomed camera. Returns ------- ApplyMethod The Animation of the Zoomed Display popping out. """ display = self.zoomed_display display.save_state(use_deepcopy=True) display.replace(self.zoomed_camera.frame, stretch=True) return ApplyMethod(display.restore)
def construct(self): my_first_text = TextMobject("Writing with manim is fun") second_line = TextMobject("and easy to do!") second_line.next_to(my_first_text, DOWN) third_line = TextMobject("for me and you!") third_line.next_to(my_first_text, DOWN) self.add(my_first_text, second_line) self.wait(2) self.play(Transform(second_line, third_line)) self.wait(2) second_line.shift(3 * DOWN) self.play(ApplyMethod(my_first_text.shift, 3 * UP)) self.wait()
def construct(self): my_first_text = TextMobject("Writing with manim is fun") second_line = TextMobject("and easy to do!") second_line.next_to(my_first_text, DOWN) third_line = TextMobject("for me and you!") third_line.next_to(my_first_text, DOWN) self.play(FadeIn(my_first_text), FadeIn(second_line)) self.wait(2) self.play(Transform(second_line, third_line)) self.wait(2) self.play(ApplyMethod(my_first_text.shift, 3 * UP)) self.play(Rotating(second_line), radians=PI, run_time=2) self.wait()
def show_counter(self): counters = VGroup( *[rhombus.get_counter_tex() for rhombus in self.rhombi]) three_types_text = self.bg_texts[2] try_tiling_text, remark = self.bg_texts[3] self.play(FadeOut(self.reflines), ApplyMethod(self.rhombi.set_fill, None, 1), Write(three_types_text), run_time=2) self.wait() self.play(Write(try_tiling_text), run_time=2) self.play(Write(remark), run_time=1) self.wait() self.play(FadeIn(counters), run_time=1) self.wait(4) self.counters = counters
def compile_play_args_to_animation_list(self, *args, **kwargs): """ Add animations so that all pi creatures look at the first mobject being animated with each .play call """ animations = Scene.compile_play_args_to_animation_list( self, *args, **kwargs) if not self.any_pi_creatures_on_screen(): return animations non_pi_creature_anims = [ anim for anim in animations if anim.mobject not in self.get_pi_creatures() ] if len(non_pi_creature_anims) == 0: return animations # Look at ending state first_anim = non_pi_creature_anims[0] first_anim_copy = copy.deepcopy(first_anim) first_anim_copy.begin() first_anim_copy.update(1) point_of_interest = first_anim_copy.mobject.get_center() for pi_creature in self.get_pi_creatures(): if pi_creature not in self.get_mobjects(): continue if pi_creature in first_anim.mobject.get_family(): continue anims_with_pi_creature = [ anim for anim in animations if pi_creature in anim.mobject.get_family() ] for anim in anims_with_pi_creature: if isinstance(anim, Transform): index = anim.mobject.get_family().index(pi_creature) target_family = anim.target_mobject.get_family() target = target_family[index] if isinstance(target, PiCreature): target.look_at(point_of_interest) if not anims_with_pi_creature: animations.append( ApplyMethod(pi_creature.look_at, point_of_interest)) return animations
def construct(self): number_line = NumberLine(x_min=-2, x_max=2) triangle = RegularPolygon(3, start_angle=-PI / 2) \ .scale(0.2) \ .next_to(number_line.get_left(), UP, buff=SMALL_BUFF) text_1 = TextMobject("1") \ .next_to(number_line.get_tick(-1), DOWN) text_2 = TextMobject("2") \ .next_to(number_line.get_tick(0), DOWN) text_3 = TextMobject("3") \ .next_to(number_line.get_tick(1), DOWN) text_4 = TextMobject("4") \ .next_to(number_line.get_tick(2), DOWN) self.add(number_line) self.play(ShowCreation(triangle)) self.wait(0.3) self.play( ApplyMethod(triangle.shift, RIGHT * 4, rate_func=linear, run_time=4), AnimationGroup(Animation(Mobject(), run_time=1), Write(text_1), lag_ratio=1), AnimationGroup(Animation(Mobject(), run_time=2), Write(text_2), lag_ratio=1), AnimationGroup(Animation(Mobject(), run_time=3), Write(text_3), lag_ratio=1), AnimationGroup(Animation(Mobject(), run_time=4), Write(text_4), lag_ratio=1)) self.wait()
def construct(self): if 1 == 1: try: self.add_sound( "sidewayoutput\\basicmanim\\transform001a_01_01_01_01_01.wav", time_offset=18) self.add_sound( "sidewayoutput\\basicmanim\\transform001a_01_01_01_02_01.wav", time_offset=93) self.add_sound( "sidewayoutput\\basicmanim\\transform001a_01_01_01_03_01.wav", time_offset=135) except: pass self.play( StartScreens01( [], [], [[r"\textbf{\textit{Basic-Manim from }\{Sideway\}}"], [r"\textbf{\textit{Transform}}\\{{Part\ \textspA{I}a}"], [ r"\tiny{\textrm{basic-manim.210200551v0\_transform001a}}" ], [], [ r"\scriptsize{\textbf{Warning:\ The\ content\ may\ contain\ errors,\ mistakes\ and\ inaccuracies.\ Information\ must\ be\ verified\ and\ evaluated\ before\ use.}}" ]], )) if 1 == 1: self.play( GrowFromCenter( TextMobject( r"\textit{\textbf{\underline{Transform}}}").shift( [0, 3.6, 0]))) squarea = Square() squareb = Square(side_length=4).shift([4, 0, 0]) circlea = Circle() circleb = Circle(radius=2).shift([-4, 0, 0]) linea = Line([-4, 3, 0], [4, 3, 0]) lineb = Line([-3, -3, 0], [3, -3, 0]) texta = TextMobject("AB").shift([0, -2.5, 0]) textb = TextMobject("HI").shift([0, 2.5, 0]) self.play( ShowCreation(Group(squarea, circlea, squareb, circleb, linea, lineb), lag_ratio=1, run_time=12)) self.play(Write(VGroup(texta, textb), lag_ratio=1, run_time=10)) self.play(Transform(circlea, squarea, run_time=5)) self.play(Transform(circlea, squareb, path_arc=3, run_time=5)) self.play(Transform(squarea, circleb, path_arc=3, run_time=5)) self.play(Transform(linea, lineb, path_arc=3, run_time=5)) self.play(Transform(linea, circleb, path_arc=3, run_time=5)) self.play(Transform(squareb, lineb, path_arc=3, run_time=5)) self.play(Transform(texta, textb, path_arc=3, run_time=5)) self.play(Transform(texta, circleb, path_arc=3, run_time=5)) self.play(Transform(squareb, textb, path_arc=3, run_time=5)) self.fadeout() if 1 == 1: self.play( GrowFromCenter( TextMobject( r"\textit{\textbf{\underline{Paths\ of\ Transform}}}"). shift([0, 3.6, 0]))) rows, cols = (7, 5) x0, y0 = axes_point([0, 2, cols - 1, -4], [2.3, -1, rows - 1, 3]) txtx = ["loc 1", "loc 2", "m1", "m2"] txty = [ "ClockwiseTransform", "Transform", "CounterclockwiseTransform" ] a1 = Group() a2 = Group() a3 = Group() a4 = Group() for j in range(1, rows): a1.add(Circle().scale(0.2).move_to([x0[1], y0[j], 0])) a2.add(Square().scale(0.2).move_to([x0[2], y0[j], 0])) a3.add( Dot([x0[3], y0[j], 0]).add_updater(lambda mob, obj=a1[ j - 1], x=x0[3], y=y0[j]: mob.become(obj.copy( ).move_to([x, y, 0]))).suspend_updating()) a4.add( Dot([x0[4], y0[j], 0]).add_updater(lambda mob, obj=a2[ j - 1], x=x0[4], y=y0[j]: mob.become(obj.copy( ).move_to([x, y, 0]))).suspend_updating()) self.play(FadeIn( Group( *[ TextMobject(txtx[i]).move_to(each) for i, each in enumerate(coord_grid(x0[1:], y0[0:1])) ], *[ TextMobject(txty[i]).move_to(each) for i, each in enumerate(coord_grid(x0[0:1], y0[1::2])) ], *[Dot(each) for each in coord_grid(x0[1:3], y0[1:])], TextMobject(r"$\rightarrow$").move_to( ([(x0[1] + x0[2]) / 2, y0[0], 0])), a1[::2], a2[::2], a3, a4, *[ Square(stroke_width=2, color="#FFFF00", fill_opacity=0.3).add_updater( lambda mob, obj=obj: mob.surround( obj, stretch=True, buff=0.2)) for obj in a1 ], *[ Square(stroke_width=2, color="#DC75CD").add_updater( lambda mob, obj=obj: mob.surround( obj, stretch=True, buff=0.3)) for obj in a2 ])), run_time=5) self.wait(2) self.play(AnimationGroup( ClockwiseTransform(a2[0], a1[0]), ClockwiseTransform(a1[1], a2[1]), Transform(a1[2], a2[2]), Transform(a2[3], a1[3]), CounterclockwiseTransform(a1[4], a2[4]), CounterclockwiseTransform(a2[5], a1[5]), ), run_time=25) self.wait(3) a1.shift([0.3, 0, 0]).set_color("#11FF00") self.wait(3) self.play(ApplyMethod(a1.shift, ([0.3, 0, 0])), run_time=3) self.fadeout() if 1 == 1: self.play( GrowFromCenter( TextMobject( r"\textit{\textbf{\underline{Methods\ of\ Transform}}}" ).shift([0, 3.6, 0]))) rows, cols = (9, 5) x0, y0 = axes_point([0, 2, cols - 1, -4], [2.3, -0.8, rows - 1, 3]) txtx = ["loc 1", "loc 2", "m1", "m2"] txty = [ "Transform", "ReplacementTransform", "TransformFromCopy", "MoveToTarget" ] a1 = Group() a2 = Group() a3 = Group() a4 = Group() for j in range(1, rows): a1.add(Circle().scale(0.2).move_to([x0[1], y0[j], 0])) a2.add(Square().scale(0.2).move_to([x0[2], y0[j], 0])) a3.add(Dot().move_to([x0[3], y0[j], 0]).add_updater( lambda mob, obj=a1[j - 1], x=x0[3], y=y0[j]: mob.become( obj.copy().move_to([x, y, 0]))).suspend_updating()) a4.add(Dot().move_to([x0[4], y0[j], 0]).add_updater( lambda mob, obj=a2[j - 1], x=x0[4], y=y0[j]: mob.become( obj.copy().move_to([x, y, 0]))).suspend_updating()) a1[6].target = a2[6] a1[7].target = a2[7] self.play(FadeIn( Group( *[ TextMobject(txtx[i]).move_to(each) for i, each in enumerate(coord_grid(x0[1:], y0[0:1])) ], *[ TextMobject(txty[i]).move_to(each) for i, each in enumerate(coord_grid(x0[0:1], y0[1::2])) ], *[Dot(each) for each in coord_grid(x0[1:3], y0[1:])], TextMobject(r"$\rightarrow$").move_to( ([(x0[1] + x0[2]) / 2, y0[0], 0])), a1[::2], a2[::2], a3, a4, Group(*[ Square( stroke_width=2, color="#FFFF00", fill_opacity=0.3). add_updater(lambda mob, obj=obj: mob.surround( obj, stretch=True, buff=0.2)) for obj in a1 ]), Group(*[ Square(stroke_width=2, color="#DC75CD").add_updater( lambda mob, obj=obj: mob.surround( obj, stretch=True, buff=0.3)) for obj in a2 ]))), run_time=5) self.wait(2) self.play(AnimationGroup(Transform(a1[0], a2[0]), Transform(a1[1], a2[1]), ReplacementTransform(a1[2], a2[2]), ReplacementTransform(a1[3], a2[3]), TransformFromCopy(a1[4], a2[4]), TransformFromCopy(a1[5], a2[5]), MoveToTarget(a1[6]), MoveToTarget(a1[7])), run_time=40) self.wait(3) a1.shift([0.3, 0, 0]).set_color("#11FF00") self.wait(10) self.play(ApplyMethod(a1.shift, ([0.3, 0, 0])), run_time=5) self.fadeout() if 1 == 1: self.play(EndScreen01()) self.wait(5)
def __init__(self, pi_creature, **kwargs): ApplyMethod.__init__(self, pi_creature.blink, **kwargs)
def construct(self): self._main_title() text_one = TextMobject("Given a list of items sold") text_two: TextMobject = TextMobject( "Randomly choose items matching this distribution") text_two.next_to(text_one, DOWN) number_line = NumberLine( numbers_with_elongated_ticks=[0, 1], include_numbers=True, x_min=0, x_max=1, unit_size=10, tick_frequency=0.1, # decimal_number_config={"num_decimal_places": 1}, numbers_to_show=[0, 1]) number_line.next_to(text_two, UP) self.play(ShowCreation(text_one)) self.wait() self.play(ShowCreation(text_two)) self.wait(4) apples_text = TextMobject("Apples:") apples_text.set_color(self._apple_colour) apples_text.to_edge(UP) apples_text.align_to(text_two, LEFT) apple_count_text = TextMobject(f"{self._apple_count}") apple_count_text.set_color(self._apple_colour) apple_count_text.next_to(apples_text, RIGHT) banana_text = TextMobject("Bananas:") banana_text.set_color(self._banana_colour) banana_text.next_to(apples_text, DOWN) banana_text.align_to(apples_text, LEFT) banana_count_text = TextMobject(f"{self._banana_count}") banana_count_text.set_color(self._banana_colour) banana_count_text.next_to(banana_text, RIGHT) self.play(Transform(text_one, apples_text)) self.play(ShowCreation(apple_count_text)) self.play(ShowCreation(banana_text), ShowCreation(banana_count_text)) banana_bar = Rectangle( height=0.4, width=number_line.point_to_number(self._banana_fraction * 10) * (number_line.number_to_point(1)[0]), color=self._banana_colour, fill_color=self._banana_colour, fill_opacity=0.75) banana_bar.next_to(banana_count_text, RIGHT + RIGHT) apple_bar = Rectangle( height=0.4, width=number_line.point_to_number(self._apple_fraction * 10) * (number_line.number_to_point(1)[0]), color=self._apple_colour, fill_color=self._apple_colour, fill_opacity=0.75) apple_bar.next_to(banana_bar, UP) apple_bar.align_to(banana_bar, LEFT) self.play(FadeIn(apple_bar), FadeIn(banana_bar)) self.wait(1.5) apple_fraction_text = TextMobject("$\\frac{" + str(self._apple_count) + "}{" + str(self._apple_count + self._banana_count) + "} = " + str(self._apple_fraction) + "$") apple_fraction_text.next_to(apple_bar, RIGHT) banana_fraction_text = TextMobject("$\\frac{" + str(self._banana_count) + "}{" + str(self._apple_count + self._banana_count) + "} = " + str(self._banana_fraction) + "$") banana_fraction_text.next_to(banana_bar, RIGHT) self.play(ShowCreation(apple_fraction_text)) self.play(ShowCreation(banana_fraction_text)) self.wait(2) number_line_map_text = TextMobject( "Map these counts to values between 0 and 1") number_line_map_text.next_to(text_two, UP) self.play(ShowCreation(number_line_map_text)) self.wait(3) self.play(Transform(number_line_map_text, number_line)) apple_num_ln_bar = Rectangle( height=0.4, # width=1 - self._apple_fraction * (number_line.number_to_point(1)[0]), width=number_line.point_to_number(self._apple_fraction * 10) * (number_line.number_to_point(1)[0]), color=self._apple_colour, fill_color=self._apple_colour, fill_opacity=0.25) apple_num_ln_bar.move_to(apple_bar, LEFT) self.add(apple_num_ln_bar) self.wait(2) self.play( ApplyMethod(apple_num_ln_bar.move_to, number_line.number_to_point(0), LEFT)) banana_num_ln_bar = Rectangle( height=0.4, width=number_line.point_to_number(self._banana_fraction * 10) * (number_line.number_to_point(1)[0]), color=self._banana_colour, fill_color=self._banana_colour, fill_opacity=0.25) banana_num_ln_bar.move_to(banana_bar, LEFT) self.add(banana_num_ln_bar) self.wait(2) self.play( ApplyMethod(banana_num_ln_bar.move_to, number_line.number_to_point(1), RIGHT)) text_scale: float = 0.75 get_rnd_full = TextMobject( "Get a random number $n$ between 0 and 1 (uniform distribution)") get_apple_text = TextMobject( f"Apple\\quad if $n <= {self._apple_fraction}$", tex_to_color_map={"Apple": self._apple_colour}) get_banana_text = TextMobject( f"Banana\\quad if $n > {self._apple_fraction}$", tex_to_color_map={"Banana": self._banana_colour}) get_rnd_full.scale(text_scale) get_rnd_full.next_to(text_two, DOWN) get_banana_text.next_to(get_apple_text, DOWN) step_group = VGroup(get_apple_text, get_banana_text) brace = Brace(step_group, LEFT) step_text_d = brace.get_text("$n \\sim U(0, 1)$") step_text_d.scale(text_scale) step_text_d.next_to(get_rnd_full, DOWN + DOWN) step_text_d.shift(LEFT) brace.next_to(step_text_d, RIGHT) step_group.scale(text_scale) step_group.next_to(step_text_d, RIGHT + RIGHT + RIGHT) self.wait(2) self.play(ShowCreation(get_rnd_full)) self.wait(2) self.play(ShowCreation(step_text_d)) self.wait(2) self.play(GrowFromCenter(brace)) self.wait() self.play(ShowCreation(get_apple_text)) self.wait(2) self.play(ShowCreation(get_banana_text)) # random_nos_to_draw = 10 # main_arrow = Arrow(ORIGIN, DOWN * 1.3) # helper_arrow = Arrow(ORIGIN, LEFT * 1.3) # # for i in range(random_nos_to_draw): # num: float = np.random.random_sample(1) # point = number_line.number_to_point(num) # arrow_colour = self._apple_colour if num <= self._apple_fraction else self._banana_colour # arrow_recipient = get_apple_text if num <= self._apple_fraction else get_banana_text # # main_arrow.set_color(arrow_colour) # # if i == 0: # main_arrow.next_to(point, UP) # helper_arrow.next_to(arrow_recipient, RIGHT) # self.play(GrowArrow(main_arrow), GrowArrow(helper_arrow)) # else: # self.play(ApplyMethod(helper_arrow.next_to, arrow_recipient, RIGHT), # ApplyMethod(main_arrow.next_to, point, UP)) # self.wait() # # self.play(FadeOut(main_arrow), FadeOut(helper_arrow)) self.wait()
def construct(self): # Add title title = self.title = TextMobject("Clicky Stuffs") title.scale(1.5) title.to_edge(UP, buff=MED_SMALL_BUFF) pi_creatures = VGroup(Randolph(), Mortimer()) for pi, vect in zip(pi_creatures, [LEFT, RIGHT]): pi.set_height(title.get_height()) pi.change_mode("thinking") pi.look(DOWN) pi.next_to(title, vect, buff=MED_LARGE_BUFF) self.add(title, pi_creatures) # Set the top of the screen logo_box = Square(side_length=2.5) logo_box.to_corner(DOWN + LEFT, buff=MED_LARGE_BUFF) black_rect = Rectangle( fill_color=BLACK, fill_opacity=1, stroke_width=3, stroke_color=BLACK, width=FRAME_WIDTH, height=0.6 * FRAME_HEIGHT, ) black_rect.to_edge(UP, buff=0) line = DashedLine(FRAME_X_RADIUS * LEFT, FRAME_X_RADIUS * RIGHT) line.move_to(ORIGIN) # Add thanks thanks = TextMobject(self.thanks_words) thanks.scale(0.9) thanks.next_to(black_rect.get_bottom(), UP, SMALL_BUFF) thanks.set_color(YELLOW) underline = Line(LEFT, RIGHT) underline.match_width(thanks) underline.scale(1.1) underline.next_to(thanks, DOWN, SMALL_BUFF) thanks.add(underline) # Build name list file_name = os.path.join(get_directories()["data"], "patrons.txt") with open(file_name, "r") as fp: names = [ self.modify_patron_name(name.strip()) for name in fp.readlines() ] if self.randomize_order: random.shuffle(names) else: names.sort() name_labels = VGroup(*map(TextMobject, names)) name_labels.scale(self.patron_scale_val) for label in name_labels: if label.get_width() > self.max_patron_width: label.set_width(self.max_patron_width) columns = VGroup(*[ VGroup(*name_labels[i::self.n_patron_columns]) for i in range(self.n_patron_columns) ]) column_x_spacing = 0.5 + max([c.get_width() for c in columns]) for i, column in enumerate(columns): for n, name in enumerate(column): name.shift(n * self.name_y_spacing * DOWN) name.align_to(ORIGIN, LEFT) column.move_to(i * column_x_spacing * RIGHT, UL) columns.center() max_width = FRAME_WIDTH - 1 if columns.get_width() > max_width: columns.set_width(max_width) underline.match_width(columns) columns.next_to(underline, DOWN, buff=3) # Set movement columns.generate_target() distance = columns.get_height() + 2 wait_time = self.scroll_time frame = self.camera.frame frame_shift = ApplyMethod( frame.shift, distance * DOWN, run_time=wait_time, rate_func=linear, ) blink_anims = [] blank_mob = Mobject() for x in range(wait_time): if random.random() < 0.25: blink_anims.append(Blink(random.choice(pi_creatures))) else: blink_anims.append(Animation(blank_mob)) blinks = Succession(*blink_anims) static_group = VGroup(black_rect, line, thanks, pi_creatures, title) static_group.fix_in_frame() self.add(columns, static_group) self.play(frame_shift, blinks)
def construct(self): if 1 == 1: try: self.add_sound( "sidewayoutput\\basicmanim\\transform001b_01_01_02_01_01.wav", time_offset=18) self.add_sound( "sidewayoutput\\basicmanim\\transform001b_01_01_02_02_01.wav", time_offset=48) self.add_sound( "sidewayoutput\\basicmanim\\transform001b_01_01_02_02_02.wav", time_offset=93) self.add_sound( "sidewayoutput\\basicmanim\\transform001b_01_01_02_03_01.wav", time_offset=148) except: pass self.play( StartScreens01( [], [], [[r"\textbf{\textit{Basic-Manim from }\{Sideway\}}"], [r"\textbf{\textit{Transform}}\\{Part\ \textspA{I}b}"], [ r"\tiny{\textrm{basic-manim.210201951v0\_transform001b}}" ], [], [ r"\scriptsize{\textbf{Warning:\ The\ content\ may\ contain\ errors,\ mistakes\ and\ inaccuracies.\ Information\ must\ be\ verified\ and\ evaluated\ before\ use.}}" ]], )) if 1 == 1: self.play( GrowFromCenter( TextMobject( r"\textit{\textbf{\underline{Apply\ Transform}}}"). shift([0, 3.6, 0]))) rows, cols = (7, 3) x = 5. x0, y0 = axes_point([-2.5, x, cols - 1, -5], [2., -1.1, rows - 1, 3]) txtx = ["\\underline{state 1}", "\\underline{state 2}"] txty = ["Method", "ApplyMethod", "ApplyFunction"] a1 = [ "\\normalsize{sq[0]}", "\\normalsize{sq[1]}", "\\normalsize{sq[2]}" ] a2 = [ r"\normalsize{sq[0]\\.shift([" + str(x) + r",\,0,\,0])}", r"\normalsize{ApplyMethod(\\sq[1].shift,\,[" + str(x) + r",\,0,\,0])}", r"\normalsize{ApplyFunction(\\lambda\,mob:\,mob.shift([" + str(x) + r",\,0,\,0]),\,sq[2])}" ] sq = [GeomSquare(0.75) for i in range(3)] self.fadein( *[ TextMobject(txtx[i]).move_to(each) for i, each in enumerate(coord_grid(x0[1:], y0[0:1])) ], *[ TextMobject(txty[i]).move_to(each) for i, each in enumerate(coord_grid(x0[0:1], y0[1::2])) ], *[GeomPoint(each) for each in coord_grid(x0[1:3], y0[2::2])], *[ MobjectOrChars(np.ravel(list(zip(a1, a2)))[i]).move_to(each) for i, each in enumerate(coord_grid(x0[1:3], y0[1::2])) ], *[ sq[i].move_to(each) for i, each in enumerate(coord_grid(x0[1:2], y0[2::2])) ], run_time=5) self.play(AnimationGroup( ShowCreation(sq[0].shift([x, 0, 0]), run_time=0), ApplyMethod(sq[1].shift, [x, 0, 0]), ApplyFunction(lambda mob: mob.shift([x, 0, 0]), sq[2])), run_time=15) self.fadeout() if 1 == 1: self.play( GrowFromCenter( TextMobject( r"\textit{\textbf{\underline{Apply Method}}}").shift( [0, 3.6, 0]).add_as_foreground(self))) rows, cols = (8, 2) x0, y0 = axes_point([-1.5, 6, cols], [3, -0.9, rows]) txty = [ MobjectOrChars(each) for each in [ r"FadeToColor(sq[0],\,RED)", r"ScaleInPlace(sq[1],\,0.5))", "ShrinkToCenter(sq[2])", "Restore(sq[3])" ] ] a1 = [ MobjectOrChars("\\normalsize{sq[" + str(i) + "]}") for i in range(4) ] sq = [GeomSquare(0.75) for i in range(4)] self.fadein( *[ to_get_zlist(a1, sq)[i].move_to(each) for i, each in enumerate(coord_grid(x0[1:2], y0)) ], *[GeomPoint(each) for each in coord_grid(x0[1:2], y0[1::2])], ) self.wait() sq[3].save_state() self.play(AnimationGroup( IndicateThenFadeOut(TextMobject( r"Transform(sq[3], Circle().scale(0.375).\\move\_to(sq[3]).shift([1, 0, 0])))" ).move_to([x0[0], y0[7], 0]), scale_factor=1, ratio_array=[1, 0]), Transform( sq[3], Circle().scale(0.375).move_to(sq[3]).shift([1, 0, 0]))), run_time=5) self.wait() self.fadein( *[ txty[i].move_to(each) for i, each in enumerate(coord_grid(x0[0:1], y0[1::2])) ], ) self.play(AnimationGroup( FadeToColor(sq[0], RED), ScaleInPlace(sq[1], 0.5), ShrinkToCenter(sq[2]), Restore(sq[3]), ), run_time=35) self.fadeout(exclude_mobjs="foreground") if 1 == 1: rows, cols = (6, 2) x0, y0 = axes_point([-1.5, 6, cols], [3, -0.9, rows]) txty = [ MobjectOrChars(each) for each in [ r"ApplyPointwiseFunction(\\lambda\,pointarray:\,pointarray\,+\,[1,\,0,\,0],\,sq[0])", r"ApplyMatrix([[1.23,\,0.9],\,[0,\,1]],\,sq[1])", r"ApplyComplexFunction(lambda pointarray:\\pointarray\,+\,np.complex(1,\,0),\,sq[2])", ] ] a1 = [ MobjectOrChars("\\normalsize{sq[" + str(i) + "]}") for i in range(4) ] sq = [GeomSquare(0.75) for i in range(4)] self.fadein( *[ to_get_zlist(a1, sq)[i].move_to(each) for i, each in enumerate(coord_grid(x0[1:2], y0)) ], *[GeomPoint(each) for each in coord_grid(x0[1:2], y0[1::2])], ) self.wait() self.fadein( *[ txty[i].move_to(each) for i, each in enumerate(coord_grid(x0[0:1], y0[1::2])) ], ) self.play(AnimationGroup( ApplyPointwiseFunction( lambda pointarray: pointarray + [1, 0, 0], sq[0]), ApplyMatrix([[1.23, 0.9], [0, 1]], sq[1]), ApplyComplexFunction( lambda pointarray: pointarray + np.complex(1, 0), sq[2]), ), run_time=45) self.fadeout() if 1 == 1: self.play( GrowFromCenter( TextMobject( r"\textit{\textbf{\underline{Swap Method}}}").shift( [0, 3.6, 0]))) rows, cols = (2, 2) count = m, n = [2, 6] x0, y0 = axes_point([-3.5, 6, cols], [2.4, -3.7, rows]) geometrys = [GeomLine(), GeomRegularPolygon(n, radius=2)] txty = [ MobjectOrChars(each) for each in [ r"Swap(*sqs)\\ \tiny{(same as CyclicReplace)}", r"CyclicReplace(*sqs)", ] ] titles = [ [ MobjectOrChars("\\normalsize{sq[" + str(i) + "]}") for i in range(m) ], [ MobjectOrChars("\\normalsize{sq[" + str(i) + "]}") for i in range(n) ], ] sqs = [ [GeomSquare(1.) for i in range(m)], [GeomSquare(1.) for i in range(n)], ] [[ sq.add(title).add(GeomPoint()) for sq, title in zip(sqs[i], titles[i]) ] for i in range(len(count))] self.fadein(*[ geometrys[i].move_to(each) for i, each in enumerate(coord_grid(x0[1:], y0[0:])) ]) self.fadein(*[ Group(*[ sqs[j][i].move_to(each) for i, each in enumerate( geometrys[j].get_counting_points()) ]) for j in range(2) ]) self.fadein( *[ txty[i].move_to(each) for i, each in enumerate(coord_grid(x0[0:1], y0[0:])) ], ) self.play(AnimationGroup( Swap(*sqs[0]), CyclicReplace(*sqs[1]), ), run_time=35) self.fadeout() if 1 == 1: self.play(EndScreen01()) self.wait(5)
def get_zoomed_display_pop_out_animation(self, **kwargs): display = self.zoomed_display display.save_state(use_deepcopy=True) display.replace(self.zoomed_camera.frame, stretch=True) return ApplyMethod(display.restore)