What’s new¶
Usage changes of new version manim¶
There are many changes in the new version of manim, and here are only the changes that may have an impact at the code writing level.
Some of the changes here may not have any major impact on the use, and some changes that affect the use are not mentioned below.
This document is for reference only, see the source code for details.
AnimationAdded
Fadeas the parent class ofFadeInandFadeOutFadeInandFadeOutcan be passed inshiftandscaleparametersDeleted
FadeInFrom, FadeInFromDown, FadeOutAndShift, FadeOutAndShiftDown, FadeInFromLarge, these can be usedFadeIn, FadeOutto achieve the same effect more easilyAdded
FadeTransformto cross fade between two objects, and subclassFadeTransformPiecesAdded
CountInFrom(decimal_mob, source_number=0)to countdecimal_mobfromsource_numberto the current valueRotatingcan directly pass inangleandaxiswithout writing keywordsangle=, axis=Rotatehas become a subclass ofRotating, and the distortion effect inTransformwill not appearRemoved
MoveCaranimationAdded
TransformMatchingShapes(mobject, target_mobject)andTransformMatchingTex(mobject, target_mobject)
CameraRemoved all camera classes except
Camera(MappingCamera,MovingCamera,MultiCamera) and all functions inThreeDCameraImplemented
CameraFrame(as aMobject)Can be called by
self.camera.frameinSceneAll methods of
Mobjectcan be used, such as.shift(),.scale(), etc.Call
.to_default_state()to place in the default positionSet the Euler angles of the camera by
.set_euler_angles(theta, phi, gamma)Set three single Euler angles by
.set_theta(theta),.set_phi(phi),.set_gamma(gamma)Use
.increment_theta(dtheta),.increment_phi(dphi),.increment_gamma(gamma)to increase the three Euler angles by a certain value. Can be used to realize automatic rotationself.camera.frame.add_updater(lambda mob, dt: mob.increment_theta(0.1 * dt))
Cameraadds a light source, which is aPoint, which can be called byself.camera.light_sourceinSceneto move and so on. The default position is(- 10, 10, 10)
Delete
ContainerMobjectsvgrelatedAdded
CheckmarkandExmarkSome unnecessary classes have been removed from
drawings.pyRemoved
CodeandParagraph(by mistake)TexMobjectis renamed toTex,TextMobjectis renamed toTexTextfont_sizehas been added toTex,TexTextandTextTexandTexTextaddedisolate, which is a list, which will be automatically split
Mobject
typesAdded a new class
Surface, which is the parent class ofParametricSurfaceandTexturedSurface.Added the group
SGroupforSurfaceAdded
TexturedSurface(uv_surface, image_file, dark_image_file=None), whereuv_surfaceis aSurface,image_fileis the image to be posted, anddark_image_fileis the image to be posted in the dark (default andimage_fileis the same)Deleted
Mobject1D,Mobject2D,PointCloudDotAdded
DotCloud(aPMobject), which has been greatly optimizedRemoved
AbstractImageMobject,ImageMobjectFromCameraRemoved
sheenfromVMobject
MobjectAdded
glossandshadow, which are the numbers between[0, 1]respectively. There are four methods of.get_gloss(),.set_gloss(gloss),.get_shadow(),.set_shadow(shadow)Added
.get_grid(n_rows, n_cols)to copy into gridAdded
.set_color_by_code(glsl_code)to use GLSL code to change the colorAdded
.set_color_by_xyz_func(glsl_snippet, min_value=-5.0, max_value=5.0, colormap="viridis")to pass in GLSL expression in the form ofx,y,z, the return value should be a floating point number
Coordinate system (including
Axes,ThreeDAxes,NumberPlane,ComplexPlane)No longer use
x_min,x_max,y_min,y_max, but usex_range,y_rangeas anp.array(), containing three numbersnp.array([ Minimum, maximum, step size])Added the abbreviation
.i2gp(x, graph)of.input_to_graph_point(x, graph)Added some functions of the original
GraphSceneAdded
.get_v_line(point),.get_h_line(point)to return the line frompointto the two coordinate axes, and specify the line type through the keyword argument ofline_func(defaultDashedLine)Added
.get_graph_label(graph, label, x, direction, buff, color)to return the label added to the imageAdded
.get_v_line_to_graph(x, graph),.get_h_line_to_graph(x, graph)to return the line from the point with the abscissa ofxon thegraphto the two- axis lineAdded
.angle_of_tangent(x, graph, dx=EPSILON), returns the inclination angle ofgraphatxAdded
.slope_of_tangent(x, graph, dx=EPSILON), returns the slope of tangent line ofgraphatxAdded
.get_tangent_line(x, graph, length=5)to return the tangent line ofgraphatxAdded
.get_riemann_rectangles(graph, x_range, dx, input_sample_type, ...)to return Riemann rectangles (aVGroup)
The attribute
number_line_configofAxesis renamed toaxis_configAxesoriginal.get_coordinate_labels(x_values, y_values)method was renamed to.add_coordinate_labels(x_values, y_values)(but it is not added to the screen).add_coordinate_labels(numbers)ofComplexPlanewill directly add the coordinates to the screen
NumberLineNo longer use
x_min,x_max,tick_frequency, but usex_range, which is an array containing three numbers[min, max, step]The original
label_directionattribute changed to theline_to_number_directionattributeReplace
tip_widthandtip_heightwithtip_config(dictionary) attributesThe original
exclude_zero_from_defaultattribute is modified to thenumbers_to_excludeattribute (default is None)The original
.add_tick_marks()method was changed to the.add_ticks()methodDelete the
.get_number_mobjects(*numbers)method, only use the.add_numbers(x_values=None, excluding=None)method
Three-dimensional objects
Added
SurfaceMesh(uv_surface), pass in aSurfaceto generate its uv meshParametricSurfaceno longer usesu_min, u_max, v_min, v_max, but instead usesu_range, v_range, which is a tuple ((min, max)), andresolutioncan be set larger, don’t worry Speed issueAdded
Torus, controlled byr1, r2keyword parametersAdded
Cylinder, controlled byheight, radiuskeyword parametersAdded
Line3D(extremely thin cylinder), controlled by thewidthkeyword parameterAdded
Disk3D, controlled byradiuskeyword parameterAdd
Square3D, controlled byside_lengthkeyword parameterImproved
CubeandPrism, the usage remains unchanged
Other objects
ParametricFunctionis renamed toParametricCurve. Instead of usingt_min, t_max, step_size, uset_range, which is an array of three numbers ([t_min, t_max, step_size]).dtwas renamed toepsilon. Other usage remains unchangedAll
TipableVMobjectcan pass intip_lengthto control the style oftipLineadds.set_points_by_ends(start, end, buff=0, path_arc=0)methodLineadded.get_projection(point)to return the projection position ofpointon a straight lineArrowadds three attributes ofthickness, tip_width_ratio, tip_angleCubicBezieris changed toa0, h0, h1, a1, that is, only a third-order Bezier curve is supportedSquarecan be initialized directly by passing inside_lengthinstead of using the keywordside_length=always_redraw(func, *args, **kwargs)supports incoming parameters*args, **kwargsThe
digit_to_digit_buffproperty ofDecimalNumberhas been renamed todigit_buff_per_font_unit, and the.scale()method has been improvedValueTrackeraddsvalue_typeattribute, the default isnp.float64
SceneRemoved all functions of
GraphScene(moved toonce_useful_constructs),MovingCameraScene,ReconfigurableScene,SceneFromVideo,ZoomedScene, andThreeDScene. Because these can basically be achieved by adjustingCameraFrame(self.camera.frame)Currently
SampleSpaceSceneandVectorScenehave not been changed for the new version, so it is not recommended to use (onlySceneis recommended)Fix the export of gif, just use the
-ioption directlyAdded the
.interact()method, during which the mouse and keyboard can be used to continue the interaction, which will be executed by default after the scene endsAdded
.embed()method, open iPython terminal to enter interactive modeAdded
.save_state()method to save the current state of the sceneAdded
.restore()method to restore the entire scene to the saved state
utilsA series of functions related to second-order Bezier have been added to
utils/bezier.pyAdded a function to read color map from
matplotlibinutils/color.pyAdded a series of related functions for processing folders/custom styles/object families
resize_array,resize_preserving_order,resize_with_interpolationthree functions have been added toutils/iterables.pyThe definition of
smoothis updated inutils/rate_functions.pyclip(a, min_a, max_a)function has been added toutils/simple_functions.pySome functions have been improved in
utils/space_ops.py, some functions for space calculation, and functions for processing triangulation have been added
constantsFixed the aspect ratio of the screen to 16:9
Deleted the old gray series (
LIGHT_GREY,GREY,DARK_GREY,DARKER_GREY), added a new series of grayGREY_A~GREY_E