This commit is contained in:
2025-11-20 23:48:36 +01:00
parent f2436ee44a
commit 45b8ce2119

280
main.py
View File

@@ -25,7 +25,12 @@ class DefaultTemplate(ThreeDScene):
top = Square(color=WHITE, side_length=start_size)
top.shift(shift_pos)
l1 = Square(color=l1_color, side_length=start_size, grid_xstep=start_size/2, grid_ystep=start_size/2)
l1 = Square(
color=l1_color,
side_length=start_size,
grid_xstep=start_size / 2,
grid_ystep=start_size / 2,
)
l1.set_z_index(-1)
l1.shift(shift_pos)
@@ -75,7 +80,13 @@ class DefaultTemplate(ThreeDScene):
for x in [-1, 1]:
text = Text(text=str(i), font_size=int(50 / div))
text.move_to(l1)
text.shift((x*start_size/4/div +offset_x,y*start_size/4/div+offset_y,0))
text.shift(
(
x * start_size / 4 / div + offset_x,
y * start_size / 4 / div + offset_y,
0,
)
)
slots.add(text)
i += 1
return slots
@@ -113,11 +124,19 @@ class DefaultTemplate(ThreeDScene):
sub_nodes_r1[i] = new
for i, n in enumerate(sub_text_r1):
self.play(n.animate.set_color(GRAY_D),l1.animate.set_stroke(opacity=0.5),run_time=0.2)
self.play(
n.animate.set_color(GRAY_D),
l1.animate.set_stroke(opacity=0.5),
run_time=0.2,
)
self.play(p2_node.animate.scale(0.75), p1_node.animate.scale(0.75))
self.play(p1_node.animate.move_to(sub_nodes_r1[1][0]),FadeOut(sub_nodes_r1[1][0]))
self.play(p2_node.animate.move_to(sub_nodes_r1[0][0]),FadeOut(sub_nodes_r1[0][0]))
self.play(
p1_node.animate.move_to(sub_nodes_r1[1][0]), FadeOut(sub_nodes_r1[1][0])
)
self.play(
p2_node.animate.move_to(sub_nodes_r1[0][0]), FadeOut(sub_nodes_r1[0][0])
)
self.play(p2.animate.set_color(GRAY))
p3 = self.add_particle((1, 1, 0), BLUE_C, 0, False)
@@ -131,7 +150,12 @@ class DefaultTemplate(ThreeDScene):
self.play(root_2.animate.move_to(sub_nodes_r1[1][0]))
l2 = Square(color=l2_color, side_length=start_size/2, grid_xstep=start_size/4, grid_ystep=start_size/4)
l2 = Square(
color=l2_color,
side_length=start_size / 2,
grid_xstep=start_size / 4,
grid_ystep=start_size / 4,
)
l2.shift((start_size / 4, start_size / 4, 0))
l2.set_z_index(-2)
l2.shift(shift_pos)
@@ -146,11 +170,19 @@ class DefaultTemplate(ThreeDScene):
sub_nodes_r2[i] = new
for i, n in enumerate(sub_text_r2):
self.play(n.animate.set_color(GRAY_D),l2.animate.set_stroke(opacity=0.5),run_time=0.2)
self.play(
n.animate.set_color(GRAY_D),
l2.animate.set_stroke(opacity=0.5),
run_time=0.2,
)
self.play(p1_node.animate.scale(0.75), p3_node.animate.scale(0.75 * 0.75))
self.play(p1_node.animate.move_to(sub_nodes_r2[0][0]),FadeOut(sub_nodes_r2[0][0]))
self.play(p3_node.animate.move_to(sub_nodes_r2[2][0]),FadeOut(sub_nodes_r2[2][0]))
self.play(
p1_node.animate.move_to(sub_nodes_r2[0][0]), FadeOut(sub_nodes_r2[0][0])
)
self.play(
p3_node.animate.move_to(sub_nodes_r2[2][0]), FadeOut(sub_nodes_r2[2][0])
)
self.play(p3.animate.set_color(GRAY))
p4 = self.add_particle((2, -1.8, 0), BLUE_C, 0, False)
@@ -161,7 +193,9 @@ class DefaultTemplate(ThreeDScene):
self.play(FadeOut(root_1))
root_1 = root_1_1
self.play(p4_node.animate.scale(0.75), p4.animate.set_color(GRAY))
self.play(p4_node.animate.move_to(sub_nodes_r1[3][0]),FadeOut(sub_nodes_r1[3][0]))
self.play(
p4_node.animate.move_to(sub_nodes_r1[3][0]), FadeOut(sub_nodes_r1[3][0])
)
# P5
p5 = self.add_particle((2.5, -2.3, 0), BLUE_C, 0, False)
@@ -175,7 +209,12 @@ class DefaultTemplate(ThreeDScene):
root_2_4 = add_2_nodes(p5_node, p4_node, 44, False, 0.75, color=l2_color)
self.play(root_2_4.animate.move_to(sub_nodes_r1[3][0]))
l3 = Square(color=l2_color, side_length=start_size/2, grid_xstep=start_size/4, grid_ystep=start_size/4)
l3 = Square(
color=l2_color,
side_length=start_size / 2,
grid_xstep=start_size / 4,
grid_ystep=start_size / 4,
)
l3.shift((start_size / 4, -start_size / 4, 0))
l3.set_z_index(-2)
l3.shift(shift_pos)
@@ -192,11 +231,18 @@ class DefaultTemplate(ThreeDScene):
self.play(Transform(new, VGroup(n, arrow)))
sub_nodes_r24[i] = new
self.play(p4_node.animate.move_to(sub_nodes_r24[1][0]),FadeOut(sub_nodes_r24[1][0]))
self.play(
p4_node.animate.move_to(sub_nodes_r24[1][0]), FadeOut(sub_nodes_r24[1][0])
)
self.play(p4_node.animate.scale(0.75), l3.animate.set_stroke(opacity=0.5))
# l4
l4 = Square(color=l3_color, side_length=start_size/4, grid_xstep=start_size/8, grid_ystep=start_size/8)
l4 = Square(
color=l3_color,
side_length=start_size / 4,
grid_xstep=start_size / 8,
grid_ystep=start_size / 8,
)
l4.shift(((start_size / 4) * 1.5, (-start_size / 4) * 1.5, 0))
l4.set_z_index(-3)
l4.shift(shift_pos)
@@ -213,60 +259,108 @@ class DefaultTemplate(ThreeDScene):
self.play(Transform(new, VGroup(n, arrow)))
sub_nodes_r3[i] = new
self.play(p5_node.animate.scale(0.75**3),p4_node.animate.scale(0.75), run_time=0.3)
self.play(p4_node.animate.move_to(sub_nodes_r3[0][0]),FadeOut(sub_nodes_r3[0][0]))
self.play(p5_node.animate.move_to(sub_nodes_r3[3][0]),FadeOut(sub_nodes_r3[3][0]))
self.play(
p5_node.animate.scale(0.75**3), p4_node.animate.scale(0.75), run_time=0.3
)
self.play(
p4_node.animate.move_to(sub_nodes_r3[0][0]), FadeOut(sub_nodes_r3[0][0])
)
self.play(
p5_node.animate.move_to(sub_nodes_r3[3][0]), FadeOut(sub_nodes_r3[3][0])
)
hide_text()
graph = VGroup(p1_node,p2_node,p3_node,p4_node,p5_node,root_1,root_2,root_2_4,root_3,sub_nodes_r1,sub_nodes_r2,sub_nodes_r24,sub_nodes_r3,sub_text_r1,sub_text_r2,sub_text_r24)
self.play(FadeOut(graph),p5.animate.set_color(GRAY))
sub_nodes_r1[0][0] = sub_nodes_r1[0][1]
sub_nodes_r1[1][0] = sub_nodes_r1[1][1]
sub_nodes_r1[3][0] = sub_nodes_r1[3][1]
sub_nodes_r2[0][0] = sub_nodes_r2[0][1]
sub_nodes_r2[2][0] = sub_nodes_r2[2][1]
sub_nodes_r24[1][0] = sub_nodes_r24[1][1]
sub_nodes_r3[0][0] = sub_nodes_r3[0][1]
sub_nodes_r3[3][0] = sub_nodes_r3[3][1]
graph = VGroup(
p1_node,
p2_node,
p3_node,
p4_node,
p5_node,
root_1,
root_2,
root_2_4,
root_3,
sub_nodes_r1,
sub_nodes_r2,
sub_nodes_r24,
sub_nodes_r3,
)
graph.save_state()
self.play(
FadeOut(graph),
p5.animate.set_color(GRAY),
FadeOut(sub_text_r1),
FadeOut(sub_text_r2),
FadeOut(sub_text_r24),
)
v = self.add_particles_and_squares()
self.play(
l1.animate.set_stroke(opacity=1),
l3.animate.set_stroke(opacity=1),
l2.animate.set_stroke(opacity=1),
run_time=0.3,
)
diagram = VGroup(v, top, p1, p2, p3, p4, p5, l1, l2, l3, l4)
self.begin_ambient_camera_rotation(90*DEGREES/3, about='phi')
self.begin_ambient_camera_rotation(90 * DEGREES / 3, about="phi")
self.play(diagram.animate.move_to((0, 0, 0)), run_time=2.5)
diagram.save_state()
self.stop_ambient_camera_rotation(about='phi')
self.stop_ambient_camera_rotation(about="phi")
self.begin_ambient_camera_rotation(360*DEGREES/10.5, about='theta')
self.play(l1.animate.set_stroke(opacity=1),l3.animate.set_stroke(opacity=1),
l2.animate.set_stroke(opacity=1),run_time=0.3)
self.play(top.animate.shift((0,0,2)),l1.animate.shift((0,0,0)),
l2.animate.shift((0,0,0)),l3.animate.shift((0,0,0)),l4.animate.shift((0,0,-1)),
p4.animate.shift((0,0,-2)),p5.animate.shift((0,0,-1)),p2.animate.shift((0,0,-2))
,p1.animate.shift((0,0,-3))
,*[x.animate.shift((0,0,0)) for x in v[0]]
,*[x.animate.shift((0,0,-1)) for x in v[1]],
self.play(
top.animate.shift((0, 0, 2)),
l4.animate.shift((0, 0, -1)),
p4.animate.shift((0, 0, -2)),
p5.animate.shift((0, 0, -1)),
p2.animate.shift((0, 0, -2)),
p1.animate.shift((0, 0, -3)),
*[x.animate.shift((0, 0, 0)) for x in v[0]],
*[x.animate.shift((0, 0, -1)) for x in v[1]],
*[x.animate.shift((0, 0, -2)) for x in v[2]],
*[x.animate.shift((0,0,-3)) for x in v[3]],run_time= 3)
self.wait(2.5)
*[x.animate.shift((0, 0, -3)) for x in v[3]],
run_time=2,
)
self.wait(2.5)
#Undo Movement
self.play(top.animate.shift((0,0,-2)),l1.animate.shift((0,0,0)),
l2.animate.shift((0,0,0)),l3.animate.shift((0,0,0)),l4.animate.shift((0,0,1)),
p4.animate.shift((0,0,2)),p5.animate.shift((0,0,1)),p2.animate.shift((0,0,2))
,p1.animate.shift((0,0,3))
,*[x.animate.shift((0,0,0)) for x in v[0]]
,*[x.animate.shift((0,0,1)) for x in v[1]],
*[x.animate.shift((0,0,2)) for x in v[2]],
*[x.animate.shift((0,0,3)) for x in v[3]],run_time= 2.5)
self.stop_ambient_camera_rotation(about='theta')
self.play(
Rotate(
diagram, angle=360 * DEGREES, rate_func=rate_functions.ease_in_out_cubic
),
run_time=5,
)
self.begin_ambient_camera_rotation(-90*DEGREES/3, about='phi')
self.play(diagram.animate.move_to(shift_pos),run_time=2.5)
self.stop_ambient_camera_rotation(about='phi')
self.wait(4)
self.begin_ambient_camera_rotation(-90 * DEGREES / 3, about="phi")
self.play(Restore(diagram), run_time=2.5)
self.stop_ambient_camera_rotation(about="phi")
self.wait(1)
diagram = diagram[1:]
self.play(FadeOut(v), run_time=0.5)
self.play(Restore(graph), diagram.animate.move_to(shift_pos))
self.wait(3)
return
def create_square(self, color, size, shift_pos, z_index, shift_values):
square = Square(color=color, side_length=size, grid_xstep=size/2, grid_ystep=size/2)
square = Square(
color=color, side_length=size, grid_xstep=size / 2, grid_ystep=size / 2
)
square.shift(shift_values)
square.set_z_index(z_index)
square.shift(shift_pos)
@@ -277,42 +371,107 @@ class DefaultTemplate(ThreeDScene):
t = 0.2
p6 = self.add_particle((-2.7, -2.7, 0), GRAY, t, False)
p7 = self.add_particle((-2.1, -1.1, 0), GRAY, t, False)
l7 = self.create_square(l2_color, start_size / 2, shift_pos, -2, (-start_size / 4, -start_size / 4, 0))
l7 = self.create_square(
l2_color,
start_size / 2,
shift_pos,
-2,
(-start_size / 4, -start_size / 4, 0),
)
p8 = self.add_particle((1.1, 2.7, 0), GRAY, t, False)
l8 = self.create_square(l3_color, start_size / 4, shift_pos, -3, ((start_size / 4) * 0.5, (start_size / 4) * 1.5, 0))
l8 = self.create_square(
l3_color,
start_size / 4,
shift_pos,
-3,
((start_size / 4) * 0.5, (start_size / 4) * 1.5, 0),
)
p9 = self.add_particle((1.67, 1.24, 0), GRAY, t, False)
p11 = self.add_particle((-0.92, 2.12, 0), GRAY, t, False)
l10 = self.create_square(l2_color, start_size / 2, shift_pos, -2, (-start_size / 4, start_size / 4, 0))
l10 = self.create_square(
l2_color,
start_size / 2,
shift_pos,
-2,
(-start_size / 4, start_size / 4, 0),
)
p12 = self.add_particle((1.13, -1.45, 0), GRAY, t, False)
p13 = self.add_particle((-2.48, 0.58, 0), GRAY, t, False)
l12 = self.create_square(l3_color, start_size / 4, shift_pos, -3, (-(start_size / 4) * 1.5, (start_size / 4) * 0.5, 0))
l12 = self.create_square(
l3_color,
start_size / 4,
shift_pos,
-3,
(-(start_size / 4) * 1.5, (start_size / 4) * 0.5, 0),
)
p14 = self.add_particle((0.62, -2.14, 0), GRAY, t, False)
p15 = self.add_particle((2.35, -1.78, 0), GRAY, t, False)
p16 = self.add_particle((-1.61, 0.91, 0), GRAY, t, False)
l16 = self.create_square(l4_color, start_size / 8, shift_pos, -4, (-(start_size / 4) * 1.25, (start_size / 4) * 0.75, 0))
l16 = self.create_square(
l4_color,
start_size / 8,
shift_pos,
-4,
(-(start_size / 4) * 1.25, (start_size / 4) * 0.75, 0),
)
p17 = self.add_particle((-2.35, -0.98, 0), GRAY, t, False)
l17 = self.create_square(l3_color, start_size / 4, shift_pos, -3, (-(start_size / 4) * 1.5, -(start_size / 4) * 0.5, 0))
l17 = self.create_square(
l3_color,
start_size / 4,
shift_pos,
-3,
(-(start_size / 4) * 1.5, -(start_size / 4) * 0.5, 0),
)
p18 = self.add_particle((0.84, 1.95, 0), GRAY, t, False)
l18 = self.create_square(l4_color, start_size / 8, shift_pos, -4, ((start_size / 4) * 0.75, (start_size / 4) * 1.25, 0))
l18 = self.create_square(
l4_color,
start_size / 8,
shift_pos,
-4,
((start_size / 4) * 0.75, (start_size / 4) * 1.25, 0),
)
l19 = self.create_square(l5_color, start_size / 16, shift_pos, -5, ((start_size / 4) * 0.625, (start_size / 4) * 1.375, 0))
l19 = self.create_square(
l5_color,
start_size / 16,
shift_pos,
-5,
((start_size / 4) * 0.625, (start_size / 4) * 1.375, 0),
)
p20 = self.add_particle((0.5, -0.5, 0), GRAY, t, False)
l20 = self.create_square(l3_color, start_size / 4, shift_pos, -3, ((start_size / 4) * 0.5, -(start_size / 4) * 0.5, 0))
l20 = self.create_square(
l3_color,
start_size / 4,
shift_pos,
-3,
((start_size / 4) * 0.5, -(start_size / 4) * 0.5, 0),
)
p21 = self.add_particle((-1.8, 1.4, 0), GRAY, t, False)
p22 = self.add_particle((1.5, -2.0, 0), GRAY, t, False)
l22 = self.create_square(l4_color, start_size / 8, shift_pos, -4, ((start_size / 4) * 1.25, -(start_size / 4) * 1.25, 0))
l22 = self.create_square(
l4_color,
start_size / 8,
shift_pos,
-4,
((start_size / 4) * 1.25, -(start_size / 4) * 1.25, 0),
)
p23 = self.add_particle((-0.5, -1.6, 0), GRAY, t, False)
p24 = self.add_particle((-2.0, -2.2, 0), GRAY, t, False)
l24 = self.create_square(l3_color, start_size / 4, shift_pos, -3, (-(start_size / 4) * 1.5, -(start_size / 4) * 1.5, 0))
l24 = self.create_square(
l3_color,
start_size / 4,
shift_pos,
-3,
(-(start_size / 4) * 1.5, -(start_size / 4) * 1.5, 0),
)
l2_g = VGroup(l7, p9, l10, p11, p14, p23)
l3_g = VGroup(p13, p7, p8, l8, p15, l12, p17, l17, p20, p12, l20, p24, p6, l24)
@@ -320,7 +479,6 @@ class DefaultTemplate(ThreeDScene):
l5_g = VGroup(p18, l19)
return VGroup(l2_g, l3_g, l4_g, l5_g)
def add_particle(self, point, color, runtime=1, write=True):
dot = Dot(color=color)
dot.move_to((shift_pos))