Advertisement
NikaGreg

Untitled

Jun 13th, 2023
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.59 KB | None | 0 0
  1. class ConicSection(ThreeDScene):
  2.     def construct(self):
  3.         # Заголовки
  4.         Text.set_default(font = 'TT Firs Neue')
  5.         h1 = Text('Поговорим про объемы', color = YELLOW).scale(0.8).to_edge(UL, buff=0.5)
  6.         h2 = Text(
  7.             "Принцип Кавальери"
  8.         ).scale(0.65).next_to(h1, DOWN, aligned_edge=LEFT, buff = 0.3)
  9.  
  10.         self.add_fixed_in_frame_mobjects(h1, h2)
  11.         self.remove(h2)
  12.         # конус
  13.         r = 2  # высота и радиус основания конуса
  14.         cone = Cone(r, r).set_fill(BLUE, 1)
  15.         cone.next_to(ORIGIN, OUT, buff=0).shift(2.5 * DOWN)
  16.         #
  17.         plane = Square(2 * r + 1).set_fill(TEAL, 0).set_stroke(opacity = 0).shift(2.5 * DOWN)
  18.         circle = Circle(r).set_stroke(YELLOW, 3).set_fill(YELLOW, 0.2).shift(2.5 * DOWN)
  19.  
  20.         area_circ = circle.copy()
  21.         area_circ.to_edge(DL)
  22.         tex_c = always_redraw(lambda:
  23.             MathTex("S_1").move_to(circle.get_center()).add_background_rectangle(color = BLACK)
  24.         )
  25.         self.add_fixed_in_frame_mobjects(area_circ, tex_c)
  26.         self.remove(area_circ, tex_c)
  27.  
  28.  
  29.         def upd_circle(circ):
  30.             height = plane.get_center()[2]
  31.             circ.move_to(height * OUT + 2.5 * DOWN)
  32.             new_radius = r - height
  33.             circ.set(width=2*new_radius)
  34.  
  35.         def upd_area_circ(circ):
  36.             height = plane.get_center()[2]
  37.             circ.to_edge(DL)
  38.             new_radius = r - height
  39.             circ.set(width=2*new_radius)
  40.  
  41.  
  42.         circle.add_updater(upd_circle)
  43.         area_circ.add_updater(upd_area_circ)
  44.  
  45.         # пирамида
  46.         h = np.sqrt(4 * PI)/2
  47.         c = Dot(radius=0.00001).move_to(plane.get_center()[2])
  48.         vertex_coords = [
  49.             [r, r, c.get_center()[2]],
  50.             [r, -r, c.get_center()[2]],
  51.             [-r, -r, c.get_center()[2]],
  52.             [-r, r, c.get_center()[2]],
  53.             [0, 0, 2]
  54.         ]
  55.         faces_list = [
  56.             [0, 1, 4],
  57.             [1, 2, 4],
  58.             [2, 3, 4],
  59.             [3, 0, 4],
  60.             [0, 1, 2, 3]
  61.         ]
  62.         pyramid = Polyhedron(
  63.             vertex_coords, faces_list
  64.         ).next_to(ORIGIN, OUT, buff=0).set_stroke(WHITE, 2.5).shift(2.5 * UP)
  65.         pyramid.graph.set_opacity(0)
  66.  
  67.  
  68.         plane_2 = Square(
  69.             4 * h + 1
  70.         ).set_fill(TEAL, 0).next_to(c.get_center()[2], OUT, buff=0).set_stroke(opacity = 0)
  71.         square = Square(
  72.             2 * r
  73.         ).set_stroke(PURPLE_A, 3).set_fill(PURPLE_A, 0.2).next_to(c.get_center()[2], OUT, buff=0).shift(0.1 * OUT + 2.5 * UP)
  74.  
  75.         cons = MathTex("=").next_to(area_circ, RIGHT, buff = 0.2)
  76.         cons.add_updater(lambda obj: obj.next_to(area_circ, RIGHT, buff = 0.2))
  77.  
  78.         self.add_fixed_in_frame_mobjects(cons)
  79.         self.remove(cons)
  80.  
  81.         area_squar = square.copy()
  82.         area_squar.next_to(cons, RIGHT, buff = 0.2)
  83.         tex_c2 = MathTex("S_2").move_to(square.get_center()).add_background_rectangle(color = BLACK)
  84.         self.add_fixed_in_frame_mobjects(area_squar, tex_c, tex_c2)
  85.         self.remove(area_squar, tex_c, tex_c2)
  86.  
  87.         tex_c2.add_updater(lambda obj: obj.move_to(area_squar.get_center()))
  88.  
  89.         # апдейтеры
  90.         def upd_square(squar):
  91.             height = plane_2.get_center()[2]
  92.             squar.move_to(height * OUT + 2.5 * UP)
  93.             new_lenght = r - height
  94.             squar.set(width = 2 * new_lenght).shift(0.1 * OUT)
  95.        
  96.         def upd_area_square(squar):
  97.             height = plane_2.get_center()[2]
  98.             squar.next_to(cons, RIGHT, buff = 0.2)
  99.             new_lenght = r - height
  100.             squar.set(width = 2 * new_lenght).shift(0.1 * OUT)
  101.  
  102.         square.add_updater(upd_square)
  103.         area_squar.add_updater(upd_area_square)
  104.  
  105.         big_plane = Rectangle(
  106.             height = 12, width = 8
  107.         ).set_fill(TEAL, 0.4).set_stroke(TEAL_A, 0).move_to(plane.get_center() + 3 * UP)
  108.  
  109.         # камера
  110.         self.set_camera_orientation(
  111.             phi= 70 * DEGREES,
  112.             theta = 20 * DEGREES,
  113.             zoom = 0.9
  114.         )
  115.         # анимации
  116.        
  117.         self.play(FadeIn(h2, shift = RIGHT))
  118.         self.wait()
  119.         self.play(FadeIn(cone, shift = OUT), FadeIn(pyramid, shift = OUT), run_time = 2)
  120.         self.add(c, plane, plane_2)
  121.         self.wait()
  122.         self.play(Create(big_plane), Create(circle), Create(square), run_time = 3)
  123.         self.wait()
  124.         self.play(Write(tex_c), Write(tex_c2))
  125.         # self.play(FadeIn(area_circ), FadeIn(cons), FadeIn(area_squar), Write(tex_c), Write(tex_c2))
  126.         self.wait()
  127.         self.play(
  128.             plane.animate.shift(0.6 * OUT),
  129.             plane_2.animate.shift(0.6 * OUT),
  130.             big_plane.animate.shift(0.6 * OUT),
  131.             run_time=5
  132.         )
  133.         self.wait()
  134.         self.play(
  135.             plane.animate.shift(0.6 * OUT),
  136.             plane_2.animate.shift(0.6 * OUT),
  137.             big_plane.animate.shift(0.6 * OUT),
  138.             run_time=6
  139.         )
  140.         self.wait()
  141.         self.play(
  142.             plane.animate.shift(0.5 * OUT),
  143.             plane_2.animate.shift(0.5 * OUT),
  144.             big_plane.animate.shift(0.5 * OUT),
  145.             run_time=7
  146.         )
  147.         self.wait()
  148.         # выыод
  149.         conclusion = MathTex(
  150.             r"\Rightarrow", "V_1 = V_2"
  151.         ).next_to(area_squar, RIGHT, buff = 0.2)
  152.  
  153.         self.add_fixed_in_frame_mobjects(conclusion)
  154.         self.remove(conclusion)
  155.  
  156.         self.play(Write(conclusion), run_time = 2.5)
  157.         self.wait()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement