I checked manim's method. I tried using ImageMobject.
from manimlib.imports import *
import numpy as np
from enum import Enum
class Color(Enum):
WHITE = (255, 255, 255)
YELLOW = (0, 255, 255)
CYAN = (255, 255, 0)
GREEN = (0, 255, 0)
MAGENTA = (255, 0, 255)
RED = (0, 0, 255)
BLUE = (255, 0, 0)
BLACK = (0, 0, 0)
class test(Scene):
def construct(self):
n = 256
imageArray = np.uint8([[i * 256 / n for i in range(0, n)] for _ in range(0, n)])
img0 = ImageMobject(imageArray)
img0.set_height(7)
img0.shift(2 * UP)
img1 = ImageMobject(np.uint8([[0, 100, 30, 200], [255, 0, 5, 33]]))
img1.set_height(7)
img1.shift(2 * UP)
width = 256
height = 256
color_img = np.zeros((height, width, 3), dtype = np.uint8)
bar_width = 32
i = 0
for c in Color:
color_img[0: height, i: i + bar_width] = c.value
i += bar_width
img2 = ImageMobject(color_img)
img2.set_height(7)
img2.shift(2 * UP)
matrix = np.uint8([[0, 0, 200], [255, 0, 33]])
img3 = ImageMobject(matrix)
img3.scale(3)
mat = np.uint8([[[0, 0, 0], [0, 0, 0], [0, 0, 200]], [[0, 0, 255], [0, 0, 0], [0, 0, 33]]])
img4 = ImageMobject(mat)
img4.scale(3)
self.play(ShowCreation(img0))
self.wait()
self.play(ShowCreation(img1))
self.wait()
self.play(ShowCreation(img2))
self.wait()
self.play(ShowCreation(img3))
self.wait()
self.play(ShowCreation(img4))
self.wait()
https://www.youtube.com/watch?v=mDAbs6f-PGQ
that's all.
Recommended Posts