Advertisement
Guest User

Rolling in the deep

a guest
Jul 23rd, 2019
466
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.48 KB | None | 0 0
  1. class They_See_Me_Rolling(ThreeDScene):
  2.     CONFIG = {
  3.         "t":4,
  4.         "r": 0.4,
  5.         "R": 4,
  6.         "laps":2*2*np.pi
  7.     }
  8.  
  9.     def they_hating(self,da):
  10.  
  11.  
  12.         ball_1 = ParametricSurface(
  13.             lambda u, v: np.array([
  14.                 self.r * np.cos(u) * np.cos(v),
  15.                 self.r * np.sin(u) * np.cos(v),
  16.                 self.r * np.sin(v)
  17.             ]), v_min=0, v_max=TAU / 2, u_min=0, u_max=TAU / 2, checkerboard_colors=[BLUE_D, BLUE_D],
  18.             resolution=(20, 20))
  19.         ball_2 = ParametricSurface(
  20.             lambda u, v: np.array([
  21.                 self.r * np.cos(u) * np.cos(v),
  22.                 self.r * np.sin(u) * np.cos(v),
  23.                 self.r * np.sin(v)
  24.             ]), v_min=TAU / 2, v_max=TAU, u_min=TAU / 2, u_max=TAU, checkerboard_colors=[RED_D, RED_D],
  25.             resolution=(20, 20))
  26.  
  27.         ball = VGroup(ball_1, ball_2)
  28.  
  29.         trajectory = ParametricFunction(
  30.             lambda j: np.array([
  31.                 self.R*np.cos(self.laps*j*da),
  32.                 self.R*np.sin(self.laps*j*da),
  33.                 (np.sin(self.R*np.sin(self.laps*j*da)) ** 2 * np.cos(self.R*np.cos(self.laps*j*da)))
  34.             ]), t_min=0, t_max=1, color=BLUE
  35.         )
  36.  
  37.         ball.rotate(self.t*self.R/self.r*da,[-self.laps*self.R*np.sin(self.laps*da),self.laps*self.R*np.cos(
  38.             self.laps*da),0])
  39.  
  40.         position_ball = np.array([self.R*np.cos(self.laps*da),
  41.                 self.R*np.sin(self.laps*da),
  42.                 ((np.sin(self.R*np.sin(self.laps*da))) ** 2 * np.cos(self.R*np.cos(
  43.                     self.laps*da)))+self.r ])
  44.  
  45.         ball.move_to(position_ball)
  46.         group=VGroup(ball,trajectory)
  47.  
  48.         return group
  49.  
  50.     def construct(self):
  51.  
  52.  
  53.         ball_1 = ParametricSurface(
  54.             lambda u, v: np.array([
  55.                 self.r * np.cos(u) * np.cos(v),
  56.                 self.r * np.sin(u) * np.cos(v),
  57.                 self.r * np.sin(v)
  58.             ]), v_min=0, v_max=TAU / 2, u_min=0, u_max=TAU / 2, checkerboard_colors=[BLUE_D, BLUE_D],
  59.             resolution=(20, 20))
  60.         ball_2 = ParametricSurface(
  61.             lambda u, v: np.array([
  62.                 self.r * np.cos(u) * np.cos(v),
  63.                 self.r * np.sin(u) * np.cos(v),
  64.                 self.r * np.sin(v)
  65.             ]), v_min=TAU / 2, v_max=TAU, u_min=TAU / 2, u_max=TAU, checkerboard_colors=[RED_D, RED_D],
  66.             resolution=(20, 20))
  67.  
  68.         ball=VGroup(ball_1,ball_2)
  69.  
  70.         Random_Surface = ParametricSurface(
  71.             lambda u, v: np.array([
  72.                 u,
  73.                 v,
  74.                 np.sin(v) ** 2 * np.cos(u)
  75.             ]), v_min=-1.8*TAU, v_max=TAU, u_min=-1.8*TAU, u_max=TAU, checkerboard_colors=[GREEN_D, GREEN_E],
  76.             resolution=(40, 40))
  77.  
  78.         ball.move_to([self.R,0,(np.sin(0) ** 2 * np.cos(self.R))+self.r])
  79.  
  80.         trajectory = ParametricFunction(
  81.             lambda da: np.array([
  82.                 0,0,0
  83.             ]), t_min=0, t_max=1, color=BLUE
  84.         )
  85.  
  86.         group=VGroup(ball,trajectory)
  87.  
  88.  
  89.  
  90.         def update(iteration,da):
  91.             new_it = self.they_hating(da)
  92.             iteration.become(new_it)
  93.             return iteration
  94.  
  95.         self.set_camera_orientation(phi=45 * DEGREES, theta=45 * DEGREES, distance=10)
  96.         self.begin_ambient_camera_rotation(rate=0.1)
  97.  
  98.         self.play(GrowFromCenter(ball),ShowCreation(Random_Surface))
  99.         self.wait()
  100.         self.play(UpdateFromAlphaFunc(group,update),run_time=self.t, rate_func=linear)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement