manim.mobject.types.vectorized_mobject.VMobject

class VMobject(fill_color=None, fill_opacity=0.0, stroke_color=None, stroke_opacity=1.0, stroke_width=4, background_stroke_color='#000000', background_stroke_opacity=1.0, background_stroke_width=0, sheen_factor=0.0, sheen_direction=array([- 1., 1., 0.]), close_new_points=False, pre_function_handle_to_anchor_scale_factor=0.01, make_smooth_after_applying_functions=False, background_image=None, shade_in_3d=False, tolerance_for_point_equality=1e-06, n_points_per_cubic_curve=4, **kwargs)[source]

Bases: manim.mobject.mobject.Mobject

Methods

add_cubic_bezier_curve

add_cubic_bezier_curve_to

Add cubic bezier curve to the path.

add_line_to

Add a straight line from the last point of VMobject to the given point.

add_points_as_corners

add_quadratic_bezier_curve_to

Add Quadratic bezier curve to the path.

add_smooth_curve_to

Creates a smooth curve from given points and add it to the VMobject.

add_subpath

align_points

align_rgbas

append_points

append_vectorized_mobject

apply_function

change_anchor_mode

Changes the anchor mode of the bezier curves.

clear_points

color_using_background_image

consider_points_equals

consider_points_equals_2d

Determine if two points are close enough to be considered equal.

fade

force_direction

Makes sure that points are either directed clockwise or counterclockwise.

gen_cubic_bezier_tuples_from_points

Returns the bezier tuples from an array of points.

gen_subpaths_from_points_2d

generate_rgbas_array

First arg can be either a color, or a tuple/list of colors.

get_anchors

Returns the anchors of the curves forming the VMobject.

get_anchors_and_handles

Returns anchors1, handles1, handles2, anchors2, where (anchors1[i], handles1[i], handles2[i], anchors2[i]) will be four points defining a cubic bezier curve for any i in range(0, len(anchors1))

get_arc_length

Return the approximated length of the whole curve.

get_background_image

get_color

Returns the color of the Mobject

get_cubic_bezier_tuples

get_cubic_bezier_tuples_from_points

get_curve_functions

Gets the functions for the curves of the mobject.

get_curve_functions_with_lengths

Gets the functions and lengths of the curves for the mobject.

get_direction

Uses shoelace_direction() to calculate the direction.

get_end_anchors

Return the starting anchors of the bezier curves.

get_fill_color

If there are multiple colors (for gradient) this returns the first one

get_fill_colors

get_fill_opacities

get_fill_opacity

If there are multiple opacities, this returns the first

get_fill_rgbas

get_gradient_start_and_end_points

get_group_class

get_last_point

get_nth_curve_function

Returns the expression of the nth curve.

get_nth_curve_function_with_length

Returns the expression of the nth curve along with its (approximate) length.

get_nth_curve_points

Returns the points defining the nth curve of the vmobject.

get_num_curves

Returns the number of curves of the vmobject.

get_point_mobject

The simplest Mobject to be transformed to or from self.

get_points

get_points_defining_boundary

get_sheen_direction

get_sheen_factor

get_start_anchors

Returns the start anchors of the bezier curves.

get_stroke_color

get_stroke_colors

get_stroke_opacities

get_stroke_opacity

get_stroke_rgbas

get_stroke_width

get_style

get_subcurve

Returns the subcurve of the VMobject between the interval [a, b].

get_subpaths

Returns subpaths formed by the curves of the VMobject.

get_subpaths_from_points

has_new_path_started

init_colors

Initializes the colors.

insert_n_curves

Inserts n curves to the bezier curves of the vmobject.

insert_n_curves_to_point_list

Given an array of k points defining a bezier curves (anchors and handles), returns points defining exactly k + n bezier curves.

interpolate_color

is_closed

make_jagged

make_smooth

match_background_image

match_style

point_from_proportion

Gets the point at a proportion along the path of the VMobject.

pointwise_become_partial

Given two bounds a and b, transforms the points of the self vmobject into the points of the vmobject passed as parameter with respect to the bounds.

reverse_direction

Reverts the point direction by inverting the point order.

rotate

Rotates the Mobject about a certain point.

rotate_sheen_direction

Rotates the direction of the applied sheen.

scale_handle_to_anchor_distances

If the distance between a given handle point H and its associated anchor point A is d, then it changes H to be a distances factor*d away from A, but so that the line from A to H doesn’t change.

set_anchors_and_handles

Given two sets of anchors and handles, process them to set them as anchors and handles of the VMobject.

set_background_stroke

set_color

Condition is function which takes in one arguments, (x, y, z).

set_fill

set_opacity

set_points

set_points_as_corners

Given an array of points, set them as corner of the vmobject.

set_points_smoothly

set_shade_in_3d

set_sheen

Applies a color gradient from a direction.

set_sheen_direction

Sets the direction of the applied sheen.

set_stroke

set_style

start_new_path

update_rgbas_array

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.

add_cubic_bezier_curve_to(handle1, handle2, anchor)[source]

Add cubic bezier curve to the path.

NOTE : the first anchor is not a parameter as by default the end of the last sub-path!

Parameters
  • handle1 (np.ndarray) – first handle

  • handle2 (np.ndarray) – second handle

  • anchor (np.ndarray) – anchor

Return type

None

add_line_to(point)[source]

Add a straight line from the last point of VMobject to the given point.

Parameters

point (np.ndarray) – end of the straight line.

Return type

manim.mobject.types.vectorized_mobject.VMobject

add_quadratic_bezier_curve_to(handle, anchor)[source]

Add Quadratic bezier curve to the path.

Parameters
  • handle (numpy.ndarray) –

  • anchor (numpy.ndarray) –

Return type

manim.mobject.types.vectorized_mobject.VMobject

add_smooth_curve_to(*points)[source]

Creates a smooth curve from given points and add it to the VMobject. If two points are passed in, the first is interpreted as a handle, the second as an anchor.

Parameters

points (np.array) – Points (anchor and handle, or just anchor) to add a smooth curve from

Returns

Return type

VMobject

Raises

ValueError – If 0 or more than 2 points are given.

change_anchor_mode(mode)[source]

Changes the anchor mode of the bezier curves. This will modify the handles.

There can be only two modes, “jagged”, and “smooth”.

Returns

For chaining purposes.

Return type

VMobject

Parameters

mode (str) –

consider_points_equals_2d(p0, p1)[source]

Determine if two points are close enough to be considered equal.

This uses the algorithm from np.isclose(), but expanded here for the 2D point case. NumPy is overkill for such a small question. :param p0: first point :type p0: np.ndarray :param p1: second point :type p1: np.ndarray

Returns

whether two points considered close.

Return type

bool

Parameters
  • p0 (numpy.ndarray) –

  • p1 (numpy.ndarray) –

force_direction(target_direction)[source]

Makes sure that points are either directed clockwise or counterclockwise.

Parameters

target_direction (str) – Either "CW" or "CCW".

gen_cubic_bezier_tuples_from_points(points)[source]

Returns the bezier tuples from an array of points.

self.points is a list of the anchors and handles of the bezier curves of the mobject (ie [anchor1, handle1, handle2, anchor2, anchor3 ..]) This algorithm basically retrieve them by taking an element every n, where n is the number of control points of the bezier curve.

Parameters

points (np.ndarray) – Points from which control points will be extracted.

Returns

Bezier control points.

Return type

typing.Tuple

generate_rgbas_array(color, opacity)[source]

First arg can be either a color, or a tuple/list of colors. Likewise, opacity can either be a float, or a tuple of floats. If self.sheen_factor is not zero, and only one color was passed in, a second slightly light color will automatically be added for the gradient

get_anchors()[source]

Returns the anchors of the curves forming the VMobject.

Returns

The anchors.

Return type

np.ndarray

get_anchors_and_handles()[source]

Returns anchors1, handles1, handles2, anchors2, where (anchors1[i], handles1[i], handles2[i], anchors2[i]) will be four points defining a cubic bezier curve for any i in range(0, len(anchors1))

Returns

Iterable of the anchors and handles.

Return type

typing.Iterable[np.ndarray]

get_arc_length(sample_points_per_curve=None)[source]

Return the approximated length of the whole curve.

Parameters

sample_points_per_curve (Optional[int]) – Number of sample points per curve used to approximate the length. More points result in a better approximation.

Returns

The length of the VMobject.

Return type

float

get_color()[source]

Returns the color of the Mobject

get_curve_functions()[source]

Gets the functions for the curves of the mobject.

Returns

The functions for the curves.

Return type

typing.Iterable[typing.Callable[[float], np.ndarray]]

get_curve_functions_with_lengths(**kwargs)[source]

Gets the functions and lengths of the curves for the mobject.

Parameters

**kwargs – The keyword arguments passed to get_nth_curve_function_with_length()

Returns

The functions and lengths of the curves.

Return type

typing.Iterable[typing.Tuple[typing.Callable[[float], np.ndarray], float]]

get_direction()[source]

Uses shoelace_direction() to calculate the direction. The direction of points determines in which direction the object is drawn, clockwise or counterclockwise.

Examples

The default direction of a Circle is counterclockwise:

>>> from manim import Circle
>>> Circle().get_direction()
'CCW'
Returns

Either "CW" or "CCW".

Return type

str

get_end_anchors()[source]

Return the starting anchors of the bezier curves.

Returns

Starting anchors

Return type

np.ndarray

get_fill_color()[source]

If there are multiple colors (for gradient) this returns the first one

get_fill_opacity()[source]

If there are multiple opacities, this returns the first

get_nth_curve_function(n)[source]

Returns the expression of the nth curve.

Parameters

n (int) – index of the desired curve.

Returns

expression of the nth bezier curve.

Return type

typing.Callable[float]

get_nth_curve_function_with_length(n, sample_points=None)[source]

Returns the expression of the nth curve along with its (approximate) length.

Parameters
  • n (int) – The index of the desired curve.

  • sample_points (Optional[int]) – The number of points to sample to find the length.

Returns

  • curve (typing.Callable[[float], np.ndarray]) – The function for the nth curve.

  • length (float) – The length of the nth curve.

Return type

Tuple[Callable[[float], numpy.ndarray], float]

get_nth_curve_points(n)[source]

Returns the points defining the nth curve of the vmobject.

Parameters

n (int) – index of the desired bezier curve.

Returns

points defininf the nth bezier curve (anchors, handles)

Return type

np.ndarray

get_num_curves()[source]

Returns the number of curves of the vmobject.

Returns

number of curves. of the vmobject.

Return type

int

get_point_mobject(center=None)[source]

The simplest Mobject to be transformed to or from self. Should by a point of the appropriate type

get_start_anchors()[source]

Returns the start anchors of the bezier curves.

Returns

Starting anchors

Return type

np.ndarray

get_subcurve(a, b)[source]

Returns the subcurve of the VMobject between the interval [a, b]. The curve is a VMobject itself.

Parameters
  • a (float) – The lower bound.

  • b (float) – The upper bound.

Returns

The subcurve between of [a, b]

Return type

VMobject

get_subpaths()[source]

Returns subpaths formed by the curves of the VMobject.

We define a subpath between two curve if one of their extreminities are coincidents.

Returns

subpaths.

Return type

typing.Tuple

init_colors(propagate_colors=True)[source]

Initializes the colors.

Gets called upon creation. This is an empty method that can be implemented by subclasses.

insert_n_curves(n)[source]

Inserts n curves to the bezier curves of the vmobject.

Parameters

n (int) – Number of curves to insert.

Returns

for chaining.

Return type

VMobject

insert_n_curves_to_point_list(n, points)[source]

Given an array of k points defining a bezier curves (anchors and handles), returns points defining exactly k + n bezier curves.

Parameters
  • n (int) – Number of desired curves.

  • points (np.ndarray) – Starting points.

Returns

Points generated.

Return type

np.ndarray

point_from_proportion(alpha)[source]

Gets the point at a proportion along the path of the VMobject.

Parameters

alpha (float) – The proportion along the the path of the VMobject.

Returns

The point on the VMobject.

Return type

numpy.ndarray

Raises
  • ValueError – If alpha is not between 0 and 1.

  • Exception – If the VMobject has no points.

pointwise_become_partial(vmobject, a, b)[source]

Given two bounds a and b, transforms the points of the self vmobject into the points of the vmobject passed as parameter with respect to the bounds. Points here stand for control points of the bezier curves (anchors and handles)

Parameters
  • vmobject (VMobject) – The vmobject that will serve as a model.

  • a (float) – upper-bound.

  • b (float) – lower-bound

Return type

manim.mobject.types.vectorized_mobject.VMobject

reverse_direction()[source]

Reverts the point direction by inverting the point order.

Returns

Returns self.

Return type

VMobject

Examples

Example: ChangeOfDirection

from manim import *

class ChangeOfDirection(Scene):
    def construct(self):
        ccw = RegularPolygon(5)
        ccw.shift(LEFT).rotate
        cw = RegularPolygon(5)
        cw.shift(RIGHT).reverse_direction()

        self.play(Create(ccw), Create(cw),
        run_time=4)
rotate(angle, axis=array([0., 0., 1.]), about_point=None, **kwargs)[source]

Rotates the Mobject about a certain point.

Parameters
  • angle (float) –

  • axis (numpy.ndarray) –

  • about_point (Optional[Sequence[float]]) –

rotate_sheen_direction(angle, axis=array([0., 0., 1.]), family=True)[source]

Rotates the direction of the applied sheen.

Parameters
  • angle (float) – Angle by which the direction of sheen is rotated.

  • axis (numpy.ndarray) – Axis of rotation.

Examples

Normal usage:

Circle().set_sheen_direction(UP).rotate_sheen_direction(PI)
scale_handle_to_anchor_distances(factor)[source]

If the distance between a given handle point H and its associated anchor point A is d, then it changes H to be a distances factor*d away from A, but so that the line from A to H doesn’t change. This is mostly useful in the context of applying a (differentiable) function, to preserve tangency properties. One would pull all the handles closer to their anchors, apply the function then push them out again.

Parameters

factor (float) – The factor used for scaling.

Returns

For chaining.

Return type

VMobject

set_anchors_and_handles(anchors1, handles1, handles2, anchors2)[source]

Given two sets of anchors and handles, process them to set them as anchors and handles of the VMobject.

anchors1[i], handles1[i], handles2[i] and anchors2[i] define the i-th bezier curve of the vmobject. There are four hardcoded parameters and this is a problem as it makes the number of points per cubic curve unchangeable from 4. (two anchors and two handles).

Returns

for chaining.

Return type

VMobject

Parameters
  • anchors1 (Sequence[float]) –

  • handles1 (Sequence[float]) –

  • handles2 (Sequence[float]) –

  • anchors2 (Sequence[float]) –

set_color(color, family=True)[source]

Condition is function which takes in one arguments, (x, y, z). Here it just recurses to submobjects, but in subclasses this should be further implemented based on the the inner workings of color

set_points_as_corners(points)[source]

Given an array of points, set them as corner of the vmobject.

To achieve that, this algorithm sets handles aligned with the anchors such that the resultant bezier curve will be the segment between the two anchors.

Parameters

points (Iterable[float]) – Array of points that will be set as corners.

Returns

self. For chaining purposes.

Return type

VMobject

set_sheen(factor, direction=None, family=True)[source]

Applies a color gradient from a direction.

Parameters
  • factor (float) – The extent of lustre/gradient to apply. If negative, the gradient starts from black, if positive the gradient starts from white and changes to the current color.

  • direction (numpy.ndarray, optional) – Direction from where the gradient is applied.

Examples

Example: SetSheen

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

class SetSheen(Scene):
    def construct(self):
        circle = Circle(fill_opacity=1).set_sheen(-0.3, DR)
        self.add(circle)
set_sheen_direction(direction, family=True)[source]

Sets the direction of the applied sheen.

Parameters

direction (numpy.ndarray, optional) – Direction from where the gradient is applied.

Examples

Normal usage:

Circle().set_sheen_direction(UP)