0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

manimの作法 その12

Posted at

概要

manimの作法、調べてみた。
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)



生成した動画

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?