Skip to content

Commit 496d908

Browse files
committed
Small alignment cleanups for ch 2, 3, 4, 5, 8
1 parent 6b38a04 commit 496d908

15 files changed

Lines changed: 261 additions & 167 deletions

File tree

Chapter2/Scene7.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ def construct(self):
3636
self.play(Write(bullet))
3737
self.wait(0.5)
3838

39-
self.wait(2)
40-
self.play(FadeOut(summary))
39+
self.play(FadeOut(summary))
4140

4241
with self.voiceover(
4342
"""In the next chapter, we'll explore masking and put together

Chapter3/Scene1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def construct(self):
3939
formatter_style="dracula",
4040
).scale(0.7).next_to(title, DOWN, buff=0.5)
4141
self.play(Write(syntax))
42-
self.wait(2)
43-
self.play(FadeOut(syntax))
42+
43+
self.play(FadeOut(syntax))
4444

4545
# Create input vector v (frontier at node 0) - vertical column vector
4646
v_data = [[1], [0], [0], [0], [0], [0]]

Chapter4/Scene1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ def construct(self):
3737
], v_buff=0.6, h_buff=0.6).scale(0.5)
3838

3939
# Small graph below the adjacency matrix
40-
a_graph = create_small_graph_from_matrix(A_adj_data, scale=0.35, directed=False, edge_color=BLUE)
41-
a_col = VGroup(a_mat, a_graph).arrange(DOWN, buff=0.2)
40+
a_graph = create_small_graph_from_matrix(A_adj_data, scale=0.6, directed=False, edge_color=BLUE)
41+
a_col = VGroup(a_mat, a_graph).arrange(DOWN, buff=0.25)
4242

4343
equals_1 = MathTex("=").scale(0.8)
4444
result_1 = create_sparse_matrix([[0], [1], [1], [0]], scale=0.5)

Chapter4/Scene2.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ def construct(self):
4141
["", "1", "1", ""],
4242
], v_buff=0.6, h_buff=0.6).scale(0.4)
4343
a_label_1 = MathTex("A").scale(0.7)
44-
a_graph_1 = create_small_graph_from_matrix(A_adj_data, scale=0.3, directed=False, edge_color=BLUE)
45-
a_col_1 = VGroup(a_label_1, a_mat_1, a_graph_1).arrange(DOWN, buff=0.15)
44+
a_graph_1 = create_small_graph_from_matrix(A_adj_data, scale=0.5, directed=False, edge_color=BLUE)
45+
a_col_1 = VGroup(a_label_1, a_mat_1, a_graph_1).arrange(DOWN, buff=0.2)
4646

4747
times_2 = MathTex(r"\times").scale(0.8)
4848

@@ -53,8 +53,8 @@ def construct(self):
5353
["", "1", "1", ""],
5454
], v_buff=0.6, h_buff=0.6).scale(0.4)
5555
a_label_2 = MathTex("A").scale(0.7)
56-
a_graph_2 = create_small_graph_from_matrix(A_adj_data, scale=0.3, directed=False, edge_color=BLUE)
57-
a_col_2 = VGroup(a_label_2, a_mat_2, a_graph_2).arrange(DOWN, buff=0.15)
56+
a_graph_2 = create_small_graph_from_matrix(A_adj_data, scale=0.5, directed=False, edge_color=BLUE)
57+
a_col_2 = VGroup(a_label_2, a_mat_2, a_graph_2).arrange(DOWN, buff=0.2)
5858

5959
equals_2 = MathTex("=").scale(0.8)
6060

@@ -66,17 +66,17 @@ def construct(self):
6666
["2", "", "", "2"],
6767
], v_buff=0.6, h_buff=0.6).scale(0.4)
6868
a2_label = MathTex("A^2").scale(0.7)
69-
a2_graph = create_small_graph_from_matrix(A2_adj_data, scale=0.3, directed=False, edge_color=YELLOW)
70-
a2_col = VGroup(a2_label, a2_mat, a2_graph).arrange(DOWN, buff=0.15)
69+
a2_graph = create_small_graph_from_matrix(A2_adj_data, scale=0.5, directed=False, edge_color=YELLOW)
70+
a2_col = VGroup(a2_label, a2_mat, a2_graph).arrange(DOWN, buff=0.2)
7171

7272
mxm_eq = VGroup(
7373
a_col_1,
7474
times_2,
7575
a_col_2,
7676
equals_2,
7777
a2_col
78-
).arrange(RIGHT, buff=0.3)
79-
mxm_eq.next_to(mxm_title, DOWN, buff=0.4)
78+
).arrange(RIGHT, buff=0.4)
79+
mxm_eq.next_to(mxm_title, DOWN, buff=0.5)
8080

8181
label_mxm = Text("2-hop paths", font_size=24, color=YELLOW).next_to(mxm_eq, DOWN, buff=0.3)
8282

Chapter4/Scene3.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ def construct(self):
4343
B_mat = create_sparse_matrix(B_data, scale=0.5)
4444

4545
# Create small graphs below matrices
46-
A_graph = create_small_graph_from_matrix(A_data, scale=0.28, directed=True, edge_color=BLUE)
47-
B_graph = create_small_graph_from_matrix(B_data, scale=0.28, directed=True, edge_color=BLUE)
46+
A_graph = create_small_graph_from_matrix(A_data, scale=0.45, directed=True, edge_color=BLUE)
47+
B_graph = create_small_graph_from_matrix(B_data, scale=0.45, directed=True, edge_color=BLUE)
4848

4949
A_label = MathTex("A").scale(0.8)
5050
B_label = MathTex("B").scale(0.8)
@@ -63,12 +63,12 @@ def construct(self):
6363
], scale=0.5)
6464

6565
# Create empty graph for C (just vertices, no edges)
66-
C_graph_group = self.create_empty_graph(scale=0.28)
66+
C_graph_group = self.create_empty_graph(scale=0.45)
6767

6868
# Arrange with graphs below matrices
69-
A_col = VGroup(A_label, A_mat, A_graph).arrange(DOWN, buff=0.15)
70-
B_col = VGroup(B_label, B_mat, B_graph).arrange(DOWN, buff=0.15)
71-
C_col = VGroup(C_label.copy(), C_initial, C_graph_group).arrange(DOWN, buff=0.15)
69+
A_col = VGroup(A_label, A_mat, A_graph).arrange(DOWN, buff=0.2)
70+
B_col = VGroup(B_label, B_mat, B_graph).arrange(DOWN, buff=0.2)
71+
C_col = VGroup(C_label.copy(), C_initial, C_graph_group).arrange(DOWN, buff=0.2)
7272

7373
# Arrange equation
7474
equation = VGroup(

Chapter4/Scene5.py

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ def construct(self):
5050
]
5151

5252
# Create graph
53-
graph = self.create_graph()
54-
graph.to_edge(RIGHT, buff=1.5)
53+
graph = self.create_graph().scale(0.7)
54+
graph.next_to(title, DOWN, buff=0.3)
5555

5656
with self.voiceover(
5757
"""Consider this graph. Node zero connects to node one. Node one
@@ -66,20 +66,6 @@ def construct(self):
6666
# R_0 = A (direct connections)
6767
R0_data = A_data
6868

69-
R0_mat = create_sparse_matrix(R0_data, scale=0.32, v_buff=0.55, h_buff=0.55)
70-
R0_label = MathTex("R_0 = A").scale(0.6)
71-
R0_small_graph = create_small_graph_from_matrix(R0_data, scale=0.22, directed=False, edge_color=BLUE)
72-
R0_desc = Text("Direct edges", font_size=16, color=GRAY)
73-
R0_group = VGroup(R0_label, R0_mat, R0_small_graph, R0_desc).arrange(DOWN, buff=0.1).to_edge(LEFT, buff=0.8).shift(UP * 1.5)
74-
75-
with self.voiceover(
76-
"""We compute transitive closure iteratively. Start with R-zero
77-
equal to A, the direct connections. Then repeatedly add new
78-
reachable pairs by multiplying."""
79-
):
80-
self.play(Write(R0_group))
81-
self.wait(1)
82-
8369
# R_1 = R_0 | (A @ R_0) - adds 2-hop connections
8470
# Union of direct and 2-hop paths
8571
R1_data = [
@@ -90,21 +76,6 @@ def construct(self):
9076
[0, 0, 1, 1, 1], # 4 can reach 2,3,4
9177
]
9278

93-
R1_mat = create_sparse_matrix(R1_data, scale=0.32, v_buff=0.55, h_buff=0.55)
94-
R1_label = MathTex(r"R_1 = R_0 \cup (A \times R_0)").scale(0.5)
95-
R1_small_graph = create_small_graph_from_matrix(R1_data, scale=0.22, directed=False, edge_color=GREEN)
96-
R1_desc = Text("+ 2-hop paths", font_size=16, color=GREEN)
97-
R1_group = VGroup(R1_label, R1_mat, R1_small_graph, R1_desc).arrange(DOWN, buff=0.1).next_to(R0_group, DOWN, buff=0.3)
98-
99-
with self.voiceover(
100-
"""R-one equals R-zero union A times R-zero. This adds all
101-
two-hop paths to our reachability. Notice how the matrix
102-
fills in as new pairs become connected."""
103-
):
104-
self.play(Write(R1_group))
105-
# Highlight new entries that appeared
106-
self.wait(1)
107-
10879
# R_2 = R_1 | (A @ R_1) - converges (all pairs now reachable)
10980
R2_data = [
11081
[1, 1, 1, 1, 1], # 0 can reach all
@@ -114,11 +85,44 @@ def construct(self):
11485
[1, 1, 1, 1, 1], # 4 can reach all
11586
]
11687

88+
R0_mat = create_sparse_matrix(R0_data, scale=0.32, v_buff=0.55, h_buff=0.55)
89+
R0_label = MathTex("R_0 = A").scale(0.6)
90+
R0_small_graph = create_small_graph_from_matrix(R0_data, scale=0.45, directed=False, edge_color=BLUE)
91+
R0_desc = Text("Direct edges", font_size=16, color=GRAY)
92+
R0_group = VGroup(R0_label, R0_mat, R0_small_graph, R0_desc).arrange(DOWN, buff=0.15)
93+
94+
R1_mat = create_sparse_matrix(R1_data, scale=0.32, v_buff=0.55, h_buff=0.55)
95+
R1_label = MathTex(r"R_1 = R_0 \cup (A \times R_0)").scale(0.5)
96+
R1_small_graph = create_small_graph_from_matrix(R1_data, scale=0.45, directed=False, edge_color=GREEN)
97+
R1_desc = Text("+ 2-hop paths", font_size=16, color=GREEN)
98+
R1_group = VGroup(R1_label, R1_mat, R1_small_graph, R1_desc).arrange(DOWN, buff=0.15)
99+
117100
R2_mat = create_sparse_matrix(R2_data, scale=0.32, v_buff=0.55, h_buff=0.55)
118101
R2_label = MathTex(r"R_2 = R_1 \cup (A \times R_1)").scale(0.5)
119-
R2_small_graph = create_small_graph_from_matrix(R2_data, scale=0.22, directed=False, edge_color=YELLOW)
102+
R2_small_graph = create_small_graph_from_matrix(R2_data, scale=0.45, directed=False, edge_color=YELLOW)
120103
R2_desc = Text("Fixed point", font_size=16, color=YELLOW)
121-
R2_group = VGroup(R2_label, R2_mat, R2_small_graph, R2_desc).arrange(DOWN, buff=0.1).next_to(R1_group, DOWN, buff=0.3)
104+
R2_group = VGroup(R2_label, R2_mat, R2_small_graph, R2_desc).arrange(DOWN, buff=0.15)
105+
106+
# Arrange the three iteration groups in a horizontal row below the chain graph
107+
r_row = VGroup(R0_group, R1_group, R2_group).arrange(RIGHT, buff=0.6, aligned_edge=UP)
108+
r_row.next_to(graph, DOWN, buff=0.4)
109+
110+
with self.voiceover(
111+
"""We compute transitive closure iteratively. Start with R-zero
112+
equal to A, the direct connections. Then repeatedly add new
113+
reachable pairs by multiplying."""
114+
):
115+
self.play(Write(R0_group))
116+
self.wait(1)
117+
118+
with self.voiceover(
119+
"""R-one equals R-zero union A times R-zero. This adds all
120+
two-hop paths to our reachability. Notice how the matrix
121+
fills in as new pairs become connected."""
122+
):
123+
self.play(Write(R1_group))
124+
# Highlight new entries that appeared
125+
self.wait(1)
122126

123127
with self.voiceover(
124128
"""After another iteration, R-two fills completely. Every node

0 commit comments

Comments
 (0)