示例#1
0
 def construct(self):
     ShowRearrangementInBigSquare.construct(self)
     self.highlight_region(region_from_polygon_vertices(
         2 * (LEFT + UP), 2 * LEFT + DOWN, RIGHT + DOWN, RIGHT + 2 * UP),
                           color=B_COLOR)
     self.highlight_region(region_from_polygon_vertices(
         RIGHT + DOWN, RIGHT + 2 * DOWN, 2 * RIGHT + 2 * DOWN,
         2 * RIGHT + DOWN),
                           color=A_COLOR)
示例#2
0
 def construct(self):
     ShowRearrangementInBigSquare.construct(self)
     self.highlight_region(
         region_from_polygon_vertices(2 * (LEFT + UP), 2 * LEFT + DOWN, RIGHT + DOWN, RIGHT + 2 * UP), color=B_COLOR
     )
     self.highlight_region(
         region_from_polygon_vertices(RIGHT + DOWN, RIGHT + 2 * DOWN, 2 * RIGHT + 2 * DOWN, 2 * RIGHT + DOWN),
         color=A_COLOR,
     )
示例#3
0
 def highlight_triangles(self):
     for mob in self.mobjects:
         if isinstance(mob, Triangle):
             vertices = list(mob.get_vertices())
             for x in range(2):
                 self.highlight_region(region_from_polygon_vertices(*vertices), color=DARK_BLUE)
                 vertices.reverse()  # silly hack
示例#4
0
 def construct(self, num, fill):
     DrawAllThreeSquares.construct(self)
     pairs = [
         ((0, 2, 0), (1, -1, 0)),
         ((-3, -1, 0), (0, -2, 0)),
         ((4, -1, 0), (1, -2, 0)),
         ((0, -2, 0), (-3, -1, 0)),
         ((1, -2, 0), (4, -1, 0)),
         ((1, -1, 0), (4, 0, 0)),
         ((4, 0, 0), (3, 3, 0)),
         ((3, 3, 0), (0, 2, 0)),
         ((-3, 3, 0), (0, 2, 0)),
         ((0, 2, 0), (-3, 3, 0)),
     ]
     to_flip = [1, 3, 8, 9]
     for n in range(num):
         triangle = Triangle()
         if n in to_flip:
             triangle.rotate(np.pi, UP)
         self.add(triangle.place_hypotenuse_on(*pairs[n]))
         vertices = list(triangle.get_vertices())
         if n not in to_flip:
             vertices.reverse()
         if fill:
             self.highlight_region(region_from_polygon_vertices(*vertices), color=DARK_BLUE)
示例#5
0
 def construct(self, *args):
     DrawAllThreeSquaresWithMoreTriangles.construct(self, *args)
     args_list = [(10, False)]
     color = Color("yellow")
     color.set_rgb(0.3 * np.array(color.get_rgb()))
     self.highlight_region(region_from_polygon_vertices((-3, 3), (-3, -2),
                                                        (4, -2), (4, 3)),
                           color=color)
示例#6
0
 def highlight_triangles(self):
     for mob in self.mobjects:
         if isinstance(mob, Triangle):
             vertices = list(mob.get_vertices())
             for x in range(2):
                 self.highlight_region(
                     region_from_polygon_vertices(*vertices),
                     color=DARK_BLUE)
                 vertices.reverse()  #silly hack
示例#7
0
 def construct(self, *args):
     AddParallelLines.construct(self, *args)
     triplets = [
         [(0, 2), (0, -1), (1, -1)],
         [(1, -1), (4, -1), (4, 0)],
         [(4, 0), (4, 3), (3, 3)],
         [(3, 3), (0, 3), (0, 2)],
     ]
     for triplet in triplets:
         self.highlight_region(region_from_polygon_vertices(*triplet), color="DARK_BLUE")
示例#8
0
 def construct(self, *args):
     AddParallelLines.construct(self, *args)
     triplets = [
         [(0, 2), (0, -1), (1, -1)],
         [(1, -1), (4, -1), (4, 0)],
         [(4, 0), (4, 3), (3, 3)],
         [(3, 3), (0, 3), (0, 2)],
     ]
     for triplet in triplets:
         self.highlight_region(region_from_polygon_vertices(*triplet),
                               color="DARK_BLUE")
示例#9
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)
示例#10
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)
示例#11
0
 def construct(self, num, fill):
     DrawAllThreeSquares.construct(self)
     pairs = [((0, 2, 0), (1, -1, 0)), ((-3, -1, 0), (0, -2, 0)),
              ((4, -1, 0), (1, -2, 0)), ((0, -2, 0), (-3, -1, 0)),
              ((1, -2, 0), (4, -1, 0)), ((1, -1, 0), (4, 0, 0)),
              ((4, 0, 0), (3, 3, 0)), ((3, 3, 0), (0, 2, 0)),
              ((-3, 3, 0), (0, 2, 0)), ((0, 2, 0), (-3, 3, 0))]
     to_flip = [1, 3, 8, 9]
     for n in range(num):
         triangle = Triangle()
         if n in to_flip:
             triangle.rotate(np.pi, UP)
         self.add(triangle.place_hypotenuse_on(*pairs[n]))
         vertices = list(triangle.get_vertices())
         if n not in to_flip:
             vertices.reverse()
         if fill:
             self.highlight_region(region_from_polygon_vertices(*vertices),
                                   color=DARK_BLUE)
示例#12
0
 def construct(self, *args):
     DrawCSquareWithAllTraingles.construct(self, *args)
     self.highlight_region(region_from_polygon_vertices(*c_square().center().get_vertices()), color=YELLOW)
示例#13
0
 def construct(self, *args):
     DrawAllThreeSquaresWithMoreTriangles.construct(self, *args)
     args_list = [(10, False)]
     color = Color("yellow")
     color.set_rgb(0.3 * np.array(color.get_rgb()))
     self.highlight_region(region_from_polygon_vertices((-3, 3), (-3, -2), (4, -2), (4, 3)), color=color)
示例#14
0
 def construct(self, *args):
     DrawCSquareWithAllTraingles.construct(self, *args)
     self.highlight_region(
         region_from_polygon_vertices(*c_square().center().get_vertices()),
         color=YELLOW)
示例#15
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)