Manim 一元二次方程函数图像动画制作教程
以下是一个使用 Manim 编写的一元二次方程函数图像的视频代码示例:
from manim import *
class QuadraticGraph(Scene):
def construct(self):
# 创建坐标轴
axes = Axes(
x_range=(-5, 5, 1),
y_range=(-10, 10, 1),
x_length=10,
y_length=6,
axis_config={'color': WHITE},
x_axis_config={'numbers_to_include': range(-5, 6)},
y_axis_config={'numbers_to_include': range(-10, 11)},
)
self.play(Create(axes))
# 创建函数图像
graph = axes.get_graph(lambda x: x**2, color=BLUE)
self.play(Create(graph))
# 添加标签
label = axes.get_graph_label(graph, label='y = x^2')
self.play(Create(label))
self.wait(2)
# 移动视角
self.play(
axes.animate.to_corner(UL),
graph.animate.scale(0.5).to_corner(UR),
label.animate.next_to(graph, RIGHT),
)
self.wait()
# 添加顶点
vertex = Dot().move_to(graph.points[0])
self.play(Create(vertex))
self.wait(2)
# 移动顶点
self.play(
vertex.animate.move_to(graph.points[-1]),
rate_func=there_and_back,
run_time=3,
)
self.wait()
self.play(FadeOut(vertex))
self.wait()
self.play(FadeOut(label), FadeOut(graph))
self.wait()
if __name__ == '__main__':
module_name = 'quadratic_graph'
scene_name = 'QuadraticGraph'
command = f'manim -pql {module_name} {scene_name}'
os.system(command)
这个代码会生成一个演示一元二次方程函数图像的视频,其中包括坐标轴、函数图像、函数标签、顶点的动态效果。你可以根据需要进行修改和扩展。
原文地址: http://www.cveoy.top/t/topic/o68m 著作权归作者所有。请勿转载和采集!