[PYTHON] Manim's method 12

Overview

I checked manim's method. I tried using RubiksCube.

Sample code

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)



Generated video

https://www.youtube.com/watch?v=hjaVvJ49_nk

that's all.

Recommended Posts

Manim's method 7
Manim's method 13
Manim's method 18
Manim's method 17
Manim's method 5
Manim's method 3
Manim's method 15
Manim's method 11
Manim's method 20
Manim's method 10
Manim's method 9
Manim's method 6
Manim's method 21
Manim's method 8
Manim's method 14
Manim's method 19
Manim's method 12
Manim's method part 23
manim's manners
Binary method
Special method
Special method
Understand k-means method
Clustering of clustering method
Dictionary items method
[PyTorch] Installation method
N cross method
Image collection method
Regression analysis method
Gradient method implementation 1
Python-peewee connection method
Class method static method
youtube-dl update method
Monte Carlo method
Mode-Matching Method Simulation_Python
Johnson method (python)
[Python] Semi-Lagrange method