Advertisement
NikaGreg

Untitled

Jan 13th, 2023
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.26 KB | None | 0 0
  1. from manim import *
  2. import numpy as np
  3.  
  4. def split_segment(A, B, k):
  5.     N = np.array(
  6.         [
  7.             (A[0] + B[0] * k) / (1 + k),
  8.             (A[1] + B[1] * k) / (1 + k),
  9.             0
  10.         ]
  11.     )
  12.     return N
  13.  
  14. class Mikel(Scene):
  15.     def construct(self):
  16.         A = np.array([-2, -2, 0])
  17.         B = np.array([3, -2, 0])
  18.         C = np.array([0, 3, 0])
  19.  
  20.         kwargs = {"radius": 0.05, "stroke_width": 0.75, "stroke_color": GREY_E, "z_index": 3, "stroke_opacity": 1}
  21.         pA = always_redraw(lambda: Dot(A, **kwargs, fill_color=BLUE))
  22.         pB = always_redraw(lambda: Dot(B, **kwargs, fill_color=BLUE))
  23.         pC = always_redraw(lambda: Dot(C, **kwargs, fill_color=BLUE))
  24.  
  25.         ABC = always_redraw(lambda:
  26.             Polygon(
  27.                 pA.get_center(), pB.get_center(), pC.get_center(), stroke_width = 2, stroke_color = BLUE_B, fill_opacity=0
  28.             )
  29.         )
  30.  
  31.         n = ValueTracker(4)
  32.         m = ValueTracker(1.5)
  33.         k = ValueTracker(0.3)
  34.         pN = always_redraw(lambda:
  35.             Dot(point = split_segment(pA.get_center(), pB.get_center(), n.get_value()), **kwargs, fill_color = GREEN_C)
  36.         )
  37.         pM = always_redraw(lambda:
  38.             Dot(point = split_segment(pB.get_center(), pC.get_center(), m.get_value()), **kwargs, fill_color = GREEN_C)
  39.         )
  40.         pK = always_redraw(lambda:
  41.             Dot(point = split_segment(pA.get_center(), pC.get_center(), k.get_value()), **kwargs, fill_color = GREEN_C)
  42.         )
  43.  
  44.         circ1 = always_redraw(lambda:
  45.             Circle.from_three_points(pA.get_center(), pN.get_center(), pK.get_center(), color = TEAL_C, stroke_width = 1.25)
  46.         )
  47.         circ2 = always_redraw(lambda:
  48.             Circle.from_three_points(pB.get_center(), pN.get_center(), pM.get_center(), color = TEAL_C, stroke_width = 1.25)
  49.         )
  50.         circ3 = always_redraw(lambda:
  51.             Circle.from_three_points(pC.get_center(), pM.get_center(), pK.get_center(), color = TEAL_C, stroke_width = 1.25)
  52.         )
  53.  
  54.        
  55.         self.play(GrowFromCenter(pA), GrowFromCenter(pB), GrowFromCenter(pC), Create(ABC), run_time=2, lag_ratio=0)
  56.         self.wait(0.5)
  57.         self.play(GrowFromCenter(pN), Flash(pN))
  58.         self.play(GrowFromCenter(pM), Flash(pM))
  59.         self.play(GrowFromCenter(pK), Flash(pK))
  60.         self.wait(0.5)
  61.         self.play(Create(circ1), run_time=1.5)
  62.         self.wait(0.5)
  63.         self.play(Create(circ2), run_time=1.5)
  64.         self.wait(0.5)
  65.         self.play(Create(circ3), run_time=1.5)
  66.         self.wait()
  67.         self.play(pC.animate.shift(3*LEFT), rate_func=there_and_back, run_time=4)
  68.         self.wait(0.5)
  69.         self.play(pC.animate.shift(3*RIGHT), rate_func=there_and_back, run_time=4)
  70.         self.wait()
  71.         self.play(
  72.             AnimationGroup(
  73.                 n.animate.set_value(0.5),
  74.                 m.animate.set_value(0.7),
  75.                 k.animate.set_value(3),
  76.                 lag_ratio=0,
  77.                 run_time=4
  78.             )
  79.         )
  80.         self.wait()
  81.  
  82.         inter = always_redraw(lambda:Intersection(circ2, circ3, stroke_opacity=0))
  83.         Z = always_redraw(lambda: Dot(inter.get_corner(LEFT), **kwargs, fill_color = YELLOW))
  84.  
  85.         self.play(GrowFromCenter(Z), Flash(Z))
  86.         self.wait(2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement