-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
126 lines (117 loc) · 5.11 KB
/
main.py
File metadata and controls
126 lines (117 loc) · 5.11 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
from manim import * # type: ignore
from manim.animation.composition import DEFAULT_LAGGED_START_LAG_RATIO
import math
class ExampleGame(Scene):
def construct(self):
dots = [
Dot((-1.5, 0, 0), DEFAULT_DOT_RADIUS * 1.5, color=BLUE),
Dot((1.5, 0, 0), DEFAULT_DOT_RADIUS * 1.5, color=BLUE),
Dot((0.0, (3 * math.sqrt(2) / 2) - 1.5, 0), DEFAULT_DOT_RADIUS * 1.5, color=BLUE),
Dot((-3, 0, 0), DEFAULT_DOT_RADIUS * 1.5, color=BLUE),
Dot((-1, 1.385, 0), DEFAULT_DOT_RADIUS * 1.5, color=BLUE),
Dot((1.1, 0.75, 0), DEFAULT_DOT_RADIUS * 1.5, color=BLUE),
Dot((1.68, 0.56, 0), DEFAULT_DOT_RADIUS * 1.5, color=BLUE),
]
lines = [
Line(dots[0].get_center(), dots[1].get_center(), path_arc=-PI / 2).set_z_index(dots[0].z_index - 1),
Circle(0.75, color=WHITE).next_to(dots[0].get_center(), LEFT, buff=0.0).set_z_index(dots[0].z_index - 1),
Line(dots[3].get_center(), dots[2].get_center(), path_arc=-PI * 0.8).set_z_index(dots[2].z_index - 1),
Line(dots[4].get_center(), dots[1].get_center(), color=RED_D, path_arc=PI / 2).set_z_index(-10),
Line(dots[4].get_center(), dots[1].get_center(), path_arc=-PI / 2).set_z_index(dots[1].z_index - 1),
Line(dots[5].get_center(), dots[1].get_center(), path_arc=-PI).set_z_index(dots[1].z_index - 1),
]
player1_label = Text('Player 1', font_size=26).to_edge(RIGHT, buff=0.8).shift(UP * 0.2)
player2_label = Text('Player 2', font_size=26).to_edge(RIGHT, buff=0.8).shift(DOWN * 0.2)
indicator = MathTex(r'\gtrdot', font_size=28, color=YELLOW).next_to(player1_label, LEFT, buff=0.15)
self.wait(1)
self.play(LaggedStart(
GrowFromCenter(dots[0], rate_func=rate_functions.ease_out_back),
GrowFromCenter(dots[1], rate_func=rate_functions.ease_out_back),
run_time=0.5,
lag_ratio=DEFAULT_LAGGED_START_LAG_RATIO * 5
))
self.play(Write(player1_label), Write(player2_label))
self.play(Write(indicator))
self.wait(0.5)
self.play(Create(lines[0]))
self.play(Create(dots[2]))
self.wait(0.5)
self.play(
indicator.animate.next_to(player2_label, LEFT, buff=0.15),
Create(lines[1])
)
self.play(Create(dots[3]))
sprouts_game = VGroup(*dots[:4] + lines[:2] + [player1_label, player2_label, indicator])
self.play(sprouts_game.animate.scale(3).shift(RIGHT * 7.6395))
self.wait(0.2)
labels = [
Tex('1', color=GREEN).next_to(dots[0], LEFT + UP, 0.2),
Tex('2', color=GREEN).next_to(dots[0], LEFT + DOWN, 0.2),
Tex('3', color=RED).next_to(dots[0], RIGHT, 0.4),
]
self.play(LaggedStart(
Write(labels[0]), Write(labels[1]), Write(labels[2]),
lag_ratio=DEFAULT_LAGGED_START_LAG_RATIO * 7.5
), run_time=2)
self.play(LaggedStart(
labels[1].animate.set_color(RED), labels[0].animate.set_color(RED), # type: ignore
lag_ratio=DEFAULT_LAGGED_START_LAG_RATIO * 10
), run_time=4/3)
cross = VGroup(
Line((-1, -1, 0), (1.0, 1, 0), stroke_width=20, color=RED_D),
Line((-1, 1, 0), (1, -1, 0), stroke_width=20, color=RED_D),
).scale(1.2).move_to(ORIGIN)
self.play(
Uncreate(labels[0]), Uncreate(labels[1]), Uncreate(labels[2]),
Create(cross),
dots[0].animate.set_color(GREY_D)
)
self.play(Uncreate(cross))
self.play(sprouts_game.animate.scale(1 / 3).shift(LEFT * 7.6395))
self.wait(0.5)
self.play(
indicator.animate.next_to(player1_label, LEFT, buff=0.15),
dots[3].animate.set_color(GREY_D),
Create(lines[2])
)
self.play(
dots[2].animate.set_color(GREY_D),
Create(dots[4])
)
self.play(
indicator.animate.next_to(player2_label, LEFT, buff=0.15),
dots[4].animate.set_color(GREY_D),
Create(lines[3])
)
self.wait(0.3)
self.play(Uncreate(lines[3]))
self.play(Create(lines[4]))
self.play(Create(dots[5]))
self.play(
indicator.animate.next_to(player1_label, LEFT, buff=0.15),
dots[5].animate.set_color(GREY_D),
Create(lines[5])
)
self.play(
dots[1].animate.set_color(GREY_D),
Create(dots[6])
)
self.wait(0.5)
self.play(
dots[3].animate.set_color(RED_D),
dots[6].animate.set_color(RED_D)
)
self.wait(0.4)
self.play(
dots[3].animate.set_color(GREY_D),
dots[6].animate.set_color(GREY_D)
)
self.wait(2)
sprouts_game = VGroup(*dots + lines)
text = VGroup(player1_label, player2_label, indicator)
title = Text('Sprouts', color=YELLOW).scale(1.5).move_to(ORIGIN)
self.play(
Unwrite(text, run_time=1),
Transform(sprouts_game, title, run_time=3),
)
self.wait(0.5)