I checked manim's method. I tried using RubiksCube.
from manimlib.imports import *
class RubiksCube(VGroup):
CONFIG = {
"colors": [
"#FFD500", # Yellow
"#C41E3A", # Orange
"#009E60", # Green
"#FF5800", # Red
"#0051BA", # Blue
"#FFFFFF" # White
],
}
def __init__(self, **kwargs):
digest_config(self, kwargs)
vectors = [OUT, RIGHT, UP, LEFT, DOWN, IN]
faces = [self.create_face(color, vector) for color, vector in zip(self.colors, vectors)]
VGroup.__init__(self, *it.chain(*faces), **kwargs)
self.set_shade_in_3d(True)
def create_face(self, color, vector):
squares = VGroup(*[self.create_square(color) for x in range(9)])
squares.arrange_in_grid(3, 3, buff = 0)
squares.set_width(2)
squares.move_to(OUT, OUT)
squares.apply_matrix(z_to_vector(vector))
return squares
def create_square(self, color):
square = Square(stroke_width = 3, stroke_color = BLACK, fill_color = color, fill_opacity = 1, side_length = 1, )
square.flip()
return square
def get_face(self, vect):
self.sort(lambda p: np.dot(p, vect))
return self[-(12 + 9):]
class test(SpecialThreeDScene):
def construct(self):
cube = RubiksCube()
cube.set_fill(opacity = 0.8)
cube.set_stroke(width = 1)
axes = self.get_axes()
self.add(axes, cube)
self.move_camera(phi = 70 * DEGREES, theta = -140 * DEGREES, )
self.begin_ambient_camera_rotation(rate = 0.02)
self.wait(2)
self.play(Rotate(cube, TAU / 4, RIGHT, run_time = 3))
self.wait(2)
self.play(Rotate(cube, TAU / 4, UP, run_time = 3))
self.wait(2)
self.play(Rotate(cube, -TAU / 3, np.ones(3), run_time = 3))
self.wait(2)
https://www.youtube.com/watch?v=hjaVvJ49_nk
that's all.
Recommended Posts