Location>code7788 >text

manim learning-by-doing - highlighting

Popularity:796 ℃/2024-12-19 17:49:56

This article introducesManimused inhighlightAnimation classes for certain content, mainly including:

  1. ApplyWave: animation class for graphics or text to produce continuous wave-like deformation, used to show the effect of fluctuations, parameters can be adjusted
  2. Circumscribe: Used to show the relationship between shapes and their peripheral shapes in a geometric scene, animating the generation of peripheral shapes around an object.
  3. Flash: create a blinking effect by quickly changing the visual attributes of an object, used to emphasize the object, the blinking parameter can be customized
  4. FocusOn: Can simulate the camera focus to guide the viewer to focus on a specific object, can set the focus speed, zoom ratio and other parameters
  5. Indicate: Indicate object parts or steps with arrows, lines, etc., customize the shape, color and dynamics of the indication.
  6. ShowPassingFlash: leave a short flash on the object's moving path, used to reflect the fast passing scene, flash parameters can be controlled
  7. Wiggle: makes the object shake randomly with small amplitude near the original position, used to simulate unstable states, the shake parameter can be adjusted

1. Overview of animation

1.1. ApplyWave

ApplyWaveDeforms the object in a continuous, fluid manner in a wave-like manner.

You can control the amplitude, frequency and other parameters of the wave, and by adjusting these parameters you can create wave effects of different strengths and styles.

This deformation effect is calculated based on the geometry of the object, so it works well for objects with complex shapes and ensures the smoothness of the deformation process.

It is very useful for creating dynamic and aesthetically pleasing presentations of mathematical functions or fluctuating phenomena (such as wave propagation in physics).

It can also be used for text, so that the text produces a visual effect similar to fluctuation on the water surface, used in some creative animation title display and other scenes.

Its main parameters are:

Parameter name typology clarification
mobject Mobject The Mobject object to be morphed
direction Waves drive the direction of shape points
amplitude float Distance moved by the shape point
wave_func func Define a function of the shape of a wave
time_width float Length of the wave relative to the width of the mobject
ripples int Number of ripples in the wave

1.2. Circumscribe

CircumscribeFocuses on highlighting the relationship between the object and its external graphics.

The animation process usually involves generating external graphics around the target object, and the speed and precision of the animation can be set.

In the process of generating an external graphic, the location and size of the external graphic will be determined based on the geometric characteristics of the object to ensure that the concept of externalization is accurately represented.

It is mainly used to show the relationship between shapes and external shapes.

For example, when explaining the outer circle of a triangle, you can use this animation effect to clearly show how the circle goes around the triangle and through its three vertices.

In addition, it can also be used for some other shapes that have the concept of external geometric shapes (e.g., the external ellipse of a quadrilateral, etc.), which can visually help viewers understand the geometric relationship of external connection.

Its main parameters are:

Parameter name typology instructions
mobject Mobject The Mobject object to be wrapped.
shape Type The shape used to surround the given Mobject, which can only be a rectangle (Rectangle) or round (Circle
fade_in bool Whether or not to fade in the surround shape
fade_out bool Whether or not to make the surround shape fade out
time_width float Time width for drawing and erasing
buff float Distance between the wraparound shape and the given Mobject
color Color Surrounding Shape Colors

1.3. Flash

Flashis characterized by quickly changing visual attributes such as the color or transparency of an object to produce a flickering effect.

You can customize the number of flashes, the frequency and the way the color changes.

When an object or part of an object needs to be emphasizedFlashVery useful.

For example, when demonstrating key elements in a complex mathematical model, or highlighting specific atoms or bonds in the structure of a chemical molecule, you can use theFlashto get the audience's attention.

Its main parameters are:

Parameter name typology clarification
point ndarray / Mobject The center point of the flashing line. If a Mobject is passed in, its center is used as the center point
line_length float Length of flashing lines
num_lines int Number of flashing lines
flash_radius float Distance point where the flashing line starts
line_stroke_width int Width of strokes for shimmering lines
color Color Color of flashing lines
time_width float Time width of flashing lines

1.4. FocusOn

FocusOnAble to simulate the effect of camera focus, shifting the center or focus of the picture to the target object.

You can set the speed of focusing, zoom ratio and other parameters to make the focusing process more natural.

It can be used to direct the viewer's attention to specific areas or objects in complex scenes or animations containing multiple objects.

Its main parameters are:

Parameter name typology clarification
focus_point ndarray / Mobject The point to which the spotlight shrinks to. If a Mobject is passed in, its center is used as the point of contraction
opacity float Spotlight opacity
color Color Spotlight color

1.5. Indicate

IndicateOften indicating the target with arrows, lines, or color changes, the

You can customize the shape, color, and dynamic effects of the indication (e.g., swinging arrows, flashing lines, etc.).

This kind of indication effect is relatively clear, can directly guide the viewer's eyes to the place that needs attention, and can be used in combination with other animation effects to enhance the effect of the indication.

It is often used in instructional animations to indicate a part of an object or to emphasize an action step.

Its main parameters are:

Parameter name typology clarification
mobject Mobject highlightedMobject
scale_factor float Mobject Scale factor for scaling when highlighted
color Color Mobject Highlight Color

1.6. ShowPassingFlash

ShowPassingFlashThe main purpose is to leave a brief flash effect on the path of the object moving, simulating the change of light and shadow when the object passes quickly.

Parameters such as flash color, duration and intensity can be controlled to suit different scene requirements.

It is generally used to show scenes where objects appear briefly or pass quickly.

Its main parameters are:

Parameter name typology clarification
mobject VMobject The object to which this animation effect is to be applied
time_width float Relative to the length of the flash portion of the stroke length, this parameter controls the proportionate size of the portion of the object displayed in each frame

1.7. Wiggle

WiggleThe object can be made to sway randomly with a small amplitude near its original position, and parameters such as the amplitude, frequency and direction of the swaying can be adjusted.

The shaking effect looks more natural, not that regular movement, and is able to simulate instability or trembling very well, and doesn't make the object deviate too far from its original position, maintaining some overall stability.

It is used to add an unsteady, slightly wobbly effect to an object.

Its main parameters are:

Parameter name typology clarification
mobject Mobject Mobject object to be swung
scale_value float Mobject Scaling factor for oscillations
rotation_angle float swing angle
n_wiggles int Number of oscillations
scale_about_point ndarray Mobject The center point of the zoom
rotate_about_point ndarray Mobject Center point of rotation

2. Examples of use

The following examples demonstrate the use of each highlight class animation.

2.1. ApplyWave Example

First create a text objectTextThen demonstrate separatelyApplyWave The effect of different parameter settings.

  1. The first time the default parameters are used, showing the basic wave deformation effect
  2. The second time the direction is specified as to the right (RIGHT), a time width of 0.5, and an amplitude of 0.3, and observe the effect of these parameters on the animation
  3. The third time the rate function was set to be linear (linear) and the number of ripples is 4 to see the effect at linear rate and number of ripples.
  4. The fourth sets the rate function to be nonlinear (rush_into) and the number of ripples is 4 to see the effect at nonlinear rate and number of ripples
# Create a text object
t = Text("Hello, Manim!").scale(1.5)
(t)

# ApplyWave with default parameters
(ApplyWave(t)
()

# ApplyWave with specified direction time width and amplitude
(
    ApplyWave(
        ApplyWave(
        direction=RIGHT,
        time_width=0.5,
        amplitude=0.3, ), ApplyWave(
    ),
)
()

# Linear ripple
(
    ApplyWave(
        t,
        rate_func=linear,
        ripples=4, .
    ),
)
()

# Nonlinear ripples
(
    ApplyWave(
        t,
        wave_func=rush_into,
        ripples=4,
    ),
)

2.2 Circumscribe example

First create arectanglesAnd then forrectanglesSeparate demonstrations of theCircumscribeThe effect of different parameter settings of the

For example, the default parameters, specifying the shape as a circle, fade-in, fade-out, and theCircumscribeSpacing from the rectanglebuffAnd so on.

# Creating a Rectangle
rect = Rectangle(width=3, height=2)
(rect)

# The default parameters of theCircumscribe
(Circumscribe(rect))
()

# Specify the shape of the roundCircumscribe
(Circumscribe(rect, Circle))
()

# fade-in effect
(
    Circumscribe(
        rect,
        fade_in=True,
        buff=0.1,
        color=RED,
    )
)
()

# fade-out effect
(
    Circumscribe(
        rect,
        fade_out=True,
        buff=0.3,
        color=GREEN,
    )
)

2.3. Flash example

First create apoint (in space or time)and aunit of Chinese currency (Yuan)And then forpoint (in space or time)respond in singingunit of Chinese currency (Yuan)Separate demonstrations of theFlash The effect of different parameter settings of the

with regards topoint (in space or time), showing the default parameters of theFlash Effect;

with regards tounit of Chinese currency (Yuan)The following shows, in turn, the designation of theLine lengthquantitiescolorstarting radiusline widthtime lagpeacerate function (math.)The effect of parameters such as.

# Create a dot and a circle
dot = Dot().shift(UP * 2)
circle = Circle(radius=1)
(dot, circle)

# Default parameter Flash
(Flash(dot))
()

# Specify the line length Quantity and color of Flash
(
    Flash(
        circle, line_length=0.5, line_color
        line_length=0.5,
        num_lines=20,
        color=YELLOW.
    )
)
()

# Specify the starting radius and line width of Flash
(
    Flash(
        circle,
        line_stroke_width=5, flash_radius=1.5,
        flash_radius=1.5,
    )
)
()

# Flash for the specified rate function
(
    Flash(
        circle,
        rate_func=rush_into,
        time_width=2, )
    )
)

2.4. FocusOn Example

First create asquareAnd then forsquareSeparate demonstrations of theFocusOnThe effect of different parameter settings of the

In addition to the default parameters, show that specifying theopacityand designationcolorThe effect of the

# Create a square and a triangle
square = Square()
(square)

# FocusOn with default parameters
(FocusOn(square))
()

# FocusOn with specified opacity
(FocusOn(square, opacity=0.8))
()

# FocusOn with specified color
(FocusOn(square, color=RED))

2.5. Indicate example

First create atext objectand aorbicularAnd then forcopiesrespond in singingorbicularseparate demonstrationsIndicateThe effect of different parameter settings of the

For example, specifyingzoom ratioFactor, Designationcolorand the designation ofrate function (math.)The effect of the

# Create a text object and a circle
text = Text("Indicate Me!").shift(UP * 2)
circle = Circle(radius=1)
(text, circle)

# The default parameters of theIndicate
(Indicate(text), Indicate(circle))
()

# Specify the scaling factor of theIndicate
(
    Indicate(text, scale_factor=1.5),
    Indicate(circle, scale_factor=1.5),
)
()

# color-specificIndicate
(
    Indicate(text, color=GREEN),
    Indicate(circle, color=BLUE),
)
()

# different rate functions of theIndicate
(
    Indicate(text, rate_func=there_and_back),
    Indicate(circle, rate_func=there_and_back_with_pause),
)

2.6. ShowPassingFlash Example

First create aregular pentagonThen demonstrateShowPassingFlashdifferenttime_widthThe effect of the next.

# Create a polygon as an example graphic
p = RegularPolygon(n=5, color=GRAY).scale(2)
(p)

colors = [RED, BLUE, GREEN]
time_widths = [0.5, 1, 2]

# Effect of different time_width parameters
for idx, tw in enumerate(time_widths).
    (
        ShowPassingFlash(
            ().set_color(colors[idx]),
            time_width=tw,
            run_time=2, )
        )
    )
    ()

2.7. Wiggle example

First atext objectand arectanglesThen demonstrate separatelyWiggle(used form a nominal expression)default parameterscale_valueparameters.rotation_angle parameters.n_wigglesparameters andscale_about_point respond in singingrotate_about_pointThe effect of the use of the parameter.

# Create a text object and a rectangle as example graphics
t = Text("Wiggle Example").shift(UP)
r = Rectangle(width=2, height=1).shift(DOWN)
(t, r)

# under the default parametersWiggle
(Wiggle(t), Wiggle(r))
()

# indicate clearly and with certaintyscale_valueparameters
(
    Wiggle(t, scale_value=1.3),
    Wiggle(r, scale_value=1.5),
)
()

# indicate clearly and with certaintyrotation_angleparameters
(
    Wiggle(t, rotation_angle= / 4),
    Wiggle(r, rotation_angle= / 3),
)
()

# indicate clearly and with certaintyn_wigglesparameters
(
    Wiggle(t, n_wiggles=4),
    Wiggle(r, n_wiggles=8),
)
()

# indicate clearly and with certaintyscale_about_pointcap (a poem)rotate_about_pointparameters
(
    Wiggle(
        r,
        scale_about_point=r.get_center(),
        rotate_about_point=r.get_corner(UR),
    )
)

3. Annexes

The code in the article is just an extract of the key parts, the complete code is shared on a web disk (),

Download at.Full Code (Access code: 6872)