Surface

Qualified name: manim.mobject.three\_dimensions.Surface

class Surface(func, u_range=[0, 1], v_range=[0, 1], resolution=32, surface_piece_config={}, fill_color='#29ABCA', fill_opacity=1.0, checkerboard_colors=['#29ABCA', '#236B8E'], stroke_color='#BBBBBB', stroke_width=0.5, should_make_jagged=False, pre_function_handle_to_anchor_scale_factor=1e-05, **kwargs)[source]

Bases: manim.mobject.types.vectorized_mobject.VGroup

Creates a Parametric Surface using a checkerboard pattern.

Parameters
  • func (Callable[[float, float], numpy.ndarray]) – The function that defines the surface.

  • u_range (Sequence[float]) – The range of the u variable: (u_min, u_max).

  • v_range (Sequence[float]) – The range of the v variable: (v_min, v_max).

  • resolution (Sequence[int]) – The number of samples taken of the surface. A tuple can be used to define different resolutions for u and v respectively.

  • surface_piece_config (dict) –

  • fill_color (Color) –

  • fill_opacity (float) –

  • checkerboard_colors (Sequence[Color]) –

  • stroke_color (Color) –

  • stroke_width (float) –

  • should_make_jagged (bool) –

  • pre_function_handle_to_anchor_scale_factor (float) –

Return type

None

Examples

Example: ParaSurface

../_images/ParaSurface-1.png
from manim import *

class ParaSurface(ThreeDScene):
    def func(self, u, v):
        return np.array([np.cos(u) * np.cos(v), np.cos(u) * np.sin(v), u])

    def construct(self):
        axes = ThreeDAxes(x_range=[-4,4], x_length=8)
        surface = Surface(
            lambda u, v: axes.c2p(*self.func(u, v)),
            u_range=[-PI, PI],
            v_range=[0, TAU]
        )
        self.set_camera_orientation(theta=70 * DEGREES, phi=75 * DEGREES)
        self.add(axes, surface)

Methods

get_u_values_and_v_values

set_fill_by_checkerboard

set_fill_by_value

Sets the color of each mobject of a parametric surface to a color relative to its z-value

setup_in_uv_space

Attributes

animate

Used to animate the application of a method.

animation_overrides

depth

The depth of the mobject.

height

The height of the mobject.

width

The width of the mobject.

set_fill_by_value(axes, colors)[source]

Sets the color of each mobject of a parametric surface to a color relative to its z-value

Parameters
  • axes (manim.mobject.mobject.Mobject) – The axes for the parametric surface, which will be used to map z-values to colors.

  • colors (Union[Iterable[colour.Color], colour.Color]) – A list of colors, ordered from lower z-values to higher z-values. If a list of tuples is passed containing colors paired with numbers, then those numbers will be used as the pivots.

Returns

The parametric surface with a gradient applied by value. For chaining.

Return type

Surface

Examples

Example: FillByValueExample

../_images/FillByValueExample-1.png
from manim import *

class FillByValueExample(ThreeDScene):
    def construct(self):
        resolution_fa = 42
        self.set_camera_orientation(phi=75 * DEGREES, theta=-120 * DEGREES)
        axes = ThreeDAxes(x_range=(0, 5, 1), y_range=(0, 5, 1), z_range=(-1, 1, 0.5))
        def param_surface(u, v):
            x = u
            y = v
            z = np.sin(x) * np.cos(y)
            return z
        surface_plane = Surface(
            lambda u, v: axes.c2p(u, v, param_surface(u, v)),
            resolution=(resolution_fa, resolution_fa),
            v_range=[0, 5],
            u_range=[0, 5],
            )
        surface_plane.set_style(fill_opacity=1)
        surface_plane.set_fill_by_value(axes=axes, colors=[(RED, -0.4), (YELLOW, 0), (GREEN, 0.4)])
        self.add(axes, surface_plane)