示例#1
0
    def construct(self):
        logo = ImageMobject("LogoGeneration", invert = False)
        name_mob = TextMobject("3Blue1Brown").center()
        name_mob.highlight("grey")
        name_mob.shift(2*DOWN)
        self.add(name_mob, logo)

        new_text = TextMobject(["with ", "Steven Strogatz"])
        new_text.next_to(name_mob, DOWN)
        self.play(*[
            ShimmerIn(part)
            for part in new_text.split()
        ])
        self.dither()
        with_word, steve = new_text.split()
        steve_copy = steve.copy().center().to_edge(UP)
        # logo.sort_points(lambda p : -np.linalg.norm(p))
        sort_by_color(logo)
        self.play(
            Transform(steve, steve_copy),
            DelayByOrder(Transform(logo, Point())),
            FadeOut(with_word),
            FadeOut(name_mob),
            run_time = 3
        )
示例#2
0
    def construct(self):
        words = TextMobject("Order 3 Pseudo-Hilbert Curve")
        words.highlight(GREEN)
        words.to_edge(UP)
        grid4 = Mobject(Grid(2, 2), Grid(4, 4, point_thickness=2))
        grid8 = Grid(8, 8, point_thickness=1)
        order_3_curve = HilbertCurve(order=3)
        mini_curves = [
            HilbertCurve(order=2).scale(0.5).shift(1.5 * vect)
            for vect in [LEFT + DOWN, LEFT + UP, RIGHT + UP, RIGHT + DOWN]
        ]

        self.add(words, grid4)
        self.dither()
        self.play(ShowCreation(grid8))
        self.dither()
        self.play(*map(GrowFromCenter, mini_curves))
        self.dither()
        self.clear()
        self.add(words, grid8, *mini_curves)
        self.play(*[
            ApplyMethod(curve.rotate_in_place, np.pi, axis)
            for curve, axis in [(mini_curves[0],
                                 UP + RIGHT), (mini_curves[3], UP + LEFT)]
        ])
        self.play(ShowCreation(order_3_curve, run_time=5))
        self.dither()
示例#3
0
    def finite_analog(self, left_mob, arrow, right_mob):
        self.clear()
        self.add(left_mob, arrow, right_mob)
        ex = TextMobject("\\times")
        ex.highlight(RED)
        # ex.shift(arrow.get_center())
        middle = TexMobject("\\sum_{n=0}^N 2^n \\equiv -1 \\mod 2^{N+1}")
        finite_analog = TextMobject("Finite analog")
        finite_analog.scale(0.8)
        brace = Brace(middle, UP)
        finite_analog.next_to(brace, UP)
        new_left = left_mob.copy().to_edge(LEFT)
        new_right = right_mob.copy().to_edge(RIGHT)
        left_arrow, right_arrow = [
            Arrow(mob1.get_right()[0] * RIGHT,
                  mob2.get_left()[0] * RIGHT,
                  buff=0)
            for mob1, mob2 in [(new_left, middle), (middle, new_right)]
        ]
        for mob in ex, middle:
            mob.sort_points(np.linalg.norm)

        self.play(GrowFromCenter(ex))
        self.wait()
        self.play(Transform(left_mob, new_left),
                  Transform(arrow.copy(), left_arrow),
                  DelayByOrder(Transform(ex, middle)),
                  Transform(arrow, right_arrow),
                  Transform(right_mob, new_right))
        self.play(GrowFromCenter(brace), ShimmerIn(finite_analog))
        self.wait()
        self.equivalence(left_mob, left_arrow,
                         Mobject(middle, brace, finite_analog))
示例#4
0
    def construct(self):
        words = TextMobject("Order 2 Pseudo-Hilbert Curve")
        words.to_edge(UP, buff=0.3)
        words.highlight(GREEN)
        grid2 = Grid(2, 2)
        grid4 = Grid(4, 4, point_thickness=2)
        # order_1_curve = HilbertCurve(order = 1)
        # squaggle_curve = order_1_curve.copy().apply_function(
        #     lambda (x, y, z) : (x + np.cos(3*y), y + np.sin(3*x), z)
        # )
        # squaggle_curve.show()
        mini_curves = [
            HilbertCurve(order=1).scale(0.5).shift(1.5 * vect)
            for vect in [LEFT + DOWN, LEFT + UP, RIGHT + UP, RIGHT + DOWN]
        ]
        last_curve = mini_curves[0]
        naive_curve = Mobject(last_curve)
        for mini_curve in mini_curves[1:]:
            line = Line(last_curve.points[-1], mini_curve.points[0])
            naive_curve.add(line, mini_curve)
            last_curve = mini_curve
        naive_curve.ingest_sub_mobjects()
        naive_curve.gradient_highlight(RED, GREEN)
        order_2_curve = HilbertCurve(order=2)

        self.add(words, grid2)
        self.dither()
        self.play(ShowCreation(grid4))
        self.play(*[ShowCreation(mini_curve) for mini_curve in mini_curves])
        self.dither()
        self.play(ShowCreation(naive_curve, run_time=5))
        self.remove(*mini_curves)
        self.dither()
        self.play(Transform(naive_curve, order_2_curve))
        self.dither()
示例#5
0
class LogoGeneration(Scene):
    CONFIG = {
        "radius"               : 1.5,
        "inner_radius_ratio"   : 0.55,
        "circle_density"       : 100,
        "circle_blue"          : "skyblue",
        "circle_brown"         : DARK_BROWN,
        "circle_repeats"       : 5,
        "sphere_density"       : 50,
        "sphere_blue"          : DARK_BLUE,
        "sphere_brown"         : LIGHT_BROWN,
        "interpolation_factor" : 0.3,
        "frame_duration"       : 0.03,
        "run_time"             : 3,
    }
    def construct(self):
        digest_config(self, {})
        ## Usually shouldn't need this...
        self.frame_duration = self.CONFIG["frame_duration"]
        ##
        digest_config(self, {})
        circle = Circle(
            density = self.circle_density, 
            color   = self.circle_blue
        )
        circle.repeat(self.circle_repeats)
        circle.scale(self.radius)
        sphere = Sphere(
            density = self.sphere_density, 
            color   = self.sphere_blue
        )
        sphere.scale(self.radius)
        sphere.rotate(-np.pi / 7, [1, 0, 0])
        sphere.rotate(-np.pi / 7)
        iris = Mobject()
        iris.interpolate(
            circle, sphere,
            self.interpolation_factor
        )
        for mob, color in [(iris, self.sphere_brown), (circle, self.circle_brown)]:
            mob.highlight(color, lambda (x, y, z) : x < 0 and y > 0)
            mob.highlight(
                "black", 
                lambda point: np.linalg.norm(point) < \
                              self.inner_radius_ratio*self.radius
            )
        self.name_mob = TextMobject("3Blue1Brown").center()
        self.name_mob.highlight("grey")
        self.name_mob.shift(2*DOWN)

        self.play(Transform(
            circle, iris, 
            run_time = self.run_time
        ))
        self.frames = drag_pixels(self.frames)
        self.save_image(IMAGE_DIR)
        self.logo = MobjectFromPixelArray(self.frames[-1])
        self.add(self.name_mob)
        self.wait()
示例#6
0
    def show_equation(self):
        equation = TexMobject([
            "\\left(\\dfrac{1}{\\phantom{v_air}}\\right)", "\\sin(\\theta_1)",
            "=", "\\left(\\dfrac{1}{\\phantom{v_water}}\\right)",
            "\\sin(\\theta_2)"
        ])
        equation.to_corner(UP + RIGHT)
        frac1, sin1, equals, frac2, sin2 = equation.split()
        v_air, v_water = [
            TexMobject("v_{\\text{%s}}" % s, size="\\Large")
            for s in "air", "water"
        ]
        v_air.next_to(Point(frac1.get_center()), DOWN)
        v_water.next_to(Point(frac2.get_center()), DOWN)
        frac1.add(v_air)
        frac2.add(v_water)
        f1, f2 = [TexMobject("F_%d" % d, size="\\Large") for d in 1, 2]
        f1.next_to(sin1, LEFT)
        f2.next_to(equals, RIGHT)
        sin2_start = sin2.copy().next_to(f2, RIGHT)
        bar1 = TexMobject("\\dfrac{\\qquad}{\\qquad}")
        bar2 = bar1.copy()
        bar1.next_to(sin1, DOWN)
        bar2.next_to(sin2, DOWN)
        v_air_copy = v_air.copy().next_to(bar1, DOWN)
        v_water_copy = v_water.copy().next_to(bar2, DOWN)
        bars = Mobject(bar1, bar2)
        new_eq = equals.copy().center().shift(bars.get_center())
        snells = TextMobject("Snell's Law")
        snells.highlight(YELLOW)
        snells.shift(new_eq.get_center()[0] * RIGHT)
        snells.shift(UP)

        anims = []
        for mob in f1, sin1, equals, f2, sin2_start:
            anims.append(ShimmerIn(mob))
        self.play(*anims)
        self.wait()
        for f, frac in (f1, frac1), (f2, frac2):
            target = frac.copy().ingest_submobjects()
            also = []
            if f is f2:
                also.append(Transform(sin2_start, sin2))
                sin2 = sin2_start
            self.play(Transform(f, target), *also)
            self.remove(f)
            self.add(frac)
        self.wait()
        self.play(FadeOut(frac1), FadeOut(frac2), Transform(v_air, v_air_copy),
                  Transform(v_water, v_water_copy), ShowCreation(bars),
                  Transform(equals, new_eq))
        self.wait()
        frac1 = Mobject(sin1, bar1, v_air)
        frac2 = Mobject(sin2, bar2, v_water)
        for frac, vect in (frac1, LEFT), (frac2, RIGHT):
            self.play(ApplyMethod(frac.next_to, equals, vect))
        self.wait()
        self.play(ShimmerIn(snells))
        self.wait()
示例#7
0
文件: light.py 项目: PythonJedi/manim
    def construct(self):
        point_a = 3*LEFT+3*UP
        point_b = 1.5*RIGHT+3*DOWN
        midpoint = ORIGIN

        lines, arcs, thetas = [], [], []
        counter = it.count(1)
        for point in point_a, point_b:
            line = Line(point, midpoint, color = RED_D)
            angle = np.pi/2-np.abs(np.arctan(line.get_slope()))
            arc = Arc(angle, radius = 0.5).rotate(np.pi/2)
            if point is point_b:
                arc.rotate(np.pi)
                line.reverse_points()
            theta = TexMobject("\\theta_%d"%counter.next())
            theta.scale(0.5)
            theta.shift(2*arc.get_center())
            arc.shift(midpoint)
            theta.shift(midpoint)

            lines.append(line)
            arcs.append(arc)
            thetas.append(theta)
        vert_line = Line(2*UP, 2*DOWN)
        vert_line.shift(midpoint)
        path = Mobject(*lines).ingest_submobjects()
        glass = Region(lambda x, y : y < 0, color = BLUE_E)
        self.add(glass)
        equation = TexMobject([
            "\\dfrac{\\sin(\\theta_1)}{v_{\\text{air}}}",
            "=",            
            "\\dfrac{\\sin(\\theta_2)}{v_{\\text{water}}}",
        ])
        equation.to_corner(UP+RIGHT)
        exp1, equals, exp2 = equation.split()
        snells_law = TextMobject("Snell's Law:")
        snells_law.highlight(YELLOW)
        snells_law.to_edge(UP)

        self.play(ShimmerIn(snells_law))
        self.dither()
        self.play(ShowCreation(path))
        self.play(self.photon_run_along_path(path))
        self.dither()
        self.play(ShowCreation(vert_line))
        self.play(*map(ShowCreation, arcs))
        self.play(*map(GrowFromCenter, thetas))
        self.dither()
        self.play(ShimmerIn(exp1))
        self.dither()
        self.play(*map(ShimmerIn, [equals, exp2]))
        self.dither()
示例#8
0
    def construct(self):
        point_a = 3*LEFT+3*UP
        point_b = 1.5*RIGHT+3*DOWN
        midpoint = ORIGIN

        lines, arcs, thetas = [], [], []
        counter = it.count(1)
        for point in point_a, point_b:
            line = Line(point, midpoint, color = RED_D)
            angle = np.pi/2-np.abs(np.arctan(line.get_slope()))
            arc = Arc(angle, radius = 0.5).rotate(np.pi/2)
            if point is point_b:
                arc.rotate(np.pi)
                line.reverse_points()
            theta = TexMobject("\\theta_%d"%counter.next())
            theta.scale(0.5)
            theta.shift(2*arc.get_center())
            arc.shift(midpoint)
            theta.shift(midpoint)

            lines.append(line)
            arcs.append(arc)
            thetas.append(theta)
        vert_line = Line(2*UP, 2*DOWN)
        vert_line.shift(midpoint)
        path = Mobject(*lines).ingest_submobjects()
        glass = Region(lambda x, y : y < 0, color = BLUE_E)
        self.add(glass)
        equation = TexMobject([
            "\\dfrac{\\sin(\\theta_1)}{v_{\\text{air}}}",
            "=",            
            "\\dfrac{\\sin(\\theta_2)}{v_{\\text{water}}}",
        ])
        equation.to_corner(UP+RIGHT)
        exp1, equals, exp2 = equation.split()
        snells_law = TextMobject("Snell's Law:")
        snells_law.highlight(YELLOW)
        snells_law.to_edge(UP)

        self.play(ShimmerIn(snells_law))
        self.wait()
        self.play(ShowCreation(path))
        self.play(self.photon_run_along_path(path))
        self.wait()
        self.play(ShowCreation(vert_line))
        self.play(*map(ShowCreation, arcs))
        self.play(*map(GrowFromCenter, thetas))
        self.wait()
        self.play(ShimmerIn(exp1))
        self.wait()
        self.play(*map(ShimmerIn, [equals, exp2]))
        self.wait()
示例#9
0
    def construct(self):
        horiz_radius = 5
        vert_radius = 3

        vert_axis = NumberLine(numerical_radius=vert_radius)
        vert_axis.rotate(np.pi / 2)
        vert_axis.shift(horiz_radius * LEFT)
        horiz_axis = NumberLine(numerical_radius=5,
                                numbers_with_elongated_ticks=[])
        axes = Mobject(horiz_axis, vert_axis)
        graph = FunctionGraph(lambda x: 0.4 * (x - 2) * (x + 2) + 3,
                              x_min=-2,
                              x_max=2,
                              density=3 * DEFAULT_POINT_DENSITY_1D)
        graph.stretch_to_fit_width(2 * horiz_radius)
        graph.highlight(YELLOW)
        min_point = Dot(graph.get_bottom())
        nature_finds = TextMobject("Nature finds this point")
        nature_finds.scale(0.5)
        nature_finds.highlight(GREEN)
        nature_finds.shift(2 * RIGHT + 3 * UP)
        arrow = Arrow(nature_finds.get_bottom(), min_point, color=GREEN)

        side_words_start = TextMobject("Parameter describing")
        top_words, last_side_words = [
            map(TextMobject, pair)
            for pair in [("Light's travel time",
                          "Potential energy"), ("path", "mechanical state")]
        ]
        for word in top_words + last_side_words + [side_words_start]:
            word.scale(0.7)
        side_words_start.next_to(horiz_axis, DOWN)
        side_words_start.to_edge(RIGHT)
        for words in top_words:
            words.next_to(vert_axis, UP)
            words.to_edge(LEFT)
        for words in last_side_words:
            words.next_to(side_words_start, DOWN)
        for words in top_words[1], last_side_words[1]:
            words.highlight(RED)

        self.add(axes, top_words[0], side_words_start, last_side_words[0])
        self.play(ShowCreation(graph))
        self.play(ShimmerIn(nature_finds), ShowCreation(arrow),
                  ShowCreation(min_point))
        self.dither()
        self.play(FadeOut(top_words[0]), FadeOut(last_side_words[0]),
                  GrowFromCenter(top_words[1]),
                  GrowFromCenter(last_side_words[1]))
        self.dither(3)
示例#10
0
    def construct(self):
        morty = Mortimer()
        morty.next_to(ORIGIN, DOWN)

        n_patrons = len(self.specific_patrons)
        special_thanks = TextMobject("Special thanks")
        special_thanks.highlight(YELLOW)
        special_thanks.to_edge(UP)

        patreon_logo = PatreonLogo()
        patreon_logo.next_to(morty, UP, buff=MED_LARGE_BUFF)

        patrons = map(TextMobject, self.specific_patrons)
        patron_groups = []
        index = 0
        counter = 0
        while index < len(patrons):
            next_index = index + self.patron_group_size
            group = VGroup(*patrons[index:next_index])
            group.arrange_submobjects(DOWN, aligned_edge=LEFT)
            if counter % 2 == 0:
                group.to_edge(LEFT)
            else:
                group.to_edge(RIGHT)
            patron_groups.append(group)
            index = next_index
            counter += 1

        self.play(
            morty.change_mode,
            "gracious",
            DrawBorderThenFill(patreon_logo),
        )
        self.play(Write(special_thanks, run_time=1))
        for i, group in enumerate(patron_groups):
            anims = [
                FadeIn(
                    group,
                    run_time=2,
                    submobject_mode="lagged_start",
                    lag_factor=4,
                ),
                morty.look_at,
                group.get_top(),
            ]
            if i >= 2:
                anims.append(FadeOut(patron_groups[i - 2]))
            self.play(*anims)
            self.play(morty.look_at, group.get_bottom())
            self.play(Blink(morty))
示例#11
0
    def construct(self):
        mathy, bubble = get_mathy_and_bubble()
        bubble.write("For a 256x256 pixel array...")
        words = TextMobject("Order 8 Pseudo-Hilbert Curve")
        words.highlight(GREEN)
        words.to_edge(UP, buff=0.3)
        curve = HilbertCurve(order=8)

        self.add(mathy, bubble)
        self.play(ShimmerIn(bubble.content))
        self.dither()
        self.clear()
        self.add(words)
        self.play(ShowCreation(curve, run_time=7, rate_func=None))
        self.dither()
示例#12
0
    def finite_analog(self, left_mob, arrow, right_mob):
        self.clear()
        self.add(left_mob, arrow, right_mob)
        ex = TextMobject("\\times")
        ex.highlight(RED)
        # ex.shift(arrow.get_center())
        middle = TexMobject(
            "\\sum_{n=0}^N 2^n \\equiv -1 \\mod 2^{N+1}"
        )
        finite_analog = TextMobject("Finite analog")
        finite_analog.scale(0.8)
        brace = Brace(middle, UP)
        finite_analog.next_to(brace, UP)
        new_left = left_mob.copy().to_edge(LEFT)
        new_right = right_mob.copy().to_edge(RIGHT)
        left_arrow, right_arrow = [
            Arrow(
                mob1.get_right()[0]*RIGHT,
                mob2.get_left()[0]*RIGHT,
                buff = 0
            )
            for mob1, mob2 in [
                (new_left, middle), 
                (middle, new_right)
            ]
        ]
        for mob in ex, middle:
            mob.sort_points(np.linalg.norm)

        self.play(GrowFromCenter(ex))
        self.dither()
        self.play(
            Transform(left_mob, new_left),
            Transform(arrow.copy(), left_arrow),
            DelayByOrder(Transform(ex, middle)),
            Transform(arrow, right_arrow),
            Transform(right_mob, new_right)
        )
        self.play(
            GrowFromCenter(brace),
            ShimmerIn(finite_analog)
        )
        self.dither()
        self.equivalence(
            left_mob,
            left_arrow, 
            Mobject(middle, brace, finite_analog)
        )
示例#13
0
    def construct(self):
        morty = Mortimer()
        morty.next_to(ORIGIN, DOWN)

        n_patrons = len(self.specific_patrons)
        special_thanks = TextMobject("Special thanks")
        special_thanks.highlight(YELLOW)
        special_thanks.to_edge(UP)

        patreon_logo = PatreonLogo()
        patreon_logo.next_to(morty, UP, buff=MED_LARGE_BUFF)

        patrons = map(TextMobject, self.specific_patrons)
        num_groups = float(len(patrons)) / self.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):
            group.arrange_submobjects(DOWN, aligned_edge=LEFT)
            group.scale(self.patron_scale_val)
            group.to_edge(LEFT if i % 2 == 0 else RIGHT)

        self.play(
            morty.change_mode,
            "gracious",
            DrawBorderThenFill(patreon_logo),
        )
        self.play(Write(special_thanks, run_time=1))
        print len(patron_groups)
        for i, group in enumerate(patron_groups):
            anims = [
                FadeIn(
                    group,
                    run_time=2,
                    submobject_mode="lagged_start",
                    lag_factor=4,
                ),
                morty.look_at,
                group.get_top(),
            ]
            if i >= 2:
                anims.append(FadeOut(patron_groups[i - 2]))
            self.play(*anims)
            self.play(morty.look_at, group.get_bottom())
            self.play(Blink(morty))
示例#14
0
    def construct(self):
        morty = Mortimer()
        morty.next_to(ORIGIN, DOWN)

        n_patrons = len(self.specific_patrons)
        special_thanks = TextMobject("Special thanks")
        special_thanks.highlight(YELLOW)
        special_thanks.to_edge(UP)

        patreon_logo = PatreonLogo()
        patreon_logo.next_to(morty, UP, buff=MED_LARGE_BUFF)

        left_patrons = VGroup(
            *map(TextMobject, self.specific_patrons[:n_patrons / 2]))
        right_patrons = VGroup(
            *map(TextMobject, self.specific_patrons[n_patrons / 2:]))
        for patrons in left_patrons, right_patrons:
            patrons.arrange_submobjects(DOWN,
                                        aligned_edge=LEFT,
                                        buff=1.5 * MED_SMALL_BUFF)

        all_patrons = VGroup(left_patrons, right_patrons)
        all_patrons.scale(0.7)
        for patrons, vect in (left_patrons, LEFT), (right_patrons, RIGHT):
            patrons.to_corner(UP + vect, buff=MED_SMALL_BUFF)

        shift_distance = max(0, 1 - SPACE_HEIGHT - all_patrons.get_bottom()[1])
        velocity = shift_distance / 9.0

        def get_shift_anim():
            return ApplyMethod(all_patrons.shift,
                               velocity * UP,
                               rate_func=None)

        self.play(
            morty.change_mode,
            "gracious",
            DrawBorderThenFill(patreon_logo),
        )
        self.play(Write(special_thanks, run_time=1))
        self.play(Write(left_patrons), morty.look_at, left_patrons)
        self.play(Write(right_patrons), morty.look_at, right_patrons)
        self.play(Blink(morty), get_shift_anim())
        for patrons in left_patrons, right_patrons:
            for index in 0, -1:
                self.play(morty.look_at, patrons[index], get_shift_anim())
                self.play(get_shift_anim())
示例#15
0
    def construct(self):
        mathy, bubble = get_mathy_and_bubble()
        bubble.write("For a 256x256 pixel array...")
        words = TextMobject("Order 8 Pseudo-Hilbert Curve")
        words.highlight(GREEN)
        words.to_edge(UP, buff = 0.3)
        curve = HilbertCurve(order = 8)

        self.add(mathy, bubble)
        self.play(ShimmerIn(bubble.content))
        self.dither()
        self.clear()
        self.add(words)
        self.play(ShowCreation(
            curve, run_time = 7, rate_func = None
        ))
        self.dither()
示例#16
0
    def construct(self):
        digest_config(self, {})
        ## Usually shouldn't need this...
        self.frame_duration = self.DEFAULT_CONFIG["frame_duration"]
        ##
        digest_config(self, {})
        circle = Circle(
            density = self.circle_density, 
            color   = self.circle_blue
        )
        circle.repeat(self.circle_repeats)
        circle.scale(self.radius)
        sphere = Sphere(
            density = self.sphere_density, 
            color   = self.sphere_blue
        )
        sphere.scale(self.radius)
        sphere.rotate(-np.pi / 7, [1, 0, 0])
        sphere.rotate(-np.pi / 7)
        iris = Mobject()
        iris.interpolate(
            circle, sphere,
            self.interpolation_factor
        )
        for mob, color in [(iris, self.sphere_brown), (circle, self.circle_brown)]:
            mob.highlight(color, lambda (x, y, z) : x < 0 and y > 0)
            mob.highlight(
                "black", 
                lambda point: np.linalg.norm(point) < \
                              self.inner_radius_ratio*self.radius
            )
        name = TextMobject("3Blue1Brown").center()
        name.highlight("grey")
        name.shift(2*DOWN)

        self.play(Transform(
            circle, iris, 
            run_time = self.run_time
        ))
        self.frames = drag_pixels(self.frames)
        self.save_image(IMAGE_DIR)
        self.show_frame()
        self.add(name)
        self.dither()
        print "Dragging pixels..."
示例#17
0
文件: objects.py 项目: wuweiict/manim
    def get_corner_numbers(self, value, symbol):
        value_mob = TextMobject(value)
        width = self.get_width() / self.card_width_to_corner_num_width
        height = self.get_height() / self.card_height_to_corner_num_height
        value_mob.scale_to_fit_width(width)
        value_mob.stretch_to_fit_height(height)
        value_mob.next_to(self.get_corner(UP + LEFT),
                          DOWN + RIGHT,
                          buff=MED_LARGE_BUFF * width)
        value_mob.highlight(symbol.get_color())
        corner_symbol = symbol.copy()
        corner_symbol.scale_to_fit_width(width)
        corner_symbol.next_to(value_mob, DOWN, buff=MED_SMALL_BUFF * width)
        corner_group = VGroup(value_mob, corner_symbol)
        opposite_corner_group = corner_group.copy()
        opposite_corner_group.rotate(np.pi, about_point=self.get_center())

        return VGroup(corner_group, opposite_corner_group)
示例#18
0
 def label(self, text, time = 5):
     mob = TextMobject(text)
     mob.scale(1.5)
     mob.to_edge(UP)
     rectangle = region_from_polygon_vertices(*[
         mob.get_corner(vect) + 0.3*vect
         for vect in [
             UP+RIGHT,
             UP+LEFT,
             DOWN+LEFT,
             DOWN+RIGHT
         ]
     ])
     mob.highlight(self.text_color)
     rectangle = MobjectFromRegion(rectangle, "#111111")
     rectangle.point_thickness = 3
     self.add(rectangle, mob)
     self.dither(time)
     self.remove(mob, rectangle)
示例#19
0
    def construct(self):
        words = TextMobject("Order 2 Pseudo-Hilbert Curve")
        words.to_edge(UP, buff = 0.3)
        words.highlight(GREEN)
        grid2 = Grid(2, 2)
        grid4 = Grid(4, 4, stroke_width = 2)
        # order_1_curve = HilbertCurve(order = 1)
        # squaggle_curve = order_1_curve.copy().apply_function(
        #     lambda (x, y, z) : (x + np.cos(3*y), y + np.sin(3*x), z)
        # )
        # squaggle_curve.show()
        mini_curves = [
            HilbertCurve(order = 1).scale(0.5).shift(1.5*vect)
            for vect in [
                LEFT+DOWN,
                LEFT+UP,
                RIGHT+UP,
                RIGHT+DOWN
            ]
        ]
        last_curve = mini_curves[0]
        naive_curve = Mobject(last_curve)
        for mini_curve in mini_curves[1:]:
            line = Line(last_curve.points[-1], mini_curve.points[0])
            naive_curve.add(line, mini_curve)
            last_curve = mini_curve
        naive_curve.ingest_submobjects()
        naive_curve.gradient_highlight(RED, GREEN)
        order_2_curve = HilbertCurve(order = 2)

        self.add(words, grid2)
        self.dither()
        self.play(ShowCreation(grid4))
        self.play(*[
            ShowCreation(mini_curve)
            for mini_curve in mini_curves
        ])
        self.dither()
        self.play(ShowCreation(naive_curve, run_time = 5))
        self.remove(*mini_curves)
        self.dither()
        self.play(Transform(naive_curve, order_2_curve))
        self.dither()
示例#20
0
    def construct(self):
        logo = ImageMobject("LogoGeneration", invert=False)
        name_mob = TextMobject("3Blue1Brown").center()
        name_mob.highlight("grey")
        name_mob.shift(2 * DOWN)
        self.add(name_mob, logo)

        new_text = TextMobject(["with ", "Steven Strogatz"])
        new_text.next_to(name_mob, DOWN)
        self.play(*[ShimmerIn(part) for part in new_text.split()])
        self.dither()
        with_word, steve = new_text.split()
        steve_copy = steve.copy().center().to_edge(UP)
        # logo.sort_points(lambda p : -np.linalg.norm(p))
        sort_by_color(logo)
        self.play(Transform(steve, steve_copy),
                  DelayByOrder(Transform(logo, Point())),
                  FadeOut(with_word),
                  FadeOut(name_mob),
                  run_time=3)
示例#21
0
    def equivalence(self, left_mob, arrow, right_mob):
        self.clear()
        self.add(left_mob, arrow, right_mob)
        words = TextMobject("is equivalent to")
        words.shift(0.25 * LEFT)
        words.highlight(BLUE)
        new_left = left_mob.copy().shift(RIGHT)
        new_right = right_mob.copy()
        new_right.shift(
            (words.get_right()[0]-\
             right_mob.get_left()[0]+\
             0.5
            )*RIGHT
        )
        for mob in arrow, words:
            mob.sort_points(np.linalg.norm)

        self.play(ApplyMethod(left_mob.shift, RIGHT), Transform(arrow, words),
                  ApplyMethod(right_mob.to_edge, RIGHT))
        self.wait()
示例#22
0
    def equivalence(self, left_mob, arrow, right_mob):
        self.clear()
        self.add(left_mob, arrow, right_mob)
        words = TextMobject("is equivalent to")
        words.shift(0.25*LEFT)
        words.highlight(BLUE)
        new_left = left_mob.copy().shift(RIGHT)
        new_right = right_mob.copy()
        new_right.shift(
            (words.get_right()[0]-\
             right_mob.get_left()[0]+\
             0.5
            )*RIGHT
        )
        for mob in arrow, words:
            mob.sort_points(np.linalg.norm)     

        self.play(
            ApplyMethod(left_mob.shift, RIGHT),
            Transform(arrow, words),
            ApplyMethod(right_mob.to_edge, RIGHT)
        )
        self.dither()
示例#23
0
    def construct(self):
        words = TextMobject("Order 3 Pseudo-Hilbert Curve")
        words.highlight(GREEN)
        words.to_edge(UP)
        grid4 = Mobject(
            Grid(2, 2),
            Grid(4, 4, stroke_width = 2)
        )
        grid8 = Grid(8, 8, stroke_width = 1)
        order_3_curve = HilbertCurve(order = 3)
        mini_curves = [
            HilbertCurve(order = 2).scale(0.5).shift(1.5*vect)
            for vect in [
                LEFT+DOWN,
                LEFT+UP,
                RIGHT+UP,
                RIGHT+DOWN
            ]
        ]

        self.add(words, grid4)
        self.dither()
        self.play(ShowCreation(grid8))
        self.dither()
        self.play(*map(GrowFromCenter, mini_curves))
        self.dither()
        self.clear()
        self.add(words, grid8, *mini_curves)
        self.play(*[
            ApplyMethod(curve.rotate_in_place, np.pi, axis)
            for curve, axis in [
                (mini_curves[0], UP+RIGHT),
                (mini_curves[3], UP+LEFT)
            ]
        ])
        self.play(ShowCreation(order_3_curve, run_time = 5))
        self.dither()
示例#24
0
    def get_corner_numbers(self, value, symbol):
        value_mob = TextMobject(value)
        width = self.get_width()/self.card_width_to_corner_num_width
        height = self.get_height()/self.card_height_to_corner_num_height
        value_mob.scale_to_fit_width(width)
        value_mob.stretch_to_fit_height(height)
        value_mob.next_to(
            self.get_corner(UP+LEFT), DOWN+RIGHT,
            buff = MED_LARGE_BUFF*width
        )
        value_mob.highlight(symbol.get_color())
        corner_symbol = symbol.copy()
        corner_symbol.scale_to_fit_width(width)
        corner_symbol.next_to(
            value_mob, DOWN, 
            buff = MED_SMALL_BUFF*width
        )
        corner_group = VGroup(value_mob, corner_symbol)
        opposite_corner_group = corner_group.copy()
        opposite_corner_group.rotate(
            np.pi, about_point = self.get_center()
        )

        return VGroup(corner_group, opposite_corner_group)
示例#25
0
 def get_author(self, quote):
     author = TextMobject("-" + self.author)
     author.next_to(quote, DOWN)
     author.highlight(YELLOW)
     return author
示例#26
0
    def construct(self):
        morty = Mortimer()
        morty.next_to(ORIGIN, DOWN)

        n_patrons = len(self.specific_patrons)
        special_thanks = TextMobject("Special thanks")
        special_thanks.highlight(YELLOW)
        special_thanks.to_edge(UP)

        patreon_logo = PatreonLogo()
        patreon_logo.next_to(morty, UP, buff = MED_LARGE_BUFF)

        left_patrons = VGroup(*map(TextMobject, 
            self.specific_patrons[:n_patrons/2]
        ))
        right_patrons = VGroup(*map(TextMobject, 
            self.specific_patrons[n_patrons/2:]
        ))
        for patrons in left_patrons, right_patrons:
            patrons.arrange_submobjects(
                DOWN, aligned_edge = LEFT,
                buff = 1.5*MED_SMALL_BUFF
            )

        all_patrons = VGroup(left_patrons, right_patrons)
        all_patrons.scale(self.patron_scale_val)
        for patrons, vect in (left_patrons, LEFT), (right_patrons, RIGHT):
            patrons.to_edge(vect, buff = MED_SMALL_BUFF)
            if patrons.get_height() > 2*SPACE_HEIGHT - LARGE_BUFF:
                patrons.to_edge(UP, buff = MED_SMALL_BUFF)

        shift_distance = max(
            0, (all_patrons.get_height() - 2*SPACE_HEIGHT)
        )
        if shift_distance > 0:
            shift_distance += 1
        velocity = shift_distance/9.0
        def get_shift_anim():
            return ApplyMethod(
                all_patrons.shift, velocity*UP,
                rate_func = None
            )

        self.play(
            morty.change_mode, "gracious",
            DrawBorderThenFill(patreon_logo),
        )
        self.play(Write(special_thanks, run_time = 1))
        self.play(
            Write(left_patrons),
            morty.look_at, left_patrons
        )
        self.play(
            Write(right_patrons),
            morty.look_at, right_patrons
        )
        self.play(Blink(morty), get_shift_anim())
        for patrons in left_patrons, right_patrons:
            for index in 0, -1:
                self.play(
                    morty.look_at, patrons[index],
                    get_shift_anim()
                )
                self.play(get_shift_anim())
示例#27
0
    def construct(self):
        horiz_radius = 5
        vert_radius = 3

        vert_axis = NumberLine(numerical_radius = vert_radius)
        vert_axis.rotate(np.pi/2)
        vert_axis.shift(horiz_radius*LEFT)
        horiz_axis = NumberLine(
            numerical_radius = 5,
            numbers_with_elongated_ticks = []
        )
        axes = Mobject(horiz_axis, vert_axis)
        graph = FunctionGraph(
            lambda x : 0.4*(x-2)*(x+2)+3,
            x_min = -2,
            x_max = 2,
            density = 3*DEFAULT_POINT_DENSITY_1D
        )
        graph.stretch_to_fit_width(2*horiz_radius)
        graph.highlight(YELLOW)
        min_point = Dot(graph.get_bottom())
        nature_finds = TextMobject("Nature finds this point")
        nature_finds.scale(0.5)
        nature_finds.highlight(GREEN)
        nature_finds.shift(2*RIGHT+3*UP)
        arrow = Arrow(
            nature_finds.get_bottom(), min_point, 
            color = GREEN
        )

        side_words_start = TextMobject("Parameter describing")
        top_words, last_side_words = [
            map(TextMobject, pair)
            for pair in [
                ("Light's travel time", "Potential energy"),
                ("path", "mechanical state")
            ]
        ]
        for word in top_words + last_side_words + [side_words_start]:
            word.scale(0.7)
        side_words_start.next_to(horiz_axis, DOWN)
        side_words_start.to_edge(RIGHT)
        for words in top_words:
            words.next_to(vert_axis, UP)
            words.to_edge(LEFT)
        for words in last_side_words:
            words.next_to(side_words_start, DOWN)
        for words in top_words[1], last_side_words[1]:
            words.highlight(RED)

        self.add(
            axes, top_words[0], side_words_start, 
            last_side_words[0]
        )
        self.play(ShowCreation(graph))
        self.play(
            ShimmerIn(nature_finds),
            ShowCreation(arrow),
            ShowCreation(min_point)
        )
        self.dither()
        self.play(
            FadeOut(top_words[0]), 
            FadeOut(last_side_words[0]),
            GrowFromCenter(top_words[1]), 
            GrowFromCenter(last_side_words[1])
        )
        self.dither(3)
示例#28
0
    def construct(self):
        word = TextMobject(["Bra", "chis", "to", "chrone"])
        original_word = word.copy()
        dots = []
        for part in word.split():
            if dots:
                part.next_to(dots[-1], buff = 0.06)
            dot = TexMobject("\\cdot")
            dot.next_to(part, buff = 0.06)
            dots.append(dot)
        dots = Mobject(*dots[:-1])
        dots.shift(0.1*DOWN)
        Mobject(word, dots).center()
        overbrace1 = Brace(Mobject(*word.split()[:-1]), UP)
        overbrace2 = Brace(word.split()[-1], UP)
        shortest = TextMobject("Shortest")
        shortest.next_to(overbrace1, UP)
        shortest.highlight(YELLOW)
        time = TextMobject("Time")
        time.next_to(overbrace2, UP)
        time.highlight(YELLOW)
        chrono_example = TextMobject("""
            As in ``Chronological'' \\\\
            or ``Synchronize''
        """)
        chrono_example.scale(0.5)
        chrono_example.to_edge(RIGHT)
        chrono_example.shift(2*UP)
        chrono_example.highlight(BLUE_D)
        chrono_arrow = Arrow(
            word.get_right(), 
            chrono_example.get_bottom(), 
            color = BLUE_D
        )
        brachy_example = TextMobject("As in . . . brachydactyly?")
        brachy_example.scale(0.5)
        brachy_example.to_edge(LEFT)
        brachy_example.shift(2*DOWN)
        brachy_example.highlight(GREEN)
        brachy_arrow = Arrow(
            word.get_left(),
            brachy_example.get_top(), 
            color = GREEN
        )

        pronunciation = TextMobject(["/br", "e", "kist","e","kr$\\bar{o}$n/"])
        pronunciation.split()[1].rotate_in_place(np.pi)
        pronunciation.split()[3].rotate_in_place(np.pi) 
        pronunciation.scale(0.7)
        pronunciation.shift(DOWN)

        latin = TextMobject(list("Latin"))
        greek = TextMobject(list("Greek"))
        for mob in latin, greek:
            mob.to_edge(LEFT)
        question_mark = TextMobject("?").next_to(greek, buff = 0.1)
        stars = Stars().highlight(BLACK)
        stars.scale(0.5).shift(question_mark.get_center())

        self.play(Transform(original_word, word), ShowCreation(dots))
        self.play(ShimmerIn(pronunciation))
        self.dither()
        self.play(
            GrowFromCenter(overbrace1),
            GrowFromCenter(overbrace2)
        )
        self.dither()
        self.play(ShimmerIn(latin))
        self.play(FadeIn(question_mark))
        self.play(Transform(
            latin, greek,
            path_func = counterclockwise_path()
        ))
        self.dither()
        self.play(Transform(question_mark, stars))
        self.remove(stars)
        self.dither()
        self.play(ShimmerIn(shortest))
        self.play(ShimmerIn(time))
        for ex, ar in [(chrono_example, chrono_arrow), (brachy_example, brachy_arrow)]:
            self.play(
                ShowCreation(ar),
                ShimmerIn(ex)
            )
        self.dither()
示例#29
0
文件: light.py 项目: PythonJedi/manim
    def show_equation(self):
        equation = TexMobject([
            "\\left(\\dfrac{1}{\\phantom{v_air}}\\right)",
            "\\sin(\\theta_1)", 
            "=", 
            "\\left(\\dfrac{1}{\\phantom{v_water}}\\right)",
            "\\sin(\\theta_2)"
        ])
        equation.to_corner(UP+RIGHT)
        frac1, sin1, equals, frac2, sin2 = equation.split()
        v_air, v_water = [
            TexMobject("v_{\\text{%s}}"%s, size = "\\Large")
            for s in "air", "water"
        ]
        v_air.next_to(Point(frac1.get_center()), DOWN)
        v_water.next_to(Point(frac2.get_center()), DOWN)
        frac1.add(v_air)
        frac2.add(v_water)
        f1, f2 = [
            TexMobject("F_%d"%d, size = "\\Large") 
            for d in 1, 2
        ]
        f1.next_to(sin1, LEFT)
        f2.next_to(equals, RIGHT)
        sin2_start = sin2.copy().next_to(f2, RIGHT)
        bar1 = TexMobject("\\dfrac{\\qquad}{\\qquad}")
        bar2 = bar1.copy()
        bar1.next_to(sin1, DOWN)
        bar2.next_to(sin2, DOWN)        
        v_air_copy = v_air.copy().next_to(bar1, DOWN)
        v_water_copy = v_water.copy().next_to(bar2, DOWN)
        bars = Mobject(bar1, bar2)
        new_eq = equals.copy().center().shift(bars.get_center())
        snells = TextMobject("Snell's Law")
        snells.highlight(YELLOW)
        snells.shift(new_eq.get_center()[0]*RIGHT)
        snells.shift(UP)

        anims = []
        for mob in f1, sin1, equals, f2, sin2_start:
            anims.append(ShimmerIn(mob))
        self.play(*anims)
        self.dither()
        for f, frac in (f1, frac1), (f2, frac2):
            target = frac.copy().ingest_submobjects()
            also = []
            if f is f2:
                also.append(Transform(sin2_start, sin2))
                sin2 = sin2_start
            self.play(Transform(f, target), *also)
            self.remove(f)
            self.add(frac)
        self.dither()
        self.play(
            FadeOut(frac1),
            FadeOut(frac2),
            Transform(v_air, v_air_copy),
            Transform(v_water, v_water_copy),
            ShowCreation(bars),
            Transform(equals, new_eq)
        )
        self.dither()
        frac1 = Mobject(sin1, bar1, v_air)
        frac2 = Mobject(sin2, bar2, v_water)
        for frac, vect in (frac1, LEFT), (frac2, RIGHT):
            self.play(ApplyMethod(
                frac.next_to, equals, vect
            ))
        self.dither()
        self.play(ShimmerIn(snells))
        self.dither()
示例#30
0
    def construct(self):
        word = TextMobject(["Bra", "chis", "to", "chrone"])
        original_word = word.copy()
        dots = []
        for part in word.split():
            if dots:
                part.next_to(dots[-1], buff=0.06)
            dot = TexMobject("\\cdot")
            dot.next_to(part, buff=0.06)
            dots.append(dot)
        dots = Mobject(*dots[:-1])
        dots.shift(0.1 * DOWN)
        Mobject(word, dots).center()
        overbrace1 = Brace(Mobject(*word.split()[:-1]), UP)
        overbrace2 = Brace(word.split()[-1], UP)
        shortest = TextMobject("Shortest")
        shortest.next_to(overbrace1, UP)
        shortest.highlight(YELLOW)
        time = TextMobject("Time")
        time.next_to(overbrace2, UP)
        time.highlight(YELLOW)
        chrono_example = TextMobject("""
            As in ``Chronological'' \\\\
            or ``Synchronize''
        """)
        chrono_example.scale(0.5)
        chrono_example.to_edge(RIGHT)
        chrono_example.shift(2 * UP)
        chrono_example.highlight(BLUE_D)
        chrono_arrow = Arrow(word.get_right(),
                             chrono_example.get_bottom(),
                             color=BLUE_D)
        brachy_example = TextMobject("As in . . . brachydactyly?")
        brachy_example.scale(0.5)
        brachy_example.to_edge(LEFT)
        brachy_example.shift(2 * DOWN)
        brachy_example.highlight(GREEN)
        brachy_arrow = Arrow(word.get_left(),
                             brachy_example.get_top(),
                             color=GREEN)

        pronunciation = TextMobject(
            ["/br", "e", "kist", "e", "kr$\\bar{o}$n/"])
        pronunciation.split()[1].rotate_in_place(np.pi)
        pronunciation.split()[3].rotate_in_place(np.pi)
        pronunciation.scale(0.7)
        pronunciation.shift(DOWN)

        latin = TextMobject(list("Latin"))
        greek = TextMobject(list("Greek"))
        for mob in latin, greek:
            mob.to_edge(LEFT)
        question_mark = TextMobject("?").next_to(greek, buff=0.1)
        stars = Stars().highlight(BLACK)
        stars.scale(0.5).shift(question_mark.get_center())

        self.play(Transform(original_word, word), ShowCreation(dots))
        self.play(ShimmerIn(pronunciation))
        self.dither()
        self.play(GrowFromCenter(overbrace1), GrowFromCenter(overbrace2))
        self.dither()
        self.play(ShimmerIn(latin))
        self.play(FadeIn(question_mark))
        self.play(Transform(latin, greek, path_func=counterclockwise_path()))
        self.dither()
        self.play(Transform(question_mark, stars))
        self.remove(stars)
        self.dither()
        self.play(ShimmerIn(shortest))
        self.play(ShimmerIn(time))
        for ex, ar in [(chrono_example, chrono_arrow),
                       (brachy_example, brachy_arrow)]:
            self.play(ShowCreation(ar), ShimmerIn(ex))
        self.dither()
示例#31
0
 def get_author(self, quote):
     author = TextMobject("-" + self.author)
     author.next_to(quote, DOWN)
     author.highlight(YELLOW)
     return author