Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class They_See_Me_Rolling(ThreeDScene):
- CONFIG = {
- "t":4,
- "r": 0.4,
- "R": 4,
- "laps":2*2*np.pi
- }
- def they_hating(self,da):
- ball_1 = ParametricSurface(
- lambda u, v: np.array([
- self.r * np.cos(u) * np.cos(v),
- self.r * np.sin(u) * np.cos(v),
- self.r * np.sin(v)
- ]), v_min=0, v_max=TAU / 2, u_min=0, u_max=TAU / 2, checkerboard_colors=[BLUE_D, BLUE_D],
- resolution=(20, 20))
- ball_2 = ParametricSurface(
- lambda u, v: np.array([
- self.r * np.cos(u) * np.cos(v),
- self.r * np.sin(u) * np.cos(v),
- self.r * np.sin(v)
- ]), v_min=TAU / 2, v_max=TAU, u_min=TAU / 2, u_max=TAU, checkerboard_colors=[RED_D, RED_D],
- resolution=(20, 20))
- ball = VGroup(ball_1, ball_2)
- trajectory = ParametricFunction(
- lambda j: np.array([
- self.R*np.cos(self.laps*j*da),
- self.R*np.sin(self.laps*j*da),
- (np.sin(self.R*np.sin(self.laps*j*da)) ** 2 * np.cos(self.R*np.cos(self.laps*j*da)))
- ]), t_min=0, t_max=1, color=BLUE
- )
- ball.rotate(self.t*self.R/self.r*da,[-self.laps*self.R*np.sin(self.laps*da),self.laps*self.R*np.cos(
- self.laps*da),0])
- position_ball = np.array([self.R*np.cos(self.laps*da),
- self.R*np.sin(self.laps*da),
- ((np.sin(self.R*np.sin(self.laps*da))) ** 2 * np.cos(self.R*np.cos(
- self.laps*da)))+self.r ])
- ball.move_to(position_ball)
- group=VGroup(ball,trajectory)
- return group
- def construct(self):
- ball_1 = ParametricSurface(
- lambda u, v: np.array([
- self.r * np.cos(u) * np.cos(v),
- self.r * np.sin(u) * np.cos(v),
- self.r * np.sin(v)
- ]), v_min=0, v_max=TAU / 2, u_min=0, u_max=TAU / 2, checkerboard_colors=[BLUE_D, BLUE_D],
- resolution=(20, 20))
- ball_2 = ParametricSurface(
- lambda u, v: np.array([
- self.r * np.cos(u) * np.cos(v),
- self.r * np.sin(u) * np.cos(v),
- self.r * np.sin(v)
- ]), v_min=TAU / 2, v_max=TAU, u_min=TAU / 2, u_max=TAU, checkerboard_colors=[RED_D, RED_D],
- resolution=(20, 20))
- ball=VGroup(ball_1,ball_2)
- Random_Surface = ParametricSurface(
- lambda u, v: np.array([
- u,
- v,
- np.sin(v) ** 2 * np.cos(u)
- ]), v_min=-1.8*TAU, v_max=TAU, u_min=-1.8*TAU, u_max=TAU, checkerboard_colors=[GREEN_D, GREEN_E],
- resolution=(40, 40))
- ball.move_to([self.R,0,(np.sin(0) ** 2 * np.cos(self.R))+self.r])
- trajectory = ParametricFunction(
- lambda da: np.array([
- 0,0,0
- ]), t_min=0, t_max=1, color=BLUE
- )
- group=VGroup(ball,trajectory)
- def update(iteration,da):
- new_it = self.they_hating(da)
- iteration.become(new_it)
- return iteration
- self.set_camera_orientation(phi=45 * DEGREES, theta=45 * DEGREES, distance=10)
- self.begin_ambient_camera_rotation(rate=0.1)
- self.play(GrowFromCenter(ball),ShowCreation(Random_Surface))
- self.wait()
- self.play(UpdateFromAlphaFunc(group,update),run_time=self.t, rate_func=linear)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement