概要
wslでmanimやってみた。
練習問題やってみた。
練習問題
3dグラフを書け。
成果物
サンプルコード
from manim import *
class DSurface(Surface):
def __init__(self, **kwargs):
kwargs = {
"u_range": [-1.5, 1.5],
"v_range": [-1.5, 1.5],
"checkerboard_colors": [GREEN, BLUE],
"fill_opacity": 0.5
}
Surface.__init__(self, self.func, **kwargs)
def func(self, x, y):
return np.array([x, y, x ** 2 + y ** 2])
class test(ThreeDScene):
def construct(self):
sphere = Surface(lambda u, v: np.array([1.5 * np.cos(u) * np.cos(v), 1.5 * np.cos(u) * np.sin(v), 1.5 * np.sin(u)]), v_range = [0, TAU], u_range = [-PI / 2, PI / 2], checkerboard_colors = [RED_D, RED_E], resolution = (15, 32))
def param_plane(u, v):
x = u
y = v
z = 0
return np.array([x, y, z])
plane = Surface(param_plane, resolution = (22, 22), v_range = [-2, +2], u_range = [-2, +2], )
def param_gauss(u, v):
x = u
y = v
d = np.sqrt(x * x + y * y)
sigma, mu = 0.4, 0.0
z = np.exp(-((d - mu) ** 2 / (2.0 * sigma ** 2)))
return np.array([x, y, z])
gauss_plane = Surface(param_gauss, resolution = (22, 22), v_range = [-2, +2], u_range = [-2, +2], )
cylinder = Surface(lambda u, v: np.array([np.cos(TAU * v), np.sin(TAU * v), 1.0 * (1 - u)]), resolution = (6, 32))
surface = DSurface()
axes = ThreeDAxes()
self.set_camera_orientation(phi = 75 * DEGREES, theta = 30 * DEGREES)
self.add(axes)
self.add(sphere)
self.wait()
self.remove(sphere)
self.add(plane)
self.wait()
self.remove(plane)
self.add(gauss_plane)
self.wait()
self.remove(gauss_plane)
self.add(cylinder)
self.wait()
self.remove(cylinder)
self.add(surface)
self.wait()
以上。