Exemple #1
0
    def construct(self):
        glass = Region(lambda x, y : y < 0, color = BLUE_E)
        self.generate_start_and_end_points()
        straight = Line(self.start_point, self.end_point)
        slow = TextMobject("Slow")
        slow.rotate(np.arctan(straight.get_slope()))
        slow.shift(straight.points[int(0.7*straight.get_num_points())])
        slow.shift(0.5*DOWN)
        too_long = TextMobject("Too long")
        too_long.shift(UP)
        air = TextMobject("Air").shift(2*UP)
        water = TextMobject("Water").shift(2*DOWN)

        self.add(glass)
        self.play(GrowFromCenter(air))
        self.play(GrowFromCenter(water))
        self.wait()
        self.remove(air, water)
        ShowMultiplePathsScene.construct(self)
        self.play(
            Transform(self.path, straight)
        )
        self.wait()
        self.play(GrowFromCenter(slow))
        self.wait()
        self.remove(slow)
        self.leftmost.ingest_submobjects()
        self.play(Transform(self.path, self.leftmost, run_time = 3))
        self.wait()
        self.play(ShimmerIn(too_long))
        self.wait()
Exemple #2
0
    def construct(self):
        self.ring_shift_val = 6*RIGHT
        self.slide_kwargs = {
            "rate_func" : there_and_back,
            "run_time" : 5
        }

        self.setup_background()
        rod = Region(
            lambda x, y : (abs(x) < 5) & (abs(y) < 0.05),
            color = GOLD_E
        )
        ring = Arc(
            angle = 11*np.pi/6,
            start_angle = -11*np.pi/12,
            radius = 0.2,
            color = YELLOW
        )
        ring.shift(-self.ring_shift_val/2)
        self.generate_springs(ring)                


        self.add_rod_and_ring(rod, ring)
        self.slide_ring(ring)
        self.wait()
        self.add_springs()
        self.add_force_definitions()
        self.slide_system(ring)
        self.show_horizontal_component(ring)
        self.show_angles(ring)
        self.show_equation()
Exemple #3
0
    def construct(self):
        words = TextMobject([
            "Fermat's principle:", """
            If a beam of light travels
            from point $A$ to $B$, it does so along the 
            fastest path possible.
            """
        ])
        words.split()[0].highlight(BLUE)
        everything = MobjectFromRegion(Region())
        everything.scale(0.9)
        angles = np.apply_along_axis(angle_of_vector, 1, everything.points)
        norms = np.apply_along_axis(np.linalg.norm, 1, everything.points)
        norms -= np.min(norms)
        norms /= np.max(norms)
        alphas = 0.25 + 0.75 * norms * (1 + np.sin(12 * angles)) / 2
        everything.rgbs = alphas.repeat(3).reshape((len(alphas), 3))

        Mobject(everything, words).show()

        everything.sort_points(np.linalg.norm)
        self.add(words)
        self.play(DelayByOrder(FadeIn(everything, run_time=3)),
                  Animation(words))
        self.play(ApplyMethod(everything.highlight, WHITE), )
        self.dither()
Exemple #4
0
    def construct(self):
        glass = Region(lambda x, y: y < 0, color=BLUE_E)
        kwargs = {"density": self.zoom_factor * DEFAULT_POINT_DENSITY_1D}
        top_line = Line(SPACE_HEIGHT * UP + 2 * LEFT, ORIGIN, **kwargs)
        extension = Line(ORIGIN, SPACE_HEIGHT * DOWN + 2 * RIGHT, **kwargs)
        bottom_line = Line(ORIGIN, SPACE_HEIGHT * DOWN + RIGHT, **kwargs)
        path1 = Mobject(top_line, extension)
        path2 = Mobject(top_line, bottom_line)
        for mob in path1, path2:
            mob.ingest_submobjects()
        extension.highlight(RED)
        theta1 = np.arctan(bottom_line.get_slope())
        theta2 = np.arctan(extension.get_slope())
        arc = Arc(theta2 - theta1, start_angle=theta1, radius=2)
        question_mark = TextMobject("$\\theta$?")
        question_mark.shift(arc.get_center() + 0.5 * DOWN + 0.25 * RIGHT)
        wave = self.wavify(path2)
        wave.highlight(YELLOW)
        wave.scale(0.5)

        self.add(glass)
        self.play(ShowCreation(path1))
        self.play(Transform(path1, path2))
        self.wait()
        # self.activate_zooming()
        self.wait()
        self.play(ShowPassingFlash(wave, run_time=3, rate_func=None))
        self.wait()
        self.play(ShowCreation(extension))
        self.play(ShowCreation(arc), ShimmerIn(question_mark))
Exemple #5
0
 def setup_background(self):
     glass = Region(lambda x, y : y < 0, color = BLUE_E)
     self.generate_start_and_end_points()
     point_a = Dot(self.start_point)
     point_b = Dot(self.end_point)
     A = TextMobject("A").next_to(point_a, UP)
     B = TextMobject("B").next_to(point_b, DOWN)
     self.add(glass, point_a, point_b, A, B)
Exemple #6
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()
Exemple #7
0
    def construct(self):
        glass = Region(lambda x, y : y < 0, color = BLUE_E)
        equation = TexMobject("v_{\\text{air}} > v_{\\text{water}}")
        equation.to_edge(UP)
        path = Line(SPACE_WIDTH*LEFT, SPACE_WIDTH*RIGHT)
        path1 = path.copy().shift(2*UP)
        path2 = path.copy().shift(2*DOWN)

        self.add(glass)
        self.play(ShimmerIn(equation))
        self.wait()
        photon_runs = []
        photon_runs.append(self.photon_run_along_path(
            path1, rate_func = lambda t : min(1, 1.2*t)
        ))
        photon_runs.append(self.photon_run_along_path(path2))
        self.play(*photon_runs, **{"run_time" : 2})
        self.wait()
Exemple #8
0
    def construct(self):
        grid = Grid(64, 64)
        space_region = Region()
        space_mobject = MobjectFromRegion(space_region, DARK_GREY)
        curve = PeanoCurve(order = 5).replace(space_mobject)
        line = Line(5*LEFT, 5*RIGHT)
        line.gradient_highlight(curve.start_color, curve.end_color)
        for mob in grid, space_mobject:
            mob.sort_points(np.linalg.norm)
        infinitely = TextMobject("Infinitely")
        detailed = TextMobject("detailed")
        extending = TextMobject("extending")
        detailed.next_to(infinitely, RIGHT)
        extending.next_to(infinitely, RIGHT)
        Mobject(extending, infinitely, detailed).center()
        arrows = Mobject(*[
            Arrow(2*p, 4*p)
            for theta in np.arange(np.pi/6, 2*np.pi, np.pi/3)
            for p in [rotate_vector(RIGHT, theta)]
        ])

        self.add(grid)
        self.wait()
        self.play(Transform(grid, space_mobject, run_time = 5))
        self.remove(grid)
        self.highlight_region(space_region, DARK_GREY)
        self.wait()
        self.add(infinitely, detailed)
        self.wait()
        self.play(DelayByOrder(Transform(detailed, extending)))
        self.play(ShowCreation(arrows))
        self.wait()
        self.clear()
        self.highlight_region(space_region, DARK_GREY)
        self.play(ShowCreation(line))
        self.play(Transform(line, curve, run_time = 5))
Exemple #9
0
    def construct(self):
        glass = Region(lambda x, y : y < 0, color = BLUE_E)
        self.generate_start_and_end_points()
        left = self.start_point[0]*RIGHT
        right = self.end_point[0]*RIGHT
        start_x = interpolate(left, right, 0.2)
        end_x = interpolate(left, right, 1.0)
        left_line = Line(self.start_point, left, color = RED_D)
        right_line = Line(self.end_point, right, color = RED_D)
        h_1, h_2 = map(TexMobject, ["h_1", "h_2"])
        h_1.next_to(left_line, LEFT)
        h_2.next_to(right_line, RIGHT)
        point_a = Dot(self.start_point)
        point_b = Dot(self.end_point)
        A = TextMobject("A").next_to(point_a, UP)
        B = TextMobject("B").next_to(point_b, DOWN)

        x = start_x
        left_brace = Brace(Mobject(Point(left), Point(x)))
        right_brace = Brace(Mobject(Point(x), Point(right)), UP)
        x_mob = TexMobject("x")
        x_mob.next_to(left_brace, DOWN)
        w_minus_x = TexMobject("w-x")
        w_minus_x.next_to(right_brace, UP)
        top_line = Line(self.start_point, x)
        bottom_line = Line(x, self.end_point)
        top_dist = TexMobject("\\sqrt{h_1^2+x^2}")
        top_dist.scale(0.5)
        a = 0.3
        n = top_line.get_num_points()
        point = top_line.points[int(a*n)]
        top_dist.next_to(Point(point), RIGHT, buff = 0.3)
        bottom_dist = TexMobject("\\sqrt{h_2^2+(w-x)^2}")
        bottom_dist.scale(0.5)
        n = bottom_line.get_num_points()
        point = bottom_line.points[int((1-a)*n)]
        bottom_dist.next_to(Point(point), LEFT, buff = 1)

        end_top_line = Line(self.start_point, end_x)
        end_bottom_line = Line(end_x, self.end_point)
        end_brace = Brace(Mobject(Point(left), Point(end_x)))
        end_x_mob = TexMobject("x").next_to(end_brace, DOWN)

        axes = Mobject(
            NumberLine(),
            NumberLine().rotate(np.pi/2).shift(7*LEFT)
        )
        graph = FunctionGraph(
            lambda x : 0.4*(x+1)*(x-3)+4,
            x_min = -2,
            x_max = 4
        )
        graph.highlight(YELLOW)
        Mobject(axes, graph).scale(0.2).to_corner(UP+RIGHT, buff = 1)
        axes.add(TexMobject("x", size = "\\small").next_to(axes, RIGHT))
        axes.add(TextMobject("Travel time", size = "\\small").next_to(
            axes, UP
        ))
        new_graph = graph.copy()
        midpoint = new_graph.points[new_graph.get_num_points()/2]
        new_graph.filter_out(lambda p : p[0] < midpoint[0])
        new_graph.reverse_points()
        pairs_for_end_transform = [
            (mob, mob.copy())
            for mob in top_line, bottom_line, left_brace, x_mob
        ]

        self.add(glass, point_a, point_b, A, B)
        line = Mobject(top_line, bottom_line).ingest_submobjects()
        self.play(ShowCreation(line))
        self.wait()
        self.play(
            GrowFromCenter(left_brace), 
            GrowFromCenter(x_mob)
        )
        self.play(
            GrowFromCenter(right_brace), 
            GrowFromCenter(w_minus_x)
        )
        self.play(ShowCreation(left_line), ShimmerIn(h_1))
        self.play(ShowCreation(right_line), GrowFromCenter(h_2))
        self.play(ShimmerIn(top_dist))
        self.play(GrowFromCenter(bottom_dist))
        self.wait(3)
        self.clear()
        self.add(glass, point_a, point_b, A, B, 
                 top_line, bottom_line, left_brace, x_mob)
        self.play(ShowCreation(axes))
        kwargs = {
            "run_time" : 4,
        }
        self.play(*[
            Transform(*pair, **kwargs)
            for pair in [
                (top_line, end_top_line),
                (bottom_line, end_bottom_line),
                (left_brace, end_brace),
                (x_mob, end_x_mob)
            ]
        ]+[ShowCreation(graph, **kwargs)])
        self.wait()
        self.show_derivatives(graph)
        line = self.show_derivatives(new_graph)
        self.add(line)
        self.play(*[
            Transform(*pair, rate_func = lambda x : 0.3*smooth(x))
            for pair in pairs_for_end_transform
        ])
        self.wait()
Exemple #10
0
 def construct(self):
     water = Region(lambda x, y : y < 0, color = BLUE_E)
     self.add(water)
     self.run_along_paths()
Exemple #11
0
 def create_region(top, color):
     return Region(
         lambda x, y : (y < top) & (y > top-self.layer_thickness),
         color = color
     )