gt22

Untitled

Mar 2nd, 2019
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.25 KB | None | 0 0
  1. from big_ol_pile_of_manim_imports import *
  2.  
  3.  
  4. class MainScene(Scene):
  5.     SL = 3
  6.     scale_matrix = np.identity(2) * SL
  7.     matrix = np.array([
  8.         [0, 1],
  9.         [1, 0]
  10.     ]).T
  11.  
  12.     def construct(self):
  13.         plane = self.make_plane()
  14.         x_label, t_label = self.make_labels(plane)
  15.  
  16.         box = self.make_box()
  17.         self.wait(0.5)
  18.         lines = self.make_lines()
  19.         objects = [plane, *lines]
  20.         x_label_t = x_label.copy().next_to((4, 0, 0), DL)
  21.         self.play(*[ApplyMatrix(self.matrix, m, run_time=1) for m in objects] + [Transform(x_label, x_label_t)])
  22.         self.wait(3)
  23.  
  24.     def make_plane(self):
  25.         plane = NumberPlane(background_line_style={
  26.             "stroke_opacity": 0.5
  27.         })
  28.  
  29.         self.add(plane)
  30.         self.play(ShowCreation(plane, run_time=0.5))
  31.         return plane
  32.  
  33.     def make_labels(self, plane):
  34.         x_label = plane.get_x_axis_label("x")
  35.         t_label = plane.get_y_axis_label("t")
  36.         self.add(x_label, t_label)
  37.         self.play(FadeIn(x_label), FadeIn(t_label))
  38.         return x_label, t_label
  39.  
  40.     def make_box(self):
  41.         box = Square(side_length=1, color=GREY)
  42.         box.scale(self.SL)
  43.         box.move_to((self.SL / 2, self.SL / 2, 0))
  44.         self.add(box)
  45.         self.play(ShowCreation(box, run_time=0.5))
  46.         return box
  47.  
  48.     def make_lines(self):
  49.         lines_data = [
  50.             {
  51.                 'color': GREEN,
  52.                 'coords': [(0, 0, 0), (1, 0.2, 0)]
  53.             },
  54.             {
  55.                 'color': GREEN,
  56.                 'coords': [(1, 0.2, 0), (0, 0.4, 0)]
  57.             },
  58.             {
  59.                 'color': GREEN,
  60.                 'coords': [(0, 0.4, 0), (1, 0.6, 0)]
  61.             },
  62.             {
  63.                 'color': GREEN,
  64.                 'coords': [(1, 0.6, 0), (0, 0.8, 0)]
  65.             },
  66.             {
  67.                 'color': GREEN,
  68.                 'coords': [(0, 0.8, 0), (1, 1, 0)]
  69.             }
  70.         ]
  71.         lines = []
  72.         for ld in lines_data:
  73.             l = Line(*(np.array(ld['coords']) * self.SL), stroke_color=ld['color'])
  74.             lines.append(l)
  75.             self.add(l)
  76.             self.play(ShowCreation(l, run_time=1 / len(lines_data)))
  77.  
  78.         return lines
Advertisement
Add Comment
Please, Sign In to add comment