コード例 #1
0
ファイル: light.py プロジェクト: coallaoh/manim
 def __init__(self, light, **kwargs):
     if (not isinstance(light, AmbientLight) and not isinstance(light, Spotlight)):
         raise Exception(
             "Only AmbientLights and Spotlights can be switched off")
     light.submobjects = light.submobjects[::-1]
     LaggedStartMap.__init__(self, FadeOut, light, **kwargs)
     light.submobjects = light.submobjects[::-1]
コード例 #2
0
ファイル: light.py プロジェクト: coallaoh/manim
 def __init__(self, light, **kwargs):
     if (not isinstance(light, AmbientLight) and not isinstance(light, Spotlight)):
         raise Exception(
             "Only AmbientLights and Spotlights can be switched on")
     LaggedStartMap.__init__(
         self, FadeIn, light, **kwargs
     )
コード例 #3
0
 def __init__(self, light, **kwargs):
     if (not isinstance(light, AmbientLight) and not isinstance(light, Spotlight)):
         raise Exception(
             "Only AmbientLights and Spotlights can be switched off")
     light.submobjects = light.submobjects[::-1]
     LaggedStartMap.__init__(self, FadeOut, light, **kwargs)
     light.submobjects = light.submobjects[::-1]
コード例 #4
0
 def __init__(self, light, **kwargs):
     if (not isinstance(light, AmbientLight) and not isinstance(light, Spotlight)):
         raise Exception(
             "Only AmbientLights and Spotlights can be switched on")
     LaggedStartMap.__init__(
         self, FadeIn, light, **kwargs
     )
コード例 #5
0
    def get_logo_animations(self, logo):
        layers = logo.spike_layers
        for i, layer in enumerate(layers):
            random.shuffle(layer.submobjects)
            for spike in layer:
                spike.save_state()
                spike.scale(0.5)
                spike.apply_complex_function(np.log)
                spike.rotate(-90 * DEGREES, about_point=ORIGIN)
                spike.set_fill(opacity=0)
            layer.rotate(i * PI / 5)

        logo.iris_background.save_state()
        logo.iris_background.scale(0.25)
        logo.iris_background.fade(1)

        return [
            Restore(
                logo.iris_background,
                run_time=3,
            ),
            AnimationGroup(*[
                LaggedStartMap(
                    Restore,
                    layer,
                    run_time=3,
                    path_arc=180 * DEGREES,
                    # rate_func=squish_rate_func(smooth, a / 3.0, (a + 1.9) / 3.0),
                    lag_ratio=0.8,
                ) for layer, a in zip(layers, [0, 0.2, 0.1, 0])
            ]),
            Animation(logo.pupil),
        ]
コード例 #6
0
    def construct(self):
        morty = Mortimer()
        morty.next_to(ORIGIN, DOWN)

        patreon_logo = PatreonLogo()
        patreon_logo.to_edge(UP)

        patrons = list(map(TextMobject, self.specific_patronds))
        num_groups = float(len(patrons)) / self.max_patron_group_size
        proportion_range = np.linspace(0, 1, num_groups + 1)
        indices = (len(patrons) * proportion_range).astype('int')
        patron_groups = [
            VGroup(*patrons[i:j])
            for i, j in zip(indices, indices[1:])
        ]

        for i, group in enumerate(patron_groups):
            left_group = VGroup(*group[:len(group) / 2])
            right_group = VGroup(*group[len(group) / 2:])
            for subgroup, vect in (left_group, LEFT), (right_group, RIGHT):
                subgroup.arrange(DOWN, aligned_edge=LEFT)
                subgroup.scale(self.patron_scale_val)
                subgroup.to_edge(vect)

        last_group = None
        for i, group in enumerate(patron_groups):
            anims = []
            if last_group is not None:
                self.play(
                    FadeOut(last_group),
                    morty.look, UP + LEFT
                )
            else:
                anims += [
                    DrawBorderThenFill(patreon_logo),
                ]
            self.play(
                LaggedStartMap(
                    FadeIn, group,
                    run_time=2,
                ),
                morty.change, "gracious", group.get_corner(UP + LEFT),
                *anims
            )
            self.play(morty.look_at, group.get_corner(DOWN + LEFT))
            self.play(morty.look_at, group.get_corner(UP + RIGHT))
            self.play(morty.look_at, group.get_corner(DOWN + RIGHT))
            self.play(Blink(morty))
            last_group = group
コード例 #7
0
    def get_logo_animations(self, logo):
        layers = logo.spike_layers

        for j, layer in enumerate(layers):
            for i, spike in enumerate(layer):
                spike.angle = (13 * (i + 1) * (j + 1) * TAU / 28) % TAU
                if spike.angle > PI:
                    spike.angle -= TAU
                spike.save_state()
                spike.rotate(spike.angle, about_point=ORIGIN)
                # spike.get_points()[1] = rotate_vector(
                #     spike.get_points()[1], TAU/28,
                # )
                # spike.get_points()[-1] = rotate_vector(
                #     spike.get_points()[-1], -TAU/28,
                # )

        def get_spike_animation(spike, **kwargs):
            return Restore(spike, path_arc=-spike.angle, **kwargs)

        logo.iris_background.save_state()
        # logo.iris_background.scale(0.49)
        logo.iris_background.set_fill(GREY_D, 0.5)

        return [
            Restore(
                logo.iris_background,
                rate_func=squish_rate_func(smooth, 2.0 / 3, 1),
                run_time=3,
            ),
            AnimationGroup(*[
                LaggedStartMap(
                    get_spike_animation,
                    layer,
                    run_time=2,
                    # rate_func=squish_rate_func(smooth, a / 3.0, (a + 0.9) / 3.0),
                    lag_ratio=0.2,
                ) for layer, a in zip(layers, [0, 2, 1, 0])
            ]),
            Animation(logo.pupil),
        ]
コード例 #8
0
    def construct(self):
        # construction of demo props
        lines = VGroup()
        for i in range(-5, 6):
            lines.add(Line(3 * UP + i * RIGHT, 3 * DOWN + i * RIGHT))

        # LaggedStartMap is used when you want to apply one animation to lots of mobjects
        # with lagged start

        # run_time is for the whole LaggedStartMap animation, not for individual animations
        # lag_ratio - how much does it wait before running next animation (as a ratio of the time
        # of one animation)
        # rate_func applies for individual animations, launching the animations is always linear,
        # because lag_ratio is constant
        self.play(
            LaggedStartMap(ShowCreation,
                           lines,
                           run_time=10,
                           lag_ratio=0.5,
                           rate_func=linear))
        self.wait()
コード例 #9
0
    def construct(self):
        logo = self.logo
        name = self.channel_name

        layers = logo.spike_layers

        logo.save_state()

        for layer in layers:
            for spike in layer:
                spike.save_state()
                point = np.array(spike.get_points()[0])
                angle = angle_of_vector(point)
                spike.rotate(-angle + 90 * DEGREES)
                spike.stretch_to_fit_width(0.2)
                spike.stretch_to_fit_height(0.5)
                spike.point = point
            for spike in layer[::2]:
                spike.rotate(180 * DEGREES)
            layer.arrange(LEFT, buff=0.1)
        layers.arrange(UP)
        layers.to_edge(DOWN)

        wrong_spike = layers[1][-5]
        wrong_spike.real_saved_state = wrong_spike.saved_state.copy()
        wrong_spike.saved_state.scale(0.25, about_point=wrong_spike.point)
        wrong_spike.saved_state.rotate(90 * DEGREES)
        self.wrong_spike = wrong_spike

        def get_spike_animation(spike, **kwargs):
            return Restore(spike, **kwargs)

        logo.iris_background.save_state()
        logo.iris_background.set_fill(opacity=0.0)
        logo.iris_background.scale(0.8)

        alt_name = name.copy()
        alt_name.set_stroke(BLACK, 5)

        self.play(
            Restore(
                logo.iris_background,
                rate_func=squish_rate_func(smooth, 1.0 / 3, 1),
                run_time=2,
            ),
            AnimationGroup(*(
                LaggedStartMap(
                    get_spike_animation,
                    layer,
                    run_time=2,
                    # rate_func=squish_rate_func(smooth, a / 3.0, (a + 0.9) / 3.0),
                    lag_ratio=2 / len(layer),
                    path_arc=-90 * DEGREES)
                for layer, a in zip(layers, [0, 2, 1, 0]))),
            Animation(logo.pupil),
            Write(alt_name),
            Write(name),
            run_time=3)

        self.wait(0.25)
        self.play(Transform(
            wrong_spike,
            wrong_spike.real_saved_state,
        ),
                  Animation(self.logo),
                  run_time=0.75)
コード例 #10
0
 def return_animation(self, line, **kwargs):
     if self.line_type == Line:
         return ShowCreationThenDestruction(line, **kwargs)
     elif self.line_type == DashedLine:
         return LaggedStartMap(ShowCreationThenDestruction, line, **kwargs)