-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrubik.py
More file actions
130 lines (112 loc) · 4.37 KB
/
Copy pathrubik.py
File metadata and controls
130 lines (112 loc) · 4.37 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
import random
from manim import *
# Use our fork of manim_rubikscube!
from cube import *
# This also replaces the default colors
import solarized
from util_cube import *
from util import *
import itertools
class Rubik(RubikScene):
def construct(self):
# By the way, using the simple tree as an intermediary is an instance of a more general trick that is sometimes useful in math or competitive programming. For example, let’s say I ask you to come up with a sequence of moves that brings this scramble of Rubik’s cube to that one. Well, if you can work out how to solve both the first cube and the second cube, you can simply revert the second solution, bring them together and you are done.
cube_distance = 13
cubie_size = 0.25
down_shift = 2*DOWN
cube_from = RubiksCube(cubie_size=cubie_size, rotate_nicely=True).shift(
LEFT * cube_distance / 2 + down_shift
)
cube_to = RubiksCube(cubie_size=cubie_size, rotate_nicely=True).shift(
RIGHT * cube_distance / 2 + down_shift
)
cube_mid = RubiksCube(cubie_size=cubie_size, rotate_nicely=True).shift( + down_shift)
scramble(cube_from, unscramble1)
scramble(cube_to, unscramble2)
self.play(
FadeIn(cube_from)
)
self.wait()
self.play(
FadeIn(cube_to)
)
self.wait()
self.play(
FadeIn(cube_mid)
)
self.wait()
cubes = [cube_from]
arrows = []
cur_cube = cube_from
ar_shift = 1*DOWN
for i in range(len(scramble1)):
new_cube = cur_cube.copy()
self.add(new_cube)
a = Arrow(
cur_cube.get_center() + ar_shift,
cur_cube.get_center() + ar_shift + (cube_mid.get_center() - cube_from.get_center())/(len(scramble1)),
buff = 0.2,
color = RED
)
self.add_sound(random_rubik_file(), time_offset = 0.0)
self.play(
CubeMove(new_cube, scramble1[i],
(
cube_mid.get_center() * i * 1.0 /len(scramble1)
+ cube_from.get_center() * (len(scramble1) - 1.0 - i)/len(scramble1)
)[0]*RIGHT + cube_mid.get_center()[1]*UP
),
Create(a),
run_time=1 / 3,
)
cubes.append(new_cube)
arrows.append(a)
cur_cube = new_cube
self.wait()
cur_cube = cube_to
for i in range(len(scramble2)):
new_cube = cur_cube.copy()
self.add(new_cube)
a = Arrow(
cur_cube.get_center() + ar_shift,
cur_cube.get_center() + ar_shift + (cube_mid.get_center() - cube_to.get_center())/(len(scramble1)),
buff = 0.2,
color = BLUE
)
self.add_sound(random_rubik_file(), time_offset = 0.0)
self.play(
CubeMove(new_cube, scramble2[i],
(cube_mid.get_center()*i/(len(scramble2)) + cube_to.get_center()*(len(scramble2) - 1.0 - i)/(len(scramble2)))[0]*RIGHT + cube_mid.get_center()[1]*UP),
Create(a),
run_time=1 / 3,
)
cubes.append(new_cube)
arrows.append(a)
cur_cube = new_cube
self.wait()
anims = []
for a in arrows[-len(scramble2):]:
anims.append(
Transform(
a,
Arrow(
a.get_left(),
a.get_right(),
buff = 0.0,
color = RED
)
)
)
self.play(
*anims
)
self.wait()
# In general, if you want to transform one complicated object into another complicated object using some operations, it sometimes suffices to come up with a simple intermediate object and only work out how to transform complicated objects to the simple one.
self.play(
Circumscribe(cube_mid, color = RED)
)
self.wait()
self.play(
Circumscribe(cube_from, color = RED),
Circumscribe(cube_to, color = RED)
)
self.wait()