示例#1
0
    def construct(self):
        big_grid_dim = 20.
        small_grid_dim = 6.
        big_grid = Grid(64, 64, height=big_grid_dim, width=big_grid_dim)
        big_grid.to_corner(UP + RIGHT, buff=2)
        small_grid = big_grid.copy()
        small_grid.scale(small_grid_dim / big_grid_dim)
        small_grid.center()
        pixel = MobjectFromRegion(
            region_from_polygon_vertices(
                *0.2 *
                np.array([RIGHT + DOWN, RIGHT + UP, LEFT + UP, LEFT + DOWN])))
        pixel.set_color(WHITE)
        pixel_width = big_grid.width / big_grid.columns
        pixel.scale_to_fit_width(pixel_width)
        pixel.to_corner(UP + RIGHT, buff=2)
        pixel.shift(5 * pixel_width * (2 * LEFT + DOWN))

        freq_line = get_freq_line()
        dot = Dot()
        dot.shift(freq_line.get_center() + 2 * RIGHT)
        string = Line(LEFT, RIGHT, color=GREEN)
        arrow = Arrow(dot, string.get_center())
        vibration_config = {
            "overtones": 1,
            "spatial_period": 2,
        }
        vibration, loud_vibration, quiet_vibration = [
            Vibrate(string.copy(), amplitude=a, **vibration_config)
            for a in [0.5, 1., 0.25]
        ]

        self.add(small_grid)
        self.dither()
        self.play(Transform(small_grid, big_grid))
        self.play(FadeIn(pixel))
        self.dither()
        self.play(FadeOut(small_grid), ShowCreation(freq_line))
        self.remove(small_grid)
        self.play(Transform(pixel, dot), )
        self.dither()
        self.play(ShowCreation(arrow))
        self.play(loud_vibration)
        self.play(TransformAnimations(loud_vibration, quiet_vibration),
                  ApplyMethod(dot.fade, 0.9))
        self.clear()
        self.add(freq_line, dot, arrow)
        self.play(quiet_vibration)
示例#2
0
    def construct(self):
        big_grid_dim = 20.
        small_grid_dim = 6.
        big_grid = Grid(64, 64, height = big_grid_dim, width = big_grid_dim)
        big_grid.to_corner(UP+RIGHT, buff = 2)
        small_grid = big_grid.copy()
        small_grid.scale(small_grid_dim/big_grid_dim)
        small_grid.center()
        pixel = MobjectFromRegion(
            region_from_polygon_vertices(*0.2*np.array([
                RIGHT+DOWN,
                RIGHT+UP,
                LEFT+UP,
                LEFT+DOWN
            ]))
        )
        pixel.set_color(WHITE)
        pixel_width = big_grid.width/big_grid.columns
        pixel.scale_to_fit_width(pixel_width)
        pixel.to_corner(UP+RIGHT, buff = 2)
        pixel.shift(5*pixel_width*(2*LEFT+DOWN))

        freq_line = get_freq_line()
        dot = Dot()
        dot.shift(freq_line.get_center() + 2*RIGHT)
        string = Line(LEFT, RIGHT, color = GREEN)
        arrow = Arrow(dot, string.get_center())
        vibration_config = {
            "overtones"      : 1,
            "spatial_period" : 2,
        }
        vibration, loud_vibration, quiet_vibration = [
            Vibrate(string.copy(), amplitude = a, **vibration_config)
            for a in [0.5, 1., 0.25]
        ]

        self.add(small_grid)
        self.dither()
        self.play(
            Transform(small_grid, big_grid)
        )
        self.play(FadeIn(pixel))
        self.dither()
        self.play(
            FadeOut(small_grid),            
            ShowCreation(freq_line)
        )
        self.remove(small_grid)
        self.play(
            Transform(pixel, dot),
        )
        self.dither()
        self.play(ShowCreation(arrow))
        self.play(loud_vibration)
        self.play(
            TransformAnimations(loud_vibration, quiet_vibration),            
            ApplyMethod(dot.fade, 0.9)
        )
        self.clear()
        self.add(freq_line, dot, arrow)
        self.play(quiet_vibration)