Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 6, 2024
1 parent 1020144 commit c8cebcc
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 62 deletions.
78 changes: 40 additions & 38 deletions example_scenes/triangle-prove1.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from manim import *
import numpy as np


# 定义一个名为TriangleAnglesSum的类,它继承自Scene类,用于构建特定的动画场景
class TriangleAnglesSum(Scene):
Expand All @@ -22,24 +22,32 @@ def construct(self):
for i, point in enumerate(vertices):
# 根据索引创建对应的顶点标签文本,字体大小为36
# 通过计算使标签位于对应顶点且相对三角形中心有一定偏移的位置
label = Text(["A", "B", "C"][i], font_size=36).next_to(point, point - triangle.get_center())
label = Text(["A", "B", "C"][i], font_size=36).next_to(
point, point - triangle.get_center()
)
labels.append(label)

# 设置角度相关的一些参数(这里角度用扇形来大致表示,设置扇形半径等属性)
angle_radius = 0.4 # 扇形半径,用于控制表示角的扇形大小
angle_arc_angle = PI / 3 # 扇形的圆心角大小,这里设置为60度(PI/3弧度),可根据实际情况调整
angle_arc_angle = (
PI / 3
) # 扇形的圆心角大小,这里设置为60度(PI/3弧度),可根据实际情况调整
angle_stroke_width = 8 # 扇形边框宽度

# 创建表示角A的扇形对象,指定扇形的圆心、两条半径对应的点以及相关属性
angle_A = Sector(
start_angle=0,
angle=angle_arc_angle,
radius=angle_radius,
stroke_color=YELLOW,
fill_color=YELLOW,
stroke_width=angle_stroke_width,
fill_opacity=0.3 # 设置一定透明度,让效果更美观
).move_arc_center_to(A).rotate(4*PI/3,about_point=A)
angle_A = (
Sector(
start_angle=0,
angle=angle_arc_angle,
radius=angle_radius,
stroke_color=YELLOW,
fill_color=YELLOW,
stroke_width=angle_stroke_width,
fill_opacity=0.3, # 设置一定透明度,让效果更美观
)
.move_arc_center_to(A)
.rotate(4 * PI / 3, about_point=A)
)

# 创建表示角B的扇形对象,指定扇形的圆心、两条半径对应的点以及相关属性
angle_B = Sector(
Expand All @@ -49,19 +57,23 @@ def construct(self):
stroke_color=RED,
fill_color=RED,
stroke_width=angle_stroke_width,
fill_opacity=0.3
fill_opacity=0.3,
).move_arc_center_to(B)

# 创建表示角C的扇形对象,指定扇形的圆心、两条半径对应的点以及相关属性
angle_C = Sector(
start_angle=0,
angle=angle_arc_angle,
radius=angle_radius,
stroke_color=BLUE,
fill_color=BLUE,
stroke_width=angle_stroke_width,
fill_opacity=0.3
).move_arc_center_to(C).rotate(5*PI/3 + PI,about_point=C)
angle_C = (
Sector(
start_angle=0,
angle=angle_arc_angle,
radius=angle_radius,
stroke_color=BLUE,
fill_color=BLUE,
stroke_width=angle_stroke_width,
fill_opacity=0.3,
)
.move_arc_center_to(C)
.rotate(5 * PI / 3 + PI, about_point=C)
)

# 将创建好的三个表示角的扇形对象放入一个列表中,方便后续统一操作
angles = [angle_A, angle_B, angle_C]
Expand Down Expand Up @@ -97,10 +109,7 @@ def construct(self):
copy_angle_A = angle_A.copy()
angle_copies.append(copy_angle_A)
# 播放动画,将复制的角度A对应的扇形移动到目标位置,动画运行时间为1.5秒
self.play(
copy_angle_A.animate.move_to(target_point_A),
run_time=1.5
)
self.play(copy_angle_A.animate.move_to(target_point_A), run_time=1.5)
# 等待0.3秒,让观众看清移动后的效果
self.wait(0.3)

Expand All @@ -109,10 +118,7 @@ def construct(self):
copy_angle_B = angle_B.copy()
angle_copies.append(copy_angle_B)
# 播放动画,将复制的角度B对应的扇形移动到目标位置并旋转PI弧度(即180度),动画运行时间为1.5秒
self.play(
copy_angle_B.animate.move_to(target_point_B).rotate(PI),
run_time=1.5
)
self.play(copy_angle_B.animate.move_to(target_point_B).rotate(PI), run_time=1.5)
# 等待0.3秒,让观众看清移动和旋转后的效果
self.wait(0.3)

Expand All @@ -121,10 +127,7 @@ def construct(self):
copy_angle_C = angle_C.copy()
angle_copies.append(copy_angle_C)
# 播放动画,将复制的角度C对应的扇形移动到目标位置并旋转PI弧度(即180度),动画运行时间为1.5秒
self.play(
copy_angle_C.animate.move_to(target_point_C).rotate(PI),
run_time=1.5
)
self.play(copy_angle_C.animate.move_to(target_point_C).rotate(PI), run_time=1.5)
# 等待0.3秒,让观众看清移动和旋转后的效果
self.wait(0.3)

Expand All @@ -135,7 +138,7 @@ def construct(self):
line = Line(
bottom_line_center + LEFT * (total_width / 2) + UP * 0.52,
bottom_line_center + RIGHT * (total_width / 2) + UP * 0.52,
color=WHITE
color=WHITE,
)
# 播放创建直线的动画,将直线添加到场景中
self.play(Create(line))
Expand All @@ -149,8 +152,7 @@ def construct(self):
# 添加闪烁效果
# 对每个角度扇形副本添加闪烁指示效果,通过缩放来实现闪烁,动画运行时间为1秒
self.play(
*[Indicate(copy, scale_factor=1.2) for copy in angle_copies],
run_time=1
*[Indicate(copy, scale_factor=1.2) for copy in angle_copies], run_time=1
)

# 添加总结文字
Expand All @@ -170,4 +172,4 @@ def construct(self):
# 创建TriangleAnglesSum类的实例,即创建一个具体的动画场景对象
scene = TriangleAnglesSum()
# 调用render方法来渲染动画场景,生成对应的动画视频等输出内容
scene.render()
scene.render()
39 changes: 15 additions & 24 deletions example_scenes/triangle-prove2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from manim import *
import numpy as np

from manim import *


class TriangleParallelProof(Scene):
def construct(self):
Expand All @@ -18,30 +19,23 @@ def construct(self):
# 为顶点添加标签
labels = []
for i, point in enumerate(vertices):
label = Text(["A", "B", "C"][i], font_size=36).next_to(point, point - triangle.get_center())
label = Text(["A", "B", "C"][i], font_size=36).next_to(
point, point - triangle.get_center()
)
labels.append(label)

# 创建三个内角
angle_radius = 0.4
angle_A = Angle(
Line(A, B), Line(A, C),
radius=angle_radius,
color=YELLOW,
stroke_width=8
Line(A, B), Line(A, C), radius=angle_radius, color=YELLOW, stroke_width=8
)

angle_B = Angle(
Line(B, C), Line(B, A),
radius=angle_radius,
color=RED,
stroke_width=8
Line(B, C), Line(B, A), radius=angle_radius, color=RED, stroke_width=8
)

angle_C = Angle(
Line(C, A), Line(C, B),
radius=angle_radius,
color=BLUE,
stroke_width=8
Line(C, A), Line(C, B), radius=angle_radius, color=BLUE, stroke_width=8
)

# 显示三角形和标签
Expand All @@ -63,11 +57,7 @@ def construct(self):
parallel_end = A + RIGHT * 2

# 创建平行线
parallel_line = Line(
parallel_start,
parallel_end,
color=WHITE
).move_to(A)
parallel_line = Line(parallel_start, parallel_end, color=WHITE).move_to(A)

# 旋转平行线使其平行于BC
angle_to_rotate = np.arctan2(bc_vector[1], bc_vector[0])
Expand All @@ -77,7 +67,9 @@ def construct(self):
self.play(Create(parallel_line))

# 调整平行线标注的位置
parallel_text = Text("平行于BC", font_size=24).next_to(parallel_line, UP, buff=0.85) # 增加 buff 值
parallel_text = Text("平行于BC", font_size=24).next_to(
parallel_line, UP, buff=0.85
) # 增加 buff 值
self.play(Write(parallel_text))
self.wait()

Expand All @@ -88,7 +80,7 @@ def construct(self):
Line(A, B),
radius=angle_radius,
color=RED,
stroke_width=8
stroke_width=8,
)

# 与角C对应的内错角
Expand All @@ -98,7 +90,7 @@ def construct(self):
radius=angle_radius,
color=BLUE,
stroke_width=8,
other_angle=True
other_angle=True,
)

# 显示内错角
Expand Down Expand Up @@ -126,11 +118,10 @@ def construct(self):
conclusion.to_edge(UP)
self.play(Write(conclusion))


self.wait(2)


if __name__ == "__main__":
with tempconfig({"quality": "medium_quality", "preview": True}):
scene = TriangleParallelProof()
scene.render()
scene.render()

0 comments on commit c8cebcc

Please sign in to comment.