Spawz

Manim Reddit Help Post

Jul 1st, 2024
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. from manim import *
  2. from numpy import sin, cos
  3. import random
  4.  
  5. #Variables
  6. chaos_num = 10
  7. fly_speed = 8
  8. time = [0,5,7,8,10]
  9.  
  10. #Random Variables
  11. A = [random.random()*0.5 for ii in range(chaos_num)]
  12. B = [random.random()*0.5 for ii in range(chaos_num)]
  13. Omega = [random.random()*fly_speed for ii in range(chaos_num)]
  14. Phi = [random.random()*2*PI for ii in range(chaos_num)]
  15. Psi = [random.random()*2*PI for ii in range(chaos_num)]
  16.  
  17. def Fly_Path(t):
  18. x = sum([a*cos(w*t+phi) for a,w,phi in zip(A,Omega,Phi)])
  19. y = sum([b*sin(w*t+psi) for b,w,psi in zip(B,Omega,Psi)])
  20.  
  21. return(x,y,0)
  22.  
  23. class AnimateAxis(Scene):
  24. def construct(self):
  25. ## COLOR
  26. self.camera.background_color = "#fff9ae"
  27.  
  28. ## THE ASSETS
  29. #
  30. def Fly_Path_N(start,end):
  31. return ParametricFunction(Fly_Path,
  32. t_range=[start, end],
  33. fill_opacity=0,
  34. color = RED)
  35.  
  36. #Define Fly Paths
  37. fly_path1 = Fly_Path_N(time[0],time[1])
  38. fly_path2 = Fly_Path_N(time[1],time[2])
  39. fly_path3 = Fly_Path_N(time[2],time[3])
  40. fly_path4 = Fly_Path_N(time[3],time[4])
  41.  
  42. #Define Axes
  43. ceiling_axis = Axes(
  44. x_range=[0, 5, 1],
  45. y_range=[0, 5, 1],
  46. tips=False,
  47. axis_config={"include_numbers": False,
  48. "include_ticks": False,
  49. "color": BLACK},
  50. x_length=5,
  51. y_length=5
  52. )
  53.  
  54. #Define Ticks
  55. ceiling_ticks = Axes(
  56. x_range=[0, 5, 1],
  57. y_range=[0, 5, 1],
  58. tips=False,
  59. axis_config={"include_numbers": False,
  60. "color": BLACK},
  61. x_length=5,
  62. y_length=5
  63. )
  64.  
  65.  
  66. ## THE ANIMATION ##
  67. #Fly Appears
  68. self.play(Create(fly_path1),
  69. run_time = time[1],
  70. rate_func=linear)
  71.  
  72. #Axis Appears
  73. self.play(Create(fly_path2),
  74. Create(ceiling_axis),
  75. rate_func=linear,
  76. run_time = time[2]-time[1])
  77.  
  78. #Ticks Appear
  79. self.play(Create(fly_path3),
  80. DrawBorderThenFill(ceiling_ticks),
  81. rate_func=linear,
  82. run_time = time[3]-time[2])
  83.  
  84. #Fly Keeps Flying
  85. self.play(Create(fly_path4),
  86. rate_func=linear,
  87. run_time = time[4]-time[3])
  88.  
  89.  
  90. self.wait(5) # Wait for 1 second at the end
  91.  
  92.  
Advertisement
Add Comment
Please, Sign In to add comment