0
0

wslでmanim その23

Posted at

概要

wslでmanimやってみた。
練習問題やってみた。

練習問題

next_toを使え。

参考にしたページ

成果物

NextToTest_ManimCE_v0.18.1.gif

サンプルコード


from manim import *

class NextToTest(Scene):
	def construct(self):
		dir_str = ['ORIGIN', 'LEFT', 'RIGHT', 'UP', 'DOWN', 'UL', 'UR', 'DL', 'DR']
		dir_list = [ORIGIN, LEFT, RIGHT, UP, DOWN, UL, UR, DL, DR]
		for str, d in zip(dir_str, dir_list):
			self.next_to_obj(str, d)
		for str, d in zip(dir_str, dir_list):
			self.next_to_obj(str + " buff = 0.5", d, buff = 0.5)
		for i in range(0,5):
			self.next_to_obj("LEFT, aligned_edge = " + dir_str[i], LEFT, buff = 0, aligned_edge = dir_list[i])
		for i in range(0, 5):
			self.next_to_obj("LEFT, buff = 0.5, aligned_edge = " + dir_str[i], LEFT, buff = 0.5, aligned_edge = dir_list[i])
		for str, d in zip(dir_str, dir_list):
			self.next_to_point(str, d)
	def next_to_obj(self, str, direction = ORIGIN, buff = 0, aligned_edge = ORIGIN):
		rect1 = Rectangle(width = 0.4, height = 0.2, stroke_color = RED)
		rect2 = Rectangle(width = 1.5, height = 1.5, stroke_color = BLUE).move_to(np.array([2, 2, 0]))
		text = Text(str, font = 'Ubuntu', stroke_width = 6, font_size = 21).next_to(rect1, DOWN)
		self.add(rect1, rect2, text)
		self.wait(0.3)
		rect1.next_to(rect2, direction, buff = aligned_edge)
		self.play(Write(rect1))
		self.wait()
		self.remove(rect1, rect2, text)
	def next_to_point(self, str, direction = ORIGIN, buff = 0, aligned_edge = ORIGIN):
		rect1 = Rectangle(width = 0.4, height = 0.2, stroke_color = RED)
		rect2 = Rectangle(width = 1.5, height = 1.5, stroke_color = BLUE).move_to(np.array([2, 2, 0]))
		text = Text(str, font = 'Ubuntu', stroke_width = 6, font_size = 21).next_to(rect1, DOWN)
		tgt_point = np.array([2, 2, 0])
		self.add(rect1, rect2, text)
		self.wait(0.3)
		rect1.next_to(tgt_point, direction, buff = aligned_edge)
		self.play(Write(rect1))
		self.wait()
		self.remove(rect1, rect2, text)





以上。

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