Files
dsProject/dsLightRag/Manim/Demos/Skeleton/Skeleton_20250804_084910_884.py
2025-08-14 15:45:08 +08:00

113 lines
3.3 KiB
Python

# -*- coding: utf-8 -*-.py
# -*- coding: utf-8 -*-
from manim import *
import numpy as np
class Skeleton(Scene):
# 定义坐标轴范围常量
X_MIN = -3.5 * PI
X_MAX = 3.5 * PI
Y_MIN = -1.5
Y_MAX = 1.5
def construct(self):
# 创建主标题文本
main_title = Text(
"东师理想数学动画AI制作平台作品",
font_size=60,
color=WHITE
)
# 创建副标题文本
sub_title = Text(
"正弦与余弦的关系",
font_size=36,
color=BLUE
).next_to(main_title, DOWN, buff=0.5)
# 标题组
title_group = VGroup(main_title, sub_title)
# 淡入动画(2秒)
self.play(FadeIn(title_group), run_time=2)
# 停留(3秒)
self.wait(3)
# 淡出动画(2秒)
self.play(FadeOut(title_group), run_time=2)
# 清屏(1秒)
self.wait(1)
# 创建坐标系
axes = Axes(
x_range=[self.X_MIN, self.X_MAX, PI/2],
y_range=[self.Y_MIN, self.Y_MAX, 0.5],
axis_config={
"color": WHITE,
"include_tip": True, # 包含箭头
"include_numbers": False
},
x_length=13,
y_length=6
)
# 坐标系居中显示
axes.center()
# 坐标轴淡入动画(1秒)
self.play(Create(axes), run_time=1)
# 创建正弦函数图像,绿色
sin_graph = axes.plot(lambda x: np.sin(x), color=GREEN)
# 曲线从左到右扫出动画(3秒)
self.play(Create(sin_graph), run_time=3)
# 在(-3π,1)位置添加sin(x)标签
sin_label = MathTex(r"\sin(x)", color=GREEN).scale(0.8)
sin_label.next_to(axes.c2p(-3*PI, 1), UP, buff=0.1)
self.play(Write(sin_label), run_time=1)
# 停留展示(2秒)
self.wait(2)
# 淡出所有元素(3秒)
graph_group = VGroup(axes, sin_graph, sin_label)
self.play(FadeOut(graph_group), run_time=3)
# 结束等待(1秒)
self.wait(1)
if __name__ == "__main__":
# 导入必要的模块
import sys
import os
from manim import *
from manim.utils.rate_functions import ease_in_out_sine
# 设置 UTF-8 编码
os.environ['PYTHONIOENCODING'] = 'utf-8'
sys.stdout.reconfigure(encoding='utf-8')
sys.stderr.reconfigure(encoding='utf-8')
# 全局指定 ctex 模板(一次性)
config.tex_template = TexTemplateLibrary.ctex
# 设置输出格式为MP4
config.output_format = "mp4"
# 设置输出目录
config.media_dir = "./output/"
# 使用临时配置渲染场景(配置只在with块内有效)
with tempconfig({
"quality": "high_quality",
"background_color": BLACK,
"preview": True,
"pixel_height": 1080,
"pixel_width": 1920,
"frame_rate": 30
}):
# 实例化场景类
scene = Skeleton()
# 执行渲染流程(包含文件生成和预览)
scene.render()