def __init__(self, *args, func=AnimateStroke, run_time=None, fix_time=None, lag_ratio=0,**kwargs): animations=AGroup() runtime={} fixtime={} if isinstance(args[-1], (int,float)): if args[-1]>=0: runtime.update({'run_time':args[-1]}) else: fixtime.update({'run_time':-args[-1]}) args=args[:-1] if run_time is not None: runtime.update({'runtime':runtime}) if fix_time is not None: fixtime.update({'fix_time':fix_time}) for arg in args: kws={} if isinstance(arg[-1], dict): kws=arg[-1] arg=arg[:-1] kws.update(fixtime) kws.update(kwargs) mobj=VMobject() for each in arg: if isinstance(arg[0],(Mobject,Group,VMobject,VGroup)): mobj.add(arg[0]) arg=arg[1:] animations.add(func(mobj,*arg,**kws)) super().__init__(*animations,lag_ratio=lag_ratio,**runtime)
def __init__(self, mobject, run_time=1, ratio_array=[0.01, 0.5, 0.5], fadeout_func=rush_into, **kwargs): animations = AGroup( FadeIn(mobject, run_time=ratio_array[0]*run_time), Indicate(mobject, run_time=ratio_array[1]*run_time, **kwargs), FadeOut(mobject, run_time=ratio_array[2]*run_time, rate_func=fadeout_func)) [animations.remove(animations[i]) for i in range(len(ratio_array)) if ratio_array[i] == 0] super().__init__(*animations, **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 __init__(self, *mobjects, width=None, run_time=1, lag_ratio=1, rate_func=shorten, **kwargs): while isinstance(mobjects[-1],(int,float)): if mobjects[-1]>=0: width=mobjects[-1] mobjects=mobjects[:-1] else: run_time=-mobjects[-1] mobjects=mobjects[:-1] animations = AGroup() for mobject in mobjects: animations.add(self.CONFIG["funx"](mobject, width=width,**kwargs)) super().__init__(*animations, run_time=run_time,lag_ratio=lag_ratio, rate_func=rate_func, **kwargs)
def __init__(self, *animations, time=None, group=False, time_wait=None, **kwargs): merge_config_kwargs(self, kwargs) while isinstance(animations[-1], (int, float, bool)): if isinstance(animations[-1], bool): if int(animations[-1]) == 1: group = True animations = animations[:-1] elif isinstance(animations[-1], (int, float)): if animations[-1] > 0: time = animations[-1] elif animations[-1] < 0: time_wait = -animations[-1] animations = animations[:-1] if group: animations = [AnimationGroup(*animations, **kwargs)] anims = AGroup(*animations) if time is not None: self.time=time if self.delay: anims.add_to_back(Freeze(self.time)) else: anims.add(Freeze(self.time)) if time_wait is not None: anims.add(Freeze(time_wait)) super().__init__(*anims, **kwargs)
def __init__(self, *animations, run_time=0.1, **kwargs): anims = AGroup( #FadeIn(animation.mobject, run_time=0.01), *animations, # IndicateThenFadeOut( # animation.mobject, run_time=0.1, scale_factor=1, color=None, ratio_array=[0.05, 0.95], rate_func=fadeout_func) # ,ratio_array=[1.2, 1.1, 0.05] DFadeOut(AnimationGroup(*animations).mobject, run_time=run_time, **kwargs) ) super().__init__(*anims)
def __init__(self, animation, run_time=0.1, ratio_array=[1, 1, 1], fadeout_func=rush_into, **kwargs): animations = AGroup( FadeIn(animation.mobject, rate_func=linear, run_time=run_time), #ApplyMethod(VGroup(*animation.mobject[:]).set_stroke,{"opacity":1}, run_time=0), animation, # IndicateThenFadeOut( # animation.mobject, run_time=1, scale_factor=1, color=None, ratio_array=[0.95, 0.05], rate_func=fadeout_func) # ,ratio_array=[1.2, 1.1, 0.05] ) super().__init__(*animations, **kwargs)
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 __init__(self, mobjs1, mobjs2, paths=None, pre=None, post=None, group=True, run_time=1, transpose=1, **kwargs): animations = AGroup() if group: lag_ratio = 0 else: lag_ratio = 1 if paths is None: paths = [None]*min(len(mobjs1), len(mobjs2)) if transpose: #[a, b, c], [x, y, z] mobjects = list(map(list, zip(mobjs1, mobjs2, paths))) #[a, x], [b, y], [c, z] [animations.add(self.func(each[0], each[1], each[2], **kwargs)) for each in mobjects] if pre is not None: animations.add_to_back(*pre) if post is not None: animations.add(*post) super().__init__(*animations, lag_ratio=lag_ratio, run_time=run_time, **kwargs)
def __init__(self, *mobjects, run_time=0.05, lag_ratio=1, **kwargs): while isinstance(mobjects[-1], (int, float)): run_time = run_time mobjects = mobjects[:-1] animations = AGroup() vmobjs = VGroup() mobjs = Group() for each in mobjects: if isinstance(each, (VMobject)): vmobjs.add(each) else: mobjs.add(each) if len(mobjs) > 0: animations.add(Show(mobjs, run_time=run_time, **kwargs)) if len(vmobjs) > 0: animations.add(Write(vmobjs, run_time=run_time, **kwargs)) super().__init__( AnimationGroup(*animations, run_time=run_time, lag_ratio=lag_ratio, **kwargs))
def __init__(self, screen01=[], screen02=[], screen03=[], lag_ratio=1, **kwargs): mobjs_1, mobjs_1_scale, mobjs_1_interval, mobjs_1_rate_func, \ title_1, title_1_color, title_1_scale, title_1_position, title_1_shadow, \ title_1_indicate_scale_factor, title_1_extra = screen01 + \ ["", 2, 0.5, linear, "", "#0808B8", 2, [DOWN], [2, slice(0, 3, 2)], 1.2, ""][len(screen01):] mobjs_2, mobjs_2_scale, mobjs_2_interval, mobjs_2_rate_func, \ title_2, title_2_color, title_2_scale, title_2_position, title_2_shadow, \ title_2_indicate_scale_factor, title_2_extra = screen02 + \ ["", 2, 0.5, linear, "", "#0808B8", 1.2, [DOWN], [2, slice(1, 4, 2)], "", [slice(1, 2), WHITE, [-2.5, 0, 0]]][len(screen02):] [title, subtitle, filename, reference, warning, mobjes_3_run_time] =\ screen03 + [[], [], [], [], [], 3][len(screen03):] [title, title_color, title_scale, title_position] = title + \ ["", WHITE, 1, [UP]][len(title):] [subtitle, subtitle_color, subtitle_scale, subtitle_position] = subtitle + \ ["", WHITE, 1, [0, 0, 0]][len(subtitle):] [filename, filename_color, filename_scale, filename_position] = filename + \ ["", WHITE, 1, [0, -2.9, 0]][len(filename):] [reference, reference_color, reference_scale, reference_position] = reference + \ ["", YELLOW, 1, [0, -3.3, 0]][len(reference):] [warning, warning_color, warning_scale, warning_position] = warning + \ ["", YELLOW, 1, [0, -3.7, 0] ][len(warning):] startscreens = AGroup() if mobjs_1 != None: if mobjs_1 == "": try: mobjs_1 = ImageMobjectGroup( np.char.mod('%01d', range(0, 10)), "sidewayoutput\\sidewayoutput2020yt") except: mobjs_1 = ImageMobjectGroup( np.char.mod('%01d', range(9, -1, -1)), "001\\") if title_1 == "": title_1 = PoweredBy title_1 = MobjectOrChars(title_1) title_1.set_color(title_1_color).scale( title_1_scale).align_on_border( *title_1_position).add_shadow_mobjects( title_1_shadow[0], title_1[title_1_shadow[1]]) if title_1_extra != "": title_1[title_1_extra[0]].set_color(title_1_extra[1]).shift( title_1_extra[2]) if title_1_indicate_scale_factor == "": title_width = mobjs_1.get_width() title_1_indicate_scale_factor = (title_width - 0.5) / title_width startscreens.add( ShowSubmobjectsOneByOneAndFadeInThenIndicateThenFadeOut( mobjs_1.scale(mobjs_1_scale), title_1, indicate_scale_factor=title_1_indicate_scale_factor, show_rate_func=mobjs_1_rate_func, run_time=mobjs_1_interval * (len(mobjs_1)), **kwargs)) if mobjs_2 != None: if mobjs_2 == "": strs = TextMobject(r"\textspA{%s}" % Project) mobjs_2 = Group( Circle(fill_opacity=0.75), RegularPolygon(fill_opacity=0.75), Triangle(color=GREEN, fill_opacity=0.75), Square(fill_opacity=0.75), strs.set_color("#FFFFFF"), strs.copy().set_color("#F8F8F8").scale(1.3), strs.copy().set_color("#F8F8B8").scale(1.6), strs.copy().set_color("#B8B8B8").scale(1.6), strs.copy().set_color("#8888B8").scale(1.6), strs.copy().set_color("#6868B8").scale(1.6), strs.copy().set_color("#4848B8").scale(1.6), strs.copy().set_color("#2828B8").scale(1.6), strs.copy().set_color("#0808B8").scale(1.6), ) if title_2 == "": title_2 = (r"{\tiny{\emph{Powered by}:}}\\ ", *PoweredBy) title_2 = MobjectOrChars(title_2) title_2.set_color(title_2_color).scale( title_2_scale).align_on_border( *title_2_position).add_shadow_mobjects( title_2_shadow[0], title_2[title_2_shadow[1]]) if title_2_extra != "": title_2[title_2_extra[0]].set_color(title_2_extra[1]).shift( title_2_extra[2]) if title_2_indicate_scale_factor == "": title_width = mobjs_2.get_width() title_2_indicate_scale_factor = (title_width - 0.5) / title_width startscreens.add( ShowSubmobjectsOneByOneAndFadeInThenIndicateThenFadeOut( mobjs_2.scale(mobjs_2_scale), title_2, indicate_scale_factor=title_2_indicate_scale_factor, show_rate_func=mobjs_2_rate_func, run_time=mobjs_2_interval * (len(mobjs_2)), **kwargs)) if title != None or subtitle != None: mobjs_3 = [Group(), "", ""] if title != None: txt_title = TextMobject(title).scale(title_scale) if txt_title.get_width() > 14: txt_title.stretch_to_fit_width(14) mobjs_3[1] = txt_title.set_color(title_color).to_edge( *title_position) mobjs_3[0].add(mobjs_3[1]) if subtitle != None: mobjs_3[0].add( TextMobject(subtitle).set_color(subtitle_color).scale( subtitle_scale).shift(subtitle_position)) if filename != None and filename != "": if reference == None or reference == "": filename_position = reference_position mobjs_3[0].add( TextMobject(filename).set_color(filename_color).scale( filename_scale).shift(filename_position)) if reference != None and reference != "": txt_reference = TextMobject(reference).scale(reference_scale) if txt_reference.get_width() > 14: txt_reference.stretch_to_fit_width(14) mobjs_3[0].add( txt_reference.set_color(reference_color).shift( reference_position)) if warning != None and warning != "": txt_warning = TextMobject(warning).scale( warning_scale) # height=0.3 if txt_warning.get_width() > 14: txt_warning.stretch_to_fit_width(14) mobjs_3[2] = txt_warning.set_color(warning_color).shift( warning_position) animations = AGroup() if len(mobjs_3[0]) > 0: animations.add( FadeIn(mobjs_3[0], run_time=0.5, scale_factor=1, color=None)) if len(mobjs_3[1]) > 0: animations.add(GrowFromCenter(Underline(mobjs_3[1]))) if len(mobjs_3[2]) > 0: animations.add( FadeInThenIndicate(mobjs_3[2], run_time=0.5, scale_factor=1.2, color=None)) startscreens.add( FadeoutSuccession(AnimationGroup(*animations, run_time=mobjes_3_run_time), run_time=0.05)) super().__init__(AnimationGroup(*startscreens, lag_ratio=1), **kwargs)
def __init__(self, parbs, anibs, sndbs, j_start=1, j_first=None, j_count=None, i_start=1, i_first=None, i_count=None, j_position=GeomPosition([-6.5, 3.3, 0]), j_width=[13], j_height=7, i_position=GeomPosition([0, 3.3, 0]), i_width=[6.75], i_height=7, mobjs=None, scene=None, **kwargs): if j_count is None: j_count = len(parbs[0]) if j_first is None: j_first = j_start if scene is None: scene = V.scene if mobjs is None: mobjs = AnimatedGroup().scale(0.2).post_to(scene) animations = AGroup() if 1 == 1: animations.add( AnimationGroup(Animation(Mobject()), sound=sndbs[0][0], xaction="sound")) animations.add( AnimationGroup(GrowTitle(parbs[0][0]), Freeze(4), anibs[0][0], foreground=True, xaction="post")) j_end = min((j_start + j_count), len(parbs[0]), len(anibs[0])) grpa = VGroup(j_position) OrderedGroup(grpa, ["/"] * (j_start - 1) + parbs[0][j_start:], width=j_width).post_to(scene) #["/"]*(i_start-1)+ blka = VGroup().save_state() blk = [grpa[j_first:j_first + i + 1] for i in range(j_count + 1)] blk[0].save_state() for j in range(j_start, j_end): print("j", j) grpa[j].add_to_group(blka) rcca = VGroup() while blka.get_height() > j_height: if len(blka) == 1: grpa[j].stretch_to_fit_height(j_height - 0.05) else: blka[0].add_to_group(rcca).remove_from_group(blka) if j >= j_first: animations.add( AnimationGroup(Animation(Mobject()), sound=sndbs[0][j], xaction="sound")) animations.add( AnimationGroup( PlayMobject(mobjs.copy().next_to(grpa[j]), grpa[j]), DiminishToSide(rcca), Write(grpa[j]), anibs[0][j], Freeze(2))) else: animations.add( AnimationGroup(DiminishToSide(rcca), Animation(grpa[j]), anibs[0][j], xaction="display")) if 1 == 1 and j >= j_first: animations.add( AnimationGroup(DiminishToEdge(blk[j - j_first].save_state()), run_time=0.5)) animations.add( *SlideShow01(parbs[j], anibs[j], sndbs[j], i_start, i_count, i_first).animations) animations.add( AnimationGroup(exclude_mobjs="foreground", xaction="fadeout")) if j < j_end - 1: animations.add( AnimationGroup(Restore(blk[j - j_first]), run_time=0.5)) super().__init__(*animations, )
def __init__(self, paras, anims, sound, i_start=1, i_count=None, i_first=None, position=GeomPosition([0, 3.3, 0]), width=[6.75], height=7, mobjs=None, scene=None, animate=True, **kwargs): if i_count is None: i_count = len(paras) if i_first is None: i_first = i_start if scene is None: scene = V.scene if mobjs is None: mobjs = AnimatedGroup().scale(0.2).post_to(scene) animations = AGroup() if 1 == 1 and paras[0] is not None: animations.add( AnimationGroup(Animation(Mobject()), sound=sound[0], xaction="sound")) animations.add( AnimationGroup(GrowTitle(paras[0]), Freeze(4), anims[0], foreground=True, xaction="post")) i_end = min((i_start + i_count), len(paras), len(anims)) print(i_end, i_start + i_count, len(paras), len(paras)) group = VGroup(position) OrderedGroup(group, ["/"] * (i_start - 1) + paras[i_start:i_end], width=width).post_to(scene) block = VGroup() print("i", anims[0].run_time) anim = Animation(Mobject()) for i in range(i_start, i_end): print("i", i, anims[i].run_time) group[i].add_to_group(block) recycle = VGroup() if animate: anim = anims[i] while block.get_height() > height: if len(block) == 1: group[i].stretch_to_fit_height(height - 0.05) else: block[0].add_to_group(recycle).remove_from_group(block) if i >= i_first: animations.add( AnimationGroup(Animation(Mobject()), sound=sound[i], time_offset=0.5, xaction="sound")) animations.add( AnimationGroup( anim, PlayMobject(mobjs.copy().next_to(group[i]), group[i]), DiminishToSide(recycle), Write(group[i]), )) else: animations.add( AnimationGroup(animDiminishToSide(recycle), Animation(group[i]), xaction="display")) #anim, super().__init__(*animations)
def __init__(self, *mobjects, rate_func=shorten, **kwargs): animations = AGroup() for mobject in mobjects: animations.add(self.CONFIG["funx"](mobject, rate_func=rate_func,**kwargs)) super().__init__(*animations, **kwargs)
def __init__(self, mobjects, **kwargs): animations = AGroup() [animations.add(ShowCreation(each, **kwargs)) for each in mobjects] super().__init__( AnimationGroup(*animations))