from manim import *
import numpy as np
class ValueSurface(ThreeDScene):
    def construct(self):
        self.set_camera_orientation(phi=68 * DEGREES, theta=-48 * DEGREES)
        title = Text("set_fill_by_value：按曲面数值渐变着色", font="STLiti", font_size=30).to_edge(UP)
        self.add_fixed_in_frame_mobjects(title)
        axes = ThreeDAxes(x_range=[-3, 3, 1], y_range=[-3, 3, 1], z_range=[-2, 2, 1],
                          x_length=6, y_length=6, z_length=4)
        def func(u, v):
            return axes.c2p(u, v, np.sin(u * PI) * np.cos(v * PI))
        surf = Surface(func, u_range=[-1, 1], v_range=[-1, 1], resolution=(16, 16))
        surf.set_fill_by_value(axes=axes, colorscale=[(RED, -0.5), (YELLOW, 0), (GREEN, 0.5)], axis=2)
        note = Text("colorscale 按 z 值映射红-黄-绿，需传入 ThreeDAxes", font="STLiti", font_size=21, color=YELLOW).to_edge(DOWN)
        self.add_fixed_in_frame_mobjects(note)
        self.play(FadeIn(title), run_time=0.6)
        self.play(FadeIn(axes), FadeIn(surf), run_time=1.6)
        self.play(FadeIn(note), run_time=0.5)
        self.wait(3.6)
