You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
951 B
28 lines
951 B
3 months ago
|
from manim import *
|
||
|
|
||
|
|
||
|
class FollowingGraphCamera(MovingCameraScene):
|
||
|
def construct(self):
|
||
|
self.camera.frame.save_state()
|
||
|
|
||
|
# create the axes and the curve
|
||
|
ax = Axes(x_range=[-1, 10], y_range=[-1, 10])
|
||
|
graph = ax.plot(lambda x: np.sin(x), color=BLUE, x_range=[0, 3 * PI])
|
||
|
|
||
|
# create dots based on the graph
|
||
|
moving_dot = Dot(ax.i2gp(graph.t_min, graph), color=ORANGE)
|
||
|
dot_1 = Dot(ax.i2gp(graph.t_min, graph))
|
||
|
dot_2 = Dot(ax.i2gp(graph.t_max, graph))
|
||
|
|
||
|
self.add(ax, graph, dot_1, dot_2, moving_dot)
|
||
|
self.play(self.camera.frame.animate.scale(0.5).move_to(moving_dot))
|
||
|
|
||
|
def update_curve(mob):
|
||
|
mob.move_to(moving_dot.get_center())
|
||
|
|
||
|
self.camera.frame.add_updater(update_curve)
|
||
|
self.play(MoveAlongPath(moving_dot, graph, rate_func=linear))
|
||
|
self.camera.frame.remove_updater(update_curve)
|
||
|
|
||
|
self.play(Restore(self.camera.frame))
|