def __init__( self, creature, content, target_mode="ask", bubble_mode="speech", look_at_arg = None, bubble_creation_class = Write, content_introduction_class= Write, **kwargs, ): bubble = creature.get_bubble(content, bubble_mode=bubble_mode) Group(bubble, bubble.content).shift_onto_screen() creature.generate_target() creature.target.change_mode(target_mode) if look_at_arg: creature.target.look_at(look_at_arg) change_mode = MoveToTarget(creature) bubble_creation = bubble_creation_class(bubble) content_introduction = content_introduction_class(bubble.content) AnimationGroup.__init__( self, change_mode, bubble_creation, content_introduction, **kwargs )
def test_animationgroup_with_wait(): sqr = Square() sqr_anim = FadeIn(sqr) wait = Wait() animation_group = AnimationGroup(wait, sqr_anim, lag_ratio=1) animation_group.begin() timings = animation_group.anims_with_timings assert timings == [(wait, 0.0, 1.0), (sqr_anim, 1.0, 2.0)]
def test_animationgroup_is_passing_remover_to_nested_animationgroups(): scene = Scene() sqr_animation = Create(Square()) circ_animation = Write(Circle(), remover=True) polygon_animation = Create(RegularPolygon(5)) animation_group = AnimationGroup( AnimationGroup(sqr_animation, polygon_animation), circ_animation, remover=True ) scene.play(animation_group) scene.wait(0.1) assert sqr_animation.remover assert circ_animation.remover assert polygon_animation.remover
def test_animationbuilder_in_group(): sqr = Square() circ = Circle() animation_group = AnimationGroup(sqr.animate.shift(DOWN).scale(2), FadeIn(circ)) assert all(isinstance(anim, Animation) for anim in animation_group.animations) succession = Succession(sqr.animate.shift(DOWN).scale(2), FadeIn(circ)) assert all(isinstance(anim, Animation) for anim in succession.animations)
def destroy_existing(self, destroyed_blocks): all_anims = [] overlay_objs = [] for id1, id2 in destroyed_blocks: # Generate a square containing both arrow blocks, and fade colour. if self.DESTRUCTION_RUNTIME > 0: anims = [] if self.DESTRUCTION_ARROW_ANIM is not None: anims.append(self.DESTRUCTION_ARROW_ANIM(self.arrow_blocks[id1])) anims.append(self.DESTRUCTION_ARROW_ANIM(self.arrow_blocks[id2])) else: # Instantly remove on animate. anims.append(FadeOut(self.arrow_blocks[id1], rate_func=lambda t: 1)) anims.append(FadeOut(self.arrow_blocks[id2], rate_func=lambda t: 1)) if self.DESTRUCTION_OVERLAY_COLOUR is not None: top = max(self.arrow_blocks[id1].get_top()[1], self.arrow_blocks[id2].get_top()[1]) right = max(self.arrow_blocks[id1].get_right()[0], self.arrow_blocks[id2].get_right()[0]) fade_square = Square(side_length=self.scale * 2, color=self.DESTRUCTION_OVERLAY_COLOUR) fade_square.set_opacity(self.DESTRUCTION_OVERLAY_STARTING_ALPHA) fade_square.move_to([right - self.scale, top - self.scale, 0]) overlay_objs.append(fade_square) anims.append(FadeOut(fade_square)) all_anims.append(AnimationGroup(*anims)) else: self.remove(self.arrow_blocks[id1], self.arrow_blocks[id2]) del self.arrow_blocks[id1] del self.arrow_blocks[id2] if self.DESTRUCTION_RUNTIME > 0 and len(all_anims) > 0: return overlay_objs, LaggedStart(*all_anims, lag_ratio=self.DESTRUCTION_LAG_RATIO) return None, None
def __init__( self, creature, look_at_arg = None, run_time= 0.5, **kwargs ): assert hasattr(creature, "bubble") if look_at_arg: creature.target.look_at(look_at_arg) AnimationGroup.__init__( self, Uncreate(creature.bubble), FadeOut(creature.bubble.content), run_time = run_time )
def creation_anim( self, text_anim: Animation = Write, arrow_anim: Animation = FadeInFrom, reactant_product_simultaneity=False, **kwargs, ) -> AnimationGroup: """Workaround and shortcut method to overcome the bugs in `Write`. Args: text_anim (Animation, optional): The animation on the reactants and products. Defaults to Write. arrow_anim (Animation, optional): The animation on the arrow. Defaults to FadeInFrom. reactant_product_simultaneity (bool, optional): Whether to animate the reactants and products together or not. Returns: AnimationGroup: The group of animations on the text and arrow. """ text = VGroup(self[0:2 * len(self.reactants) - 1], self[2 * len(self.reactants):]) arrow = self[2 * len(self.reactants) - 1] if "text_kwargs" not in kwargs.keys(): kwargs["text_kwargs"] = dict() if "arrow_kwargs" not in kwargs.keys(): kwargs["arrow_kwargs"] = dict() if "group_kwargs" not in kwargs.keys(): kwargs["group_kwargs"] = dict() print(kwargs["group_kwargs"]) anim_group = (AnimationGroup(text_anim(text[0]), text_anim(text[1]), arrow_anim(arrow), **kwargs) if reactant_product_simultaneity else AnimationGroup( text_anim(text), arrow_anim(arrow), **kwargs)) try: print(anim_group.run_time) except Exception: pass return anim_group
def test_animationgroup_is_passing_remover_to_animations( animation_remover, animation_group_remover): scene = Scene() sqr_animation = Create(Square(), remover=animation_remover) circ_animation = Write(Circle(), remover=animation_remover) animation_group = AnimationGroup(sqr_animation, circ_animation, remover=animation_group_remover) scene.play(animation_group) scene.wait(0.1) assert sqr_animation.remover assert circ_animation.remover
def zoom_out(self, board=Mobject()): def zoom_out(mob): mob.scale(1/3) mob.to_corner(UL) return mob self.play( LaggedStart( ApplyFunction(zoom_out, board), AnimationGroup( *[FadeInFrom(student) for student in self.students], FadeInFrom(self.teacher, RIGHT), ), lag_ratio = 0.1, run_time=2 ), )
def adjust_lines(self): tabledict = self.tabledict cell_height = self.cell_height cell_length = self.cell_length vertlines = self.submobjects[-(len(tabledict) - 1):] lowestmobject = min(self.submobjects[0:len(self.submobjects) - (len(tabledict))], key=lambda m: m.get_y()) rightestmobject = max(self.submobjects[:len(tabledict)], key=lambda m: m.get_x()) anims = [] for line in vertlines: curr_start, curr_end = line.get_start_and_end() if line.get_angle( ) * DEGREES == 0: #This only happens when a field has been added, but a vertical separator doesnt exist for it. new_end = np.array(curr_end + (rightestmobject.get_x() - curr_end[0] + cell_length / 4, 0, 0)) newsep = Line( #This is the vertical separator for the new field. start=(rightestmobject.get_center() - (cell_length / 4, -cell_height / 4, 0)), end=(rightestmobject.get_center() - (cell_length / 4, +rightestmobject.get_y() - lowestmobject.get_y() + cell_height / 4, 0)), color=self.line_color) anims.append(ShowCreation(newsep)) self.add(newsep) else: new_end = np.array((curr_end) + (0, lowestmobject.get_y() - curr_end[1] - cell_height / 4, 0)) new_line = Line(curr_start, new_end, color=self.line_color) anims.append(Transform( line, new_line)) #Set the new bottom to the required position return AnimationGroup(*anims)
def create_arrows(self, created): all_anims = [] overlay_objs = [] for (id1, (p11, p12), (d1x, d1y)), (id2, (p21, p22), (d2x, d2y)) in created: self.arrow_blocks[id1] = self._create_arrow( [((p11[0] + p12[0])/2 + 0.5) * self.scale, ((p11[1] + p12[1])/2 + 0.5) * self.scale, 0], [d1x, d1y], ) self.arrow_blocks[id2] = self._create_arrow( [((p21[0] + p22[0])/2 + 0.5) * self.scale, ((p21[1] + p22[1])/2 + 0.5) * self.scale, 0], [d2x, d2y], ) overlay_objs.extend([self.arrow_blocks[id1], self.arrow_blocks[id2]]) if self.ARROW_OVERLAY_COLOUR is not None: top = max(self.arrow_blocks[id1].get_top()[1], self.arrow_blocks[id2].get_top()[1]) right = max(self.arrow_blocks[id1].get_right()[0], self.arrow_blocks[id2].get_right()[0]) fade_square = Square(side_length=self.scale * 2, color=self.ARROW_OVERLAY_COLOUR) fade_square.set_opacity(self.ARROW_OVERLAY_STARTING_ALPHA) fade_square.move_to([right - self.scale, top - self.scale, 0]) overlay_objs.append(fade_square) if self.ARROW_CREATE_RUNTIME > 0: anims = [] if self.ARROW_OVERLAY_COLOUR is not None: anims.append(FadeOut(fade_square)) if self.ARROW_CREATE_ANIM is not None: if self.ARROW_CREATE_ANIM == FadeInFrom: anims.append(FadeInFrom(self.arrow_blocks[id1], direction=[-d1x * self.scale, -d1y * self.scale, 0])) anims.append(FadeInFrom(self.arrow_blocks[id2], direction=[-d2x * self.scale, -d2y * self.scale, 0])) else: anims.append(self.ARROW_CREATE_ANIM(self.arrow_blocks[id1])) anims.append(self.ARROW_CREATE_ANIM(self.arrow_blocks[id2])) else: # This adds them to the scene. anims.append(Transform(self.arrow_blocks[id1], self.arrow_blocks[id1])) anims.append(Transform(self.arrow_blocks[id2], self.arrow_blocks[id2])) all_anims.append(AnimationGroup(*anims)) if self.ARROW_CREATE_RUNTIME > 0 and len(all_anims) > 0: return overlay_objs, LaggedStart(*all_anims, lag_ratio=self.ARROW_LAG_RATIO) return overlay_objs, None
def creation_anim(self, chem_anim: Animation = Write, name_anim: Animation = FadeInFrom): return AnimationGroup(chem_anim(self.chem), name_anim(self.name))