Surface¶
Qualified name: manim.mobject.three\_d.three\_dimensions.Surface
- class Surface(func, u_range=(0, 1), v_range=(0, 1), resolution=32, surface_piece_config={}, fill_color=ManimColor('#29ABCA'), fill_opacity=1.0, checkerboard_colors=[ManimColor('#29ABCA'), ManimColor('#236B8E')], stroke_color=ManimColor('#BBBBBB'), stroke_width=0.5, should_make_jagged=False, pre_function_handle_to_anchor_scale_factor=1e-05, **kwargs)[source]¶
Bases:
VGroupCreates a Parametric Surface using a checkerboard pattern.
- Parameters:
func (Callable[[float, float], np.ndarray]) – The function defining the
Surface.u_range (tuple[float, float]) – The range of the
uvariable:(u_min, u_max).v_range (tuple[float, float]) – The range of the
vvariable:(v_min, v_max).resolution (int | Sequence[int]) – The number of samples taken of the
Surface. A tuple can be used to define different resolutions foruandvrespectively.fill_color (ParsableManimColor) – The color of the
Surface. Ignored ifcheckerboard_colorsis set.fill_opacity (float) – The opacity of the
Surface, from 0 being fully transparent to 1 being fully opaque. Defaults to 1.checkerboard_colors (list[ManimColor] | Literal[False]) – ng individual faces alternating colors. Overrides
fill_color.stroke_color (ParsableManimColor) – Color of the stroke surrounding each face of
Surface.stroke_width (float) – Width of the stroke surrounding each face of
Surface. Defaults to 0.5.should_make_jagged (bool) – Changes the anchor mode of the Bézier curves from smooth to jagged. Defaults to
False.surface_piece_config (dict)
pre_function_handle_to_anchor_scale_factor (float)
kwargs (Any)
Examples
Example: ParaSurface ¶
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], resolution=8, ) self.set_camera_orientation(theta=70 * DEGREES, phi=75 * DEGREES) self.add(axes, surface)
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], resolution=8, ) self.set_camera_orientation(theta=70 * DEGREES, phi=75 * DEGREES) self.add(axes, surface)Methods
funcSets the fill_color of each face of
Surfacein an alternating pattern.Sets the color of each mobject of a parametric surface to a color relative to its axis-value.
Attributes
alwaysCall a method on a mobject every frame.
animateUsed to animate the application of any method of
self.animation_overridescolordepthThe depth of the mobject.
fill_colorIf there are multiple colors (for gradient) this returns the first one
heightThe height of the mobject.
n_points_per_curvesheen_factorstroke_colorwidthThe width of the mobject.
- _original__init__(func, u_range=(0, 1), v_range=(0, 1), resolution=32, surface_piece_config={}, fill_color=ManimColor('#29ABCA'), fill_opacity=1.0, checkerboard_colors=[ManimColor('#29ABCA'), ManimColor('#236B8E')], stroke_color=ManimColor('#BBBBBB'), stroke_width=0.5, should_make_jagged=False, pre_function_handle_to_anchor_scale_factor=1e-05, **kwargs)¶
Initialize self. See help(type(self)) for accurate signature.
- Parameters:
func (Callable[[float, float], ndarray])
u_range (tuple[float, float])
v_range (tuple[float, float])
resolution (int | Sequence[int])
surface_piece_config (dict)
fill_color (ParsableManimColor)
fill_opacity (float)
checkerboard_colors (Iterable[TypeAliasForwardRef('~manim.utils.color.core.ParsableManimColor')] | Literal[False])
stroke_color (ParsableManimColor)
stroke_width (float)
should_make_jagged (bool)
pre_function_handle_to_anchor_scale_factor (float)
kwargs (Any)
- Return type:
None
- set_fill_by_checkerboard(*colors, opacity=None)[source]¶
Sets the fill_color of each face of
Surfacein an alternating pattern.- Parameters:
colors (ParsableManimColor) – List of colors for alternating pattern.
opacity (float | None) – The fill_opacity of
Surface, from 0 being fully transparent to 1 being fully opaque.
- Returns:
The parametric surface with an alternating pattern.
- Return type:
- set_fill_by_value(axes, colorscale=None, axis=2, **kwargs)[source]¶
Sets the color of each mobject of a parametric surface to a color relative to its axis-value.
- Parameters:
axes (ThreeDAxes) – The axes for the parametric surface, which will be used to map axis-values to colors.
colorscale (Iterable[ParsableManimColor] | Iterable[tuple[ParsableManimColor, float]] | None) – A list of colors, ordered from lower axis-values to higher axis-values. If a list of tuples is passed containing colors paired with numbers, then those numbers will be used as the pivots.
axis (int) – The chosen axis to use for the color mapping. (0 = x, 1 = y, 2 = z)
kwargs (Any)
- Returns:
The parametric surface with a gradient applied by value. For chaining.
- Return type:
Examples
Example: FillByValueExample ¶
from manim import * class FillByValueExample(ThreeDScene): def construct(self): resolution_fa = 8 self.set_camera_orientation(phi=75 * DEGREES, theta=-160 * 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, colorscale=[(RED, -0.5), (YELLOW, 0), (GREEN, 0.5)], axis=2) self.add(axes, surface_plane)
class FillByValueExample(ThreeDScene): def construct(self): resolution_fa = 8 self.set_camera_orientation(phi=75 * DEGREES, theta=-160 * 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, colorscale=[(RED, -0.5), (YELLOW, 0), (GREEN, 0.5)], axis=2) self.add(axes, surface_plane)