给我几段manim炫酷的立体图形代码
时间: 2023-05-25 19:05:37 浏览: 181
以下是几段manim炫酷的立体图形代码:
1. 正方体旋转
```python
class CubeRotation(ThreeDScene):
def construct(self):
cube = Cube(fill_opacity=0.5).rotate(45 * DEGREES)
self.set_camera_orientation(phi=75 * DEGREES, theta=-45 * DEGREES)
self.play(Rotate(cube, 360 * DEGREES, about_point=ORIGIN), run_time=8)
self.wait()
```
2. 万花筒立方体
```python
class KaleidoscopeCube(ThreeDScene):
def construct(self):
cube = Prismatoid()
kaleidoscope = Kaleidoscope(cube)
self.add(kaleidoscope)
self.play(kaleidoscope.animate.spin(),
kaleidoscope.animate.move_to(ORIGIN),
run_time=60
)
```
3. 悬浮的四面体
```python
class TetrahedronFloating(ThreeDScene):
def construct(self):
colors = [RED, BLUE, GREEN, PURPLE]
tetrahedron = Tetrahedron().set_color_by_gradient(*colors)
vertices = [tetrahedron.get_vertices()[i] for i in [0, 2, 1, 3]]
faces = VGroup(
Polygon(vertices[0], vertices[1], vertices[2]),
Polygon(vertices[0], vertices[1], vertices[3]),
Polygon(vertices[0], vertices[2], vertices[3]),
Polygon(vertices[1], vertices[2], vertices[3])
).set_color_by_gradient(*colors)
self.set_camera_orientation(phi=75 * DEGREES, theta=-45 * DEGREES)
self.play(
LaggedStartMap(
TetrahedronReveal, tetrahedron, run_time=1.5, lag_ratio=0.7,
remover=True
)
)
self.play(Write(faces))
self.wait()
```
4. 立体八音盒
```python
class EightNoteCube(ThreeDScene):
def construct(self):
cube = Cube(fill_opacity=0)
front = Polygon(
ORIGIN, RIGHT, RIGHT + UP, UP,
stroke_color=YELLOW, fill_opacity=1
)
back = front.copy().move_down()
top = Polygon(
ORIGIN, UP, RIGHT + UP, RIGHT,
stroke_color=RED, fill_opacity=1
)
bottom = top.copy().shift(2 * DOWN)
right = Polygon(
ORIGIN, UP, RIGHT + UP, RIGHT,
stroke_color=BLUE, fill_opacity=1
).rotate(90 * DEGREES, axis="X")
left = right.copy().shift(2 * LEFT)
self.set_camera_orientation(phi=45 * DEGREES, theta=-45 * DEGREES)
self.add(cube)
self.play(Create(front), Create(back),
Create(top), Create(bottom),
Create(right), Create(left), run_time=2)
self.wait()
```
以上是一些manim炫酷的立体图形代码,它们可以展示出manim的强大功能和丰富的图形效果。
阅读全文