def update(self, dt): # Not actual time, but something which passes at # an altered rate to make the implementation below # cleaner time = self.total_time * self.cycle_rate growing, fading = self.boundary_copies colors = self.colors msw = self.max_stroke_width vmobject = self.vmobject index = int(time % len(colors)) alpha = smooth(time % 1) if int(time) % 2 == 0: bounds = (0, alpha) else: bounds = (1 - alpha, 1) self.full_family_become_partial(growing, vmobject, *bounds) growing.set_stroke(colors[index], width=msw) if time >= 1: self.full_family_become_partial(fading, vmobject, 0, 1) fading.set_stroke(color=colors[index - 1], width=(1 - alpha) * msw) self.total_time += dt
class UnGrowFromRandom(GrowFromRandom): CONFIG = { "anim_kwargs": { "rate_func": lambda t: smooth(1 - t) }, "remover": True }
class UnWriteRandom(WriteRandom): CONFIG = { "anim_kwargs": { "rate_func": lambda t: smooth(1 - t) }, "remover": True, }
def do_vectors_only_period_hide(self, _, alpha): fade_ratio = 3 if alpha >= (fade_ratio - 1) / fade_ratio: opacity = 1 - smooth(fade_ratio * alpha - (fade_ratio - 1)) self.x_vector.set_opacity(opacity) self.y_vector.set_opacity(opacity) self.xy_vector.set_opacity(opacity) self.ellipse.set_stroke(opacity=opacity) self.do_vectors_only_period(_, alpha)
def get_sub_alpha(self, alpha, index, num_submobjects): if self.submobject_mode in ["lagged_start", "smoothed_lagged_start"]: prop = float(index) / num_submobjects if self.submobject_mode is "smoothed_lagged_start": prop = smooth(prop) lf = self.lag_factor return np.clip(lf * alpha - (lf - 1) * prop, 0, 1) elif self.submobject_mode == "one_at_a_time": lower = float(index) / num_submobjects upper = float(index + 1) / num_submobjects return np.clip((alpha - lower) / (upper - lower), 0, 1) elif self.submobject_mode == "all_at_once": return alpha raise Exception("Invalid submobject mode")
class Uncreate(ShowCreation): """ Type: ``ShowCreation`` ``CONFIG`` parameters :: "rate_func": lambda t: smooth(1 - t), "remover": True """ CONFIG = { "rate_func": lambda t: smooth(1 - t), "remover": True }
def get_sub_alpha(self, alpha, index, num_submobjects): # TODO, make this more understanable, and/or combine # its functionality with AnimationGroup's method # build_animations_with_timings lag_ratio = self.lag_ratio full_length = (num_submobjects - 1) * lag_ratio + 1 value = alpha * full_length lower = index * lag_ratio if self.submobject_mode in ["lagged_start", "smoothed_lagged_start"]: prop = float(index) / num_submobjects if self.submobject_mode is "smoothed_lagged_start": prop = smooth(prop) lf = self.lag_factor return np.clip(lf * alpha - (lf - 1) * prop, 0, 1) elif self.submobject_mode == "one_at_a_time": lower = float(index) / num_submobjects upper = float(index + 1) / num_submobjects return np.clip((alpha - lower) / (upper - lower), 0, 1) elif self.submobject_mode == "all_at_once": return alpha return np.clip((value - lower), 0, 1)
class Uncreate(ShowCreation): CONFIG = { "rate_func": lambda t: smooth(1 - t), "remover": True, "should_match_start": True, }
class Uncreate(ShowCreation): CONFIG = { "rate_func": lambda t: smooth(1 - t), "remover": True }
def construct(self): text = TextMobject("Hello") # Just run rate_func backward self.play(Write(text, rate_func=lambda t: smooth(1 - t))) self.wait()