-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscene4.py
More file actions
233 lines (197 loc) · 9.16 KB
/
Copy pathscene4.py
File metadata and controls
233 lines (197 loc) · 9.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
from manim import *
from config import *
from frisbee_base import FrisbeeBaseScene
from custom_mobjects import DashedArrow
# Text.set_default(font="Kaiti") windows
Text.set_default(font="STKaiti")
class scene4(FrisbeeBaseScene):
def construct(self):
'''
# 使用方法
camera_grid = create_camera_grid(self)
self.add(camera_grid)
'''
# 创建一个长方形,宽度为场景宽度,高度为场景高度
'''
rectangle = Rectangle(width=GROUND_WIDTH, height=GROUND_LENGTH, color=BLUE)
dashed_line_up = DashedLine(start=LEFT * GROUND_WIDTH/2 + UP * GROUND_LENGTH*32/100,end=RIGHT * GROUND_WIDTH/2 + UP * GROUND_LENGTH*32/100)
dashed_line_down = DashedLine(start=LEFT * GROUND_WIDTH/2 + DOWN * GROUND_LENGTH*32/100,end=RIGHT * GROUND_WIDTH/2 + DOWN * GROUND_LENGTH*32/100)
Create(rectangle)
Create(dashed_line_up)
Create(dashed_line_down)
shu_ground = VGroup(rectangle,dashed_line_up,dashed_line_down)
'''
# 添加网格作为参考
grid1 = NumberPlane(x_range=[-6, 6], y_range=[-4, 4])
self.add(grid1)
# scene1
rectangle1 = Rectangle(width=GROUND_RATIO * GROUND_LENGTH,height=GROUND_RATIO * GROUND_WIDTH,color=BLUE)
dashed_line_Left = DashedLine(
start = GROUND_RATIO * LEFT * GROUND_LENGTH*32/100 + GROUND_RATIO * UP * GROUND_WIDTH/2,
end = GROUND_RATIO * LEFT * GROUND_LENGTH*32/100 + GROUND_RATIO * DOWN * GROUND_WIDTH/2)
dashed_line_Right = DashedLine(
start = GROUND_RATIO * RIGHT * GROUND_LENGTH*32/100 + GROUND_RATIO * UP * GROUND_WIDTH/2,
end = GROUND_RATIO * RIGHT * GROUND_LENGTH*32/100 + GROUND_RATIO * DOWN * GROUND_WIDTH/2)
self.play(Create(rectangle1))
self.wait(0.5)
self.play(Create(dashed_line_Left),run_time = 0.5)
self.play(Create(dashed_line_Right),run_time = 0.5)
heng_ground = VGroup(rectangle1,dashed_line_Left,dashed_line_Right)
self.play(heng_ground.animate.rotate(-PI/2))
self.play(heng_ground.animate.shift(DOWN * 2))
self.play(heng_ground.animate.scale(2)) # 放大两倍
# scene2: frisbee and handler
attackers = {}
for i in range(2,8):
attackers[i] = self.create_player(i,RED,WHITE)
defender = {}
for i in range(1,8):
defender[i] = self.create_player(i,BLUE,WHITE)
attackers_group = VGroup()
for i in range(3,8):
attackers_group.add(attackers[i])
defenders_group = VGroup()
for i in range(3, 8):
defenders_group.add(defender[i])
frisbee = Circle(radius=FRISBEE_RADIUS,color=WHITE)
handler = self.create_player(1,RED,WHITE)
handler.shift(np.array([0, -2.2, 0]))
frisbee_position = self.get_frisbee_position(handler, RIGHT, frisbee)
frisbee.move_to(frisbee_position)
defender[1].next_to(handler,UL, buff=0.02)
self.play(FadeIn(handler),FadeIn(frisbee),FadeIn(defender[1]))
self.wait(0.5)
# scene3
direction_of_attack = DashedArrow(
start = np.array([-3.5, 2.2, 0]),
end = np.array([-3.5, 3.2, 0]),
color=WHITE,
buff=0,
stroke_width=3,
tip_length=0.2
)
direction_of_attack_label = MathTex("Direction\ of\ attack", font_size=32).next_to(direction_of_attack, RIGHT)
direction_of_attack_label_chinese=Text("进攻方向", font_size=24).next_to(direction_of_attack_label, RIGHT)
# play direction of attack
self.play(Create(direction_of_attack))
self.play(Write(direction_of_attack_label))
self.play(Write(direction_of_attack_label_chinese))
tuli_attackers = Circle(radius=PLAER_RADIUS,color=RED)
tuli_attackers.set_fill(color=RED,opacity=1)
tuli_attackers.set_stroke(color=WHITE, width=2)
tuli_defender = Circle(radius=PLAER_RADIUS,color=BLUE)
tuli_defender.set_fill(color=BLUE,opacity=1)
tuli_defender.set_stroke(color=WHITE, width=2)
tuli_attackers.next_to(direction_of_attack, DOWN)
tuli_defender.next_to(tuli_attackers, DOWN)
attackers_label = MathTex("Attackers", font_size=32).next_to(tuli_attackers, RIGHT)
attackers_label_chinese=Text("进攻方", font_size=24).next_to(attackers_label, RIGHT)
defenders_label = MathTex("Defenders", font_size=32).next_to(tuli_defender, RIGHT)
defenders_label_chinese=Text("防守方", font_size=24).next_to(defenders_label, RIGHT)
# play attackers and defenders label
self.play(Create(tuli_attackers))
self.play(Write(attackers_label))
self.play(Write(attackers_label_chinese))
self.play(Create(tuli_defender))
self.play(Write(defenders_label))
self.play(Write(defenders_label_chinese))
self.wait(2)
self.play(FadeOut(direction_of_attack_label_chinese),FadeOut(attackers_label_chinese),FadeOut(defenders_label_chinese))
# fadeout chinese and transform
tuli_attackers_label_suoxie= MathTex("A", font_size=32).next_to(tuli_attackers, RIGHT)
tuli_defender_label_suoxie= MathTex("D", font_size=32).next_to(tuli_defender, RIGHT)
direction_of_attack_label_suoxie= MathTex("DOA", font_size=32).next_to(direction_of_attack, RIGHT)
self.play(Transform(direction_of_attack_label, direction_of_attack_label_suoxie))
self.play(Transform(attackers_label, tuli_attackers_label_suoxie))
self.play(Transform(defenders_label, tuli_defender_label_suoxie))
legend_group = VGroup(
direction_of_attack,
direction_of_attack_label,
tuli_attackers,
attackers_label,
tuli_defender,
defenders_label
)
legend_bg = SurroundingRectangle(legend_group, color=GREY, fill_opacity=0.1, buff=0.1)
self.play(Create(legend_bg))
legend_with_bg = VGroup(legend_bg, legend_group)
# shift right 1.8
self.play(legend_with_bg.animate.shift(np.array([-1.8, 0, 0])))
legend_with_bg_position=legend_with_bg.get_center()
def update_position(mob):
camera_center = self.camera.frame.get_center()
offset=np.array([legend_with_bg_position[0],legend_with_bg_position[1],0])
mob.move_to(camera_center + offset)
# 添加updater
legend_with_bg.add_updater(update_position)
self.wait(2)
# scene4: attackers and defenders
self.wait(0.5)
# 将2号攻击者移动到handler左边
attackers[2].shift(np.array([-2.5,-1.4,0]))
defender[2].next_to(attackers[2], UR,buff=0.02)
# 显示2号攻击者
self.play(FadeIn(attackers[2]))
self.play(FadeIn(defender[2]))
# 将攻击者排成一竖排,2号距离handler约8-10m,间隔2m
self.position_attackers(handler, attackers, base_distance=1.7, interval=0.6)
self.position_defenders(attackers, defender,offset_x=0.5, offset_y=-0.4, interval=0.8)
self.play(FadeIn(attackers_group))
self.play(FadeIn(defenders_group))
origin_pos_attacker = {}
origin_pos_defender = {}
for i in range(2, 8):
origin_pos_attacker[i] = attackers[i].get_center()
origin_pos_defender[i] = defender[i].get_center()
origin_pos_attacker[1] = handler.get_center()
origin_pos_defender[1] = defender[1].get_center()
arr1=Arrow(
start=origin_pos_attacker[6],
end=np.array([1.5,1,0]),
color=BLUE,
buff=0,
stroke_width=2,
tip_length=0.2
)
arr1_label=MathTex("Fake", font_size=32).next_to(arr1, RIGHT)
self.play(Create(arr1))
self.play(Write(arr1_label))
self.play(FadeOut(arr1_label),FadeOut(arr1))
self.move_multiple_players([
(attackers[6], np.array([1.5,1,0]), False), # 第1个玩家
(defender[6], np.array([1,1.5,0]), False) # 第2个玩家
],
run_time=1.5,
path_type="straight",
is_camera_follow=False
)
self.wait(1)
pos1=attackers[6].get_center()
arr2=Arrow(
start=pos1,
end=np.array([2,3,0]),
color=BLUE,
buff=0,
stroke_width=2,
tip_length=0.2
)
arr2_label=MathTex("Go\ deep", font_size=32).next_to(arr2, RIGHT)
huck_label=MathTex("Huck", font_size=32).next_to(frisbee, RIGHT)
self.play(Create(arr2))
self.play(Write(arr2_label),Write(huck_label))
self.play(FadeOut(arr2_label),FadeOut(arr2),FadeOut(huck_label))
self.fly_frisbee(
frisbee=frisbee,
handler=handler,
target_player=attackers[6],
direction=RIGHT,
defender=defender[6],
target_player_movement=np.array([3,6.5,0]),
defender_movement=np.array([2.5,6,0]),
is_camera_move=True,
vertical_only=True,
flight_type="right",
is_relative=False,
run_time=1.5
)
self.wait(2)