コード例 #1
0
ファイル: pythagorean_proof.py プロジェクト: PythonJedi/manim
 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.set_color_region(region_from_polygon_vertices(
         2*(LEFT+UP), 2*LEFT+DOWN, RIGHT+DOWN, RIGHT+2*UP
     ), color = B_COLOR)
     self.set_color_region(region_from_polygon_vertices(
         RIGHT+DOWN, RIGHT+2*DOWN, 2*RIGHT+2*DOWN, 2*RIGHT+DOWN
     ), color = A_COLOR)
コード例 #3
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.set_color_region(
                 region_from_polygon_vertices(*vertices),
                 color = DARK_BLUE
             )
コード例 #4
0
ファイル: pythagorean_proof.py プロジェクト: PythonJedi/manim
 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
ファイル: pythagorean_proof.py プロジェクト: zhujianing/manim
 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 set_color_triangles(self):
     for mob in self.mobjects:
         if isinstance(mob, Triangle):
             vertices = list(mob.get_vertices())
             for x in range(2):
                 self.set_color_region(
                     region_from_polygon_vertices(*vertices), color=BLUE_D)
                 vertices.reverse()  #silly hack
コード例 #7
0
ファイル: pythagorean_proof.py プロジェクト: zhujianing/manim
 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
コード例 #8
0
ファイル: pythagorean_proof.py プロジェクト: PythonJedi/manim
 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
コード例 #9
0
ファイル: pythagorean_proof.py プロジェクト: zhujianing/manim
 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")
コード例 #10
0
ファイル: pythagorean_proof.py プロジェクト: PythonJedi/manim
 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"
         )
コード例 #11
0
ファイル: pythagorean_proof.py プロジェクト: PythonJedi/manim
 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
     )
コード例 #12
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.wait()
        self.play(Transform(small_grid, big_grid))
        self.play(FadeIn(pixel))
        self.wait()
        self.play(FadeOut(small_grid), ShowCreation(freq_line))
        self.remove(small_grid)
        self.play(Transform(pixel, dot), )
        self.wait()
        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)
コード例 #13
0
 def construct(self, *args):
     DrawCSquareWithAllTraingles.construct(self, *args)
     self.set_color_region(region_from_polygon_vertices(
         *c_square().center().get_vertices()
     ), color = YELLOW)
コード例 #14
0
ファイル: section1.py プロジェクト: GodotMisogi/manim
    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)
コード例 #15
0
ファイル: pythagorean_proof.py プロジェクト: PythonJedi/manim
 def construct(self, *args):
     DrawCSquareWithAllTraingles.construct(self, *args)
     self.highlight_region(region_from_polygon_vertices(
         *c_square().center().get_vertices()
     ), color = YELLOW)