VMobject¶
Qualified name: 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=ManimColor('#000000'), background_stroke_opacity=1.0, background_stroke_width=0, sheen_factor=0.0, joint_type=None, 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, cap_style=CapStyleType.AUTO, **kwargs)[source]¶
Bases:
MobjectA vectorized mobject.
- Parameters:
background_stroke_color (ManimColor) – The purpose of background stroke is to have something that won’t overlap fill, e.g. For text against some textured background.
sheen_factor (float) – When a color c is set, there will be a second color computed based on interpolating c to WHITE by with sheen_factor, and the display will gradient to this secondary color in the direction of sheen_direction.
close_new_points (bool) – Indicates that it will not be displayed, but that it should count in parent mobject’s path
tolerance_for_point_equality (float) – This is within a pixel
joint_type (LineJointType) – The line joint type used to connect the curve segments of this vectorized mobject. See
LineJointTypefor options.fill_color (ParsableManimColor | None)
fill_opacity (float)
stroke_color (ParsableManimColor | None)
stroke_opacity (float)
stroke_width (float)
background_stroke_opacity (float)
background_stroke_width (float)
sheen_direction (Vector3DLike)
pre_function_handle_to_anchor_scale_factor (float)
make_smooth_after_applying_functions (bool)
background_image (Image | str | None)
shade_in_3d (bool)
n_points_per_cubic_curve (int)
cap_style (CapStyleType)
kwargs (Any)
Methods
add_cubic_bezier_curveAdd cubic bezier curve to the path.
add_cubic_bezier_curvesAdd a straight line from the last point of VMobject to the given point.
Append multiple straight lines at the end of
VMobject.points, which connect the givenpointsin order starting from the end of the current path.Add Quadratic bezier curve to the path.
Creates a smooth curve from given points and add it to the VMobject.
add_subpathAdds points to self and vmobject so that they both have the same number of subpaths, with corresponding subpaths each containing the same number of points.
align_rgbasAppend the given
new_pointsto the end ofVMobject.points.append_vectorized_mobjectapply_functionChanges the anchor mode of the bezier curves.
clear_pointsclose_pathcolor_using_background_imageconsider_points_equalsDetermine if two points are close enough to be considered equal.
fadeMakes sure that points are either directed clockwise or counterclockwise.
Returns the bezier tuples from an array of points.
gen_subpaths_from_points_2dFirst arg can be either a color, or a tuple/list of colors.
Returns the anchors of the curves forming the VMobject.
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))
Return the approximated length of the whole curve.
get_background_imageReturns the color of the
Mobjectget_cubic_bezier_tuplesget_cubic_bezier_tuples_from_pointsGets the functions for the curves of the mobject.
Gets the functions and lengths of the curves for the mobject.
Uses
shoelace_direction()to calculate the direction.Return the end anchors of the bezier curves.
If there are multiple colors (for gradient) this returns the first one
get_fill_colorsget_fill_opacitiesIf there are multiple opacities, this returns the first
get_fill_rgbasget_gradient_start_and_end_pointsget_group_classget_last_pointReturn the base class of this mobject type.
Returns the expression of the nth curve.
Returns the expression of the nth curve along with its (approximate) length.
Returns the (approximate) length of the nth curve.
Returns the array of short line lengths used for length approximation.
Returns the points defining the nth curve of the vmobject.
Returns the number of curves of the vmobject.
The simplest
Mobjectto be transformed to or from self.get_points_defining_boundaryget_sheen_directionget_sheen_factorReturns the start anchors of the bezier curves.
get_stroke_colorget_stroke_colorsget_stroke_opacitiesget_stroke_opacityget_stroke_rgbasget_stroke_widthget_styleReturns the subcurve of the VMobject between the interval [a, b].
Returns subpaths formed by the curves of the VMobject.
get_subpaths_from_pointshas_new_path_startedInitializes the colors.
Inserts n curves to the bezier curves of the vmobject.
Given an array of k points defining a bezier curves (anchors and handles), returns points defining exactly k + n bezier curves.
interpolate_coloris_closedmake_jaggedmake_smoothmatch_background_imagematch_styleGets the point at a proportion along the path of the
VMobject.Given a 2nd
VMobjectvmobject, a lower boundaand an upper boundb, modify thisVMobject's points to match the portion of the Bézier spline described byvmobject.pointswith the parametertbetweenaandb.Returns the proportion along the path of the
VMobjecta particular given point is at.Resize the array of anchor points and handles to have the specified size.
Reverts the point direction by inverting the point order.
Rotates the
Mobjectaround a specified axis and point.Rotates the direction of the applied sheen.
Scale the size by a factor.
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.
Given two sets of anchors and handles, process them to set them as anchors and handles of the VMobject.
set_background_strokeSets the cap style of the
VMobject.Condition is function which takes in one arguments, (x, y, z).
Set the fill color and fill opacity of a
VMobject.set_opacityset_pointsGiven an array of points, set them as corners of the
VMobject.set_points_smoothlyset_shade_in_3dApplies a color gradient from a direction.
Sets the direction of the applied sheen.
set_strokeset_styleAppend a
pointto theVMobject.points, which will be the beginning of a new Bézier curve in the path given by the points.update_rgbas_arrayAttributes
alwaysCall a method on a mobject every frame.
animateUsed to animate the application of any method of
self.animation_overridescolordepthThe depth of the mobject.
If 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.
- _assert_valid_submobjects(submobjects)[source]¶
Check that all submobjects are actually instances of
Mobject, and that none of them isself(aMobjectcannot contain itself).This is an auxiliary function called when adding Mobjects to the
submobjectslist.This function is intended to be overridden by subclasses such as
VMobject, which should assert that only other VMobjects may be added into it.- Parameters:
submobjects (Iterable[VMobject]) – The list containing values to validate.
- Returns:
The Mobject itself.
- Return type:
Mobject- Raises:
TypeError – If any of the values in submobjects is not a
Mobject.ValueError – If there was an attempt to add a
Mobjectas its own submobject.
- _gen_subpaths_from_points(points, filter_func)[source]¶
Given an array of points defining the bezier curves of the vmobject, return subpaths formed by these points. Here, Two bezier curves form a path if at least two of their anchors are evaluated True by the relation defined by filter_func.
The algorithm every bezier tuple (anchors and handles) in
self.points(by regrouping each n elements, where n is the number of points per cubic curve)), and evaluate the relation between two anchors with filter_func. NOTE : The filter_func takes an int n as parameter, and will evaluate the relation between points[n] and points[n - 1]. This should probably be changed so the function takes two points as parameters.- Parameters:
points (CubicBezierPath) – points defining the bezier curve.
filter_func (Callable[[int], bool]) – Filter-func defining the relation.
- Returns:
subpaths formed by the points.
- Return type:
Iterable[CubicSpline]
- _original__init__(fill_color=None, fill_opacity=0.0, stroke_color=None, stroke_opacity=1.0, stroke_width=4, background_stroke_color=ManimColor('#000000'), background_stroke_opacity=1.0, background_stroke_width=0, sheen_factor=0.0, joint_type=None, 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, cap_style=CapStyleType.AUTO, **kwargs)¶
Initialize self. See help(type(self)) for accurate signature.
- Parameters:
fill_color (TypeAliasForwardRef('~manim.utils.color.core.ParsableManimColor') | None)
fill_opacity (float)
stroke_color (TypeAliasForwardRef('~manim.utils.color.core.ParsableManimColor') | None)
stroke_opacity (float)
stroke_width (float)
background_stroke_color (TypeAliasForwardRef('~manim.utils.color.core.ParsableManimColor') | None)
background_stroke_opacity (float)
background_stroke_width (float)
sheen_factor (float)
joint_type (LineJointType | None)
sheen_direction (Vector3DLike)
close_new_points (bool)
pre_function_handle_to_anchor_scale_factor (float)
make_smooth_after_applying_functions (bool)
background_image (Image | str | None)
shade_in_3d (bool)
tolerance_for_point_equality (float)
n_points_per_cubic_curve (int)
cap_style (CapStyleType)
kwargs (Any)
- 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 (Point3DLike) – first handle
handle2 (Point3DLike) – second handle
anchor (Point3DLike) – anchor
- Returns:
self- Return type:
- add_line_to(point)[source]¶
Add a straight line from the last point of VMobject to the given point.
- Parameters:
point (Point3DLike) – The end of the straight line.
- Returns:
self- Return type:
- add_points_as_corners(points)[source]¶
Append multiple straight lines at the end of
VMobject.points, which connect the givenpointsin order starting from the end of the current path. Thesepointswould be therefore the corners of the new polyline appended to the path.- Parameters:
points (Point3DLike_Array) – An array of 3D points representing the corners of the polyline to append to
VMobject.points.- Returns:
The VMobject itself, after appending the straight lines to its path.
- Return type:
- add_quadratic_bezier_curve_to(handle, anchor)[source]¶
Add Quadratic bezier curve to the path.
- Returns:
self- Return type:
- Parameters:
handle (Point3DLike)
anchor (Point3DLike)
- 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 (Point3DLike) – Points (anchor and handle, or just anchor) to add a smooth curve from
- Returns:
self- Return type:
- Raises:
ValueError – If 0 or more than 2 points are given.
- align_points(vmobject)[source]¶
Adds points to self and vmobject so that they both have the same number of subpaths, with corresponding subpaths each containing the same number of points.
Points are added either by subdividing curves evenly along the subpath, or by creating new subpaths consisting of a single point repeated.
- Parameters:
vmobject (VMobject) – The object to align points with.
- Returns:
self- Return type:
See also
- append_points(new_points)[source]¶
Append the given
new_pointsto the end ofVMobject.points.- Parameters:
new_points (Point3DLike_Array) – An array of 3D points to append.
- Returns:
The VMobject itself, after appending
new_points.- Return type:
- 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:
self- Return type:
- Parameters:
mode (Literal['jagged', 'smooth'])
- 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 :param p1: second point
- Returns:
whether two points considered close.
- Return type:
bool
- Parameters:
p0 (Point2DLike)
p1 (Point2DLike)
- property fill_color: ManimColor¶
If there are multiple colors (for gradient) this returns the first one
- force_direction(target_direction)[source]¶
Makes sure that points are either directed clockwise or counterclockwise.
- Parameters:
target_direction (Literal['CW', 'CCW']) – Either
"CW"or"CCW".- Return type:
Self
- 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 (CubicBezierPathLike) – Points from which control points will be extracted.
- Returns:
Bezier control points.
- Return type:
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
- Parameters:
color (TypeAliasForwardRef('~manim.utils.color.core.ParsableManimColor') | Iterable[ManimColor] | None)
opacity (float | Iterable[float])
- Return type:
- get_anchors()[source]¶
Returns the anchors of the curves forming the VMobject.
- Returns:
The anchors.
- Return type:
- 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:
list[Point3D_Array]
- get_arc_length(sample_points_per_curve=None)[source]¶
Return the approximated length of the whole curve.
- Parameters:
sample_points_per_curve (int | None) – 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
MobjectExamples
>>> from manim import Square, RED >>> Square(color=RED).get_color() == RED True
- Return type:
- get_curve_functions()[source]¶
Gets the functions for the curves of the mobject.
- Returns:
The functions for the curves.
- Return type:
Iterable[Callable[[float], Point3D]]
- 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:
Iterable[tuple[Callable[[float], Point3D], 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
Circleis counterclockwise:>>> from manim import Circle >>> Circle().get_direction() 'CCW'
- Returns:
Either
"CW"or"CCW".- Return type:
str
- get_end_anchors()[source]¶
Return the end anchors of the bezier curves.
- Returns:
Starting anchors
- Return type:
- get_fill_color()[source]¶
If there are multiple colors (for gradient) this returns the first one
- Return type:
- static get_mobject_type_class()[source]¶
Return the base class of this mobject type.
- Return type:
type[VMobject]
- 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:
Callable[float, Point3D]
- 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 (int | None) – The number of points to sample to find the length.
- Returns:
curve (Callable[[float], Point3D]) – The function for the nth curve.
length (
float) – The length of the nth curve.
- Return type:
tuple[Callable[[float], TypeAliasForwardRef(‘~manim.typing.Point3D’)], float]
- get_nth_curve_length(n, sample_points=None)[source]¶
Returns the (approximate) length of the nth curve.
- Parameters:
n (int) – The index of the desired curve.
sample_points (int | None) – The number of points to sample to find the length.
- Returns:
length – The length of the nth curve.
- Return type:
float
- get_nth_curve_length_pieces(n, sample_points=None)[source]¶
Returns the array of short line lengths used for length approximation.
- Parameters:
n (int) – The index of the desired curve.
sample_points (int | None) – The number of points to sample to find the length.
- Return type:
The short length-pieces of the nth curve.
- 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 defining the nth bezier curve (anchors, handles)
- Return type:
- 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
Mobjectto be transformed to or from self. Should by a point of the appropriate type- Parameters:
center (TypeAliasForwardRef('~manim.typing.Point3DLike') | None)
- Return type:
- get_start_anchors()[source]¶
Returns the start anchors of the bezier curves.
- Returns:
Starting anchors
- Return type:
- 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:
- get_subpaths()[source]¶
Returns subpaths formed by the curves of the VMobject.
Subpaths are ranges of curves with each pair of consecutive curves having their end/start points coincident.
- Returns:
subpaths.
- Return type:
list[CubicSpline]
- init_colors(propagate_colors=True)[source]¶
Initializes the colors.
Gets called upon creation. This is an empty method that can be implemented by subclasses.
- Parameters:
propagate_colors (bool)
- Return type:
Self
- insert_n_curves(n)[source]¶
Inserts n curves to the bezier curves of the vmobject.
- Parameters:
n (int) – Number of curves to insert.
- Returns:
self- Return type:
- 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 (BezierPathLike) – Starting points.
- Return type:
Points generated.
- 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
alphais not between 0 and 1.Exception – If the
VMobjecthas no points.
Example
Example: PointFromProportion ¶
from manim import * class PointFromProportion(Scene): def construct(self): line = Line(2*DL, 2*UR) self.add(line) colors = (RED, BLUE, YELLOW) proportions = (1/4, 1/2, 3/4) for color, proportion in zip(colors, proportions): self.add(Dot(color=color).move_to( line.point_from_proportion(proportion) ))
class PointFromProportion(Scene): def construct(self): line = Line(2*DL, 2*UR) self.add(line) colors = (RED, BLUE, YELLOW) proportions = (1/4, 1/2, 3/4) for color, proportion in zip(colors, proportions): self.add(Dot(color=color).move_to( line.point_from_proportion(proportion) ))
- pointwise_become_partial(vmobject, a, b)[source]¶
Given a 2nd
VMobjectvmobject, a lower boundaand an upper boundb, modify thisVMobject’s points to match the portion of the Bézier spline described byvmobject.pointswith the parametertbetweenaandb.
- proportion_from_point(point)[source]¶
Returns the proportion along the path of the
VMobjecta particular given point is at.- Parameters:
point (Point3DLike) – The Cartesian coordinates of the point which may or may not lie on the
VMobject- Returns:
The proportion along the path of the
VMobject.- Return type:
float
- Raises:
ValueError – If
pointdoes not lie on the curve.Exception – If the
VMobjecthas no points.
- resize_points(new_length, resize_func=<function resize_array>)[source]¶
Resize the array of anchor points and handles to have the specified size.
- Parameters:
new_length (int) – The new (total) number of points.
resize_func (Callable[[Point3D_Array, int], Point3D_Array]) – A function mapping a Numpy array (the points) and an integer (the target size) to a Numpy array. The default implementation is based on Numpy’s
resizefunction.
- Return type:
Self
- reverse_direction()[source]¶
Reverts the point direction by inverting the point order.
- Returns:
Returns self.
- Return type:
Examples
Example: ChangeOfDirection ¶
from manim import * class ChangeOfDirection(Scene): def construct(self): ccw = RegularPolygon(5) ccw.shift(LEFT) cw = RegularPolygon(5) cw.shift(RIGHT).reverse_direction() self.play(Create(ccw), Create(cw), run_time=4)
class ChangeOfDirection(Scene): def construct(self): ccw = RegularPolygon(5) ccw.shift(LEFT) 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, about_edge=None)[source]¶
Rotates the
Mobjectaround a specified axis and point.- Parameters:
angle (float) – The angle of rotation in radians. Predefined constants such as
DEGREEScan also be used to specify the angle in degrees.axis (Vector3DLike) – The rotation axis (see
Rotatingfor more).about_point (Point3DLike | None) – The point about which the mobject rotates. If
None, rotation occurs around the center of the mobject.about_edge (Vector3DLike | None) – The edge about which to apply the scaling.
- Returns:
self(for method chaining)- Return type:
Mobject
Note
To animate a rotation, use
RotatingorRotateinstead of.animate.rotate(...). The.animate.rotate(...)syntax only applies a transformation from the initial state to the final rotated state (interpolation between the two states), without showing proper rotational motion based on the angle (from 0 to the given angle).Examples
Example: RotateMethodExample ¶
from manim import * class RotateMethodExample(Scene): def construct(self): circle = Circle(radius=1, color=BLUE) line = Line(start=ORIGIN, end=RIGHT) arrow1 = Arrow(start=ORIGIN, end=RIGHT, buff=0, color=GOLD) group1 = VGroup(circle, line, arrow1) group2 = group1.copy() arrow2 = group2[2] arrow2.rotate(angle=PI / 4, about_point=arrow2.get_start()) group3 = group1.copy() arrow3 = group3[2] arrow3.rotate(angle=120 * DEGREES, about_point=arrow3.get_start()) self.add(VGroup(group1, group2, group3).arrange(RIGHT, buff=1))
class RotateMethodExample(Scene): def construct(self): circle = Circle(radius=1, color=BLUE) line = Line(start=ORIGIN, end=RIGHT) arrow1 = Arrow(start=ORIGIN, end=RIGHT, buff=0, color=GOLD) group1 = VGroup(circle, line, arrow1) group2 = group1.copy() arrow2 = group2[2] arrow2.rotate(angle=PI / 4, about_point=arrow2.get_start()) group3 = group1.copy() arrow3 = group3[2] arrow3.rotate(angle=120 * DEGREES, about_point=arrow3.get_start()) self.add(VGroup(group1, group2, group3).arrange(RIGHT, buff=1))
- 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 (Vector3DLike) – Axis of rotation.
family (bool)
- Return type:
Self
Examples
Normal usage:
Circle().set_sheen_direction(UP).rotate_sheen_direction(PI)
See also
- scale(scale_factor, scale_stroke=False, *, about_point=None, about_edge=None)[source]¶
Scale the size by a factor.
Default behavior is to scale about the center of the vmobject.
- Parameters:
scale_factor (float) – The scaling factor \(\alpha\). If \(0 < |\alpha| < 1\), the mobject will shrink, and for \(|\alpha| > 1\) it will grow. Furthermore, if \(\alpha < 0\), the mobject is also flipped.
scale_stroke (bool) – Boolean determining if the object’s outline is scaled when the object is scaled. If enabled, and object with 2px outline is scaled by a factor of .5, it will have an outline of 1px.
kwargs – Additional keyword arguments passed to
scale().about_point (Point3DLike | None)
about_edge (Vector3DLike | None)
- Returns:
self- Return type:
Examples
Example: MobjectScaleExample ¶
from manim import * class MobjectScaleExample(Scene): def construct(self): c1 = Circle(1, RED).set_x(-1) c2 = Circle(1, GREEN).set_x(1) vg = VGroup(c1, c2) vg.set_stroke(width=50) self.add(vg) self.play( c1.animate.scale(.25), c2.animate.scale(.25, scale_stroke=True) )
class MobjectScaleExample(Scene): def construct(self): c1 = Circle(1, RED).set_x(-1) c2 = Circle(1, GREEN).set_x(1) vg = VGroup(c1, c2) vg.set_stroke(width=50) self.add(vg) self.play( c1.animate.scale(.25), c2.animate.scale(.25, scale_stroke=True) )See also
move_to()
- 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:
self- Return type:
- 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:
self- Return type:
- Parameters:
anchors1 (Point3DLike_Array)
handles1 (Point3DLike_Array)
handles2 (Point3DLike_Array)
anchors2 (Point3DLike_Array)
- set_cap_style(cap_style)[source]¶
Sets the cap style of the
VMobject.- Parameters:
cap_style (CapStyleType) – The cap style to be set. See
CapStyleTypefor options.- Returns:
self- Return type:
Examples
Example: CapStyleExample ¶
from manim import * class CapStyleExample(Scene): def construct(self): line = Line(LEFT, RIGHT, color=YELLOW, stroke_width=20) line.set_cap_style(CapStyleType.ROUND) self.add(line)
class CapStyleExample(Scene): def construct(self): line = Line(LEFT, RIGHT, color=YELLOW, stroke_width=20) line.set_cap_style(CapStyleType.ROUND) self.add(line)
- 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
- Parameters:
color (ParsableManimColor)
family (bool)
- Return type:
Self
- set_fill(color=None, opacity=None, family=True)[source]¶
Set the fill color and fill opacity of a
VMobject.- Parameters:
color (ParsableManimColor | None) – Fill color of the
VMobject.opacity (float | None) – Fill opacity of the
VMobject.family (bool) – If
True, the fill color of all submobjects is also set.
- Returns:
self- Return type:
Examples
Example: SetFill ¶
from manim import * class SetFill(Scene): def construct(self): square = Square().scale(2).set_fill(WHITE,1) circle1 = Circle().set_fill(GREEN,0.8) circle2 = Circle().set_fill(YELLOW) # No fill_opacity circle3 = Circle().set_fill(color = '#FF2135', opacity = 0.2) group = Group(circle1,circle2,circle3).arrange() self.add(square) self.add(group)
class SetFill(Scene): def construct(self): square = Square().scale(2).set_fill(WHITE,1) circle1 = Circle().set_fill(GREEN,0.8) circle2 = Circle().set_fill(YELLOW) # No fill_opacity circle3 = Circle().set_fill(color = '#FF2135', opacity = 0.2) group = Group(circle1,circle2,circle3).arrange() self.add(square) self.add(group)See also
set_style()
- set_points_as_corners(points)[source]¶
Given an array of points, set them as corners of the
VMobject.To achieve that, this algorithm sets handles aligned with the anchors such that the resultant Bézier curve will be the segment between the two anchors.
- Parameters:
points (Point3DLike_Array) – Array of points that will be set as corners.
- Returns:
The VMobject itself, after setting the new points as corners.
- Return type:
Examples
Example: PointsAsCornersExample ¶
from manim import * class PointsAsCornersExample(Scene): def construct(self): corners = ( # create square UR, UL, DL, DR, UR, # create crosses DL, UL, DR ) vmob = VMobject(stroke_color=RED) vmob.set_points_as_corners(corners).scale(2) self.add(vmob)
class PointsAsCornersExample(Scene): def construct(self): corners = ( # create square UR, UL, DL, DR, UR, # create crosses DL, UL, DR ) vmob = VMobject(stroke_color=RED) vmob.set_points_as_corners(corners).scale(2) self.add(vmob)
- 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 (Vector3DLike | None) – Direction from where the gradient is applied.
family (bool)
- Return type:
Self
Examples
Example: SetSheen ¶
from manim import * class SetSheen(Scene): def construct(self): circle = Circle(fill_opacity=1).set_sheen(-0.3, DR) self.add(circle)
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 (Vector3DLike) – Direction from where the gradient is applied.
family (bool)
- Return type:
Self
Examples
Normal usage:
Circle().set_sheen_direction(UP)
See also
- start_new_path(point)[source]¶
Append a
pointto theVMobject.points, which will be the beginning of a new Bézier curve in the path given by the points. If there’s an unfinished curve at the end ofVMobject.points, complete it by appending the last Bézier curve’s start anchor as many times as needed.- Parameters:
point (Point3DLike) – A 3D point to append to
VMobject.points.- Returns:
The VMobject itself, after appending
pointand starting a new curve.- Return type: