example.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. from manimlib import *
  2. class SquareToCircle(Scene):
  3. def construct(self):
  4. circle = Circle()
  5. circle.set_fill(BLUE, opacity=0.5)
  6. circle.set_stroke(BLUE_E, width=4)
  7. square = Square()
  8. self.play(ShowCreation(square))
  9. self.wait()
  10. self.play(ReplacementTransform(square, circle))
  11. self.wait()
  12. # Try typing the following lines
  13. # self.play(circle.animate.stretch(4, dim=0))
  14. # self.play(Rotate(circle, TAU / 4))
  15. # self.play(circle.animate.shift(2 * RIGHT), circle.animate.scale(0.25))
  16. # circle.insert_n_curves(10)
  17. # self.play(circle.animate.apply_complex_function(lambda z: z**2))
  18. class SquareToCircleEmbed(Scene):
  19. def construct(self):
  20. circle = Circle()
  21. circle.set_fill(BLUE, opacity=0.5)
  22. circle.set_stroke(BLUE_E, width=4)
  23. self.add(circle)
  24. self.wait()
  25. self.play(circle.animate.stretch(4, dim=0))
  26. self.wait(1.5)
  27. self.play(Rotate(circle, TAU / 4))
  28. self.wait(1.5)
  29. self.play(circle.animate.shift(2 * RIGHT), circle.animate.scale(0.25))
  30. self.wait(1.5)
  31. circle.insert_n_curves(10)
  32. self.play(circle.animate.apply_complex_function(lambda z: z**2))
  33. self.wait(2)