速率函数

一系列速率函数,即动画的速度曲线。请在https://easings.net/找到标准列表。这里是非标准函数的图片

示例:RateFuncExample

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

class RateFuncExample(Scene):
    def construct(self):
        x = VGroup()
        for k, v in rate_functions.__dict__.items():
            if "function" in str(v):
                if (
                    not k.startswith("__")
                    and not k.startswith("sqrt")
                    and not k.startswith("bezier")
                ):
                    try:
                        rate_func = v
                        plot = (
                            ParametricFunction(
                                lambda x: [x, rate_func(x), 0],
                                t_range=[0, 1, .01],
                                use_smoothing=False,
                                color=YELLOW,
                            )
                            .stretch_to_fit_width(1.5)
                            .stretch_to_fit_height(1)
                        )
                        plot_bg = SurroundingRectangle(plot).set_color(WHITE)
                        plot_title = (
                            Text(rate_func.__name__, weight=BOLD)
                            .scale(0.5)
                            .next_to(plot_bg, UP, buff=0.1)
                        )
                        x.add(VGroup(plot_bg, plot, plot_title))
                    except: # because functions `not_quite_there`, `function squish_rate_func` are not working.
                        pass
        x.arrange_in_grid(cols=8)
        x.height = config.frame_height
        x.width = config.frame_width
        x.move_to(ORIGIN).scale(0.95)
        self.add(x)
class RateFuncExample(Scene):
    def construct(self):
        x = VGroup()
        for k, v in rate_functions.__dict__.items():
            if "function" in str(v):
                if (
                    not k.startswith("__")
                    and not k.startswith("sqrt")
                    and not k.startswith("bezier")
                ):
                    try:
                        rate_func = v
                        plot = (
                            ParametricFunction(
                                lambda x: [x, rate_func(x), 0],
                                t_range=[0, 1, .01],
                                use_smoothing=False,
                                color=YELLOW,
                            )
                            .stretch_to_fit_width(1.5)
                            .stretch_to_fit_height(1)
                        )
                        plot_bg = SurroundingRectangle(plot).set_color(WHITE)
                        plot_title = (
                            Text(rate_func.__name__, weight=BOLD)
                            .scale(0.5)
                            .next_to(plot_bg, UP, buff=0.1)
                        )
                        x.add(VGroup(plot_bg, plot, plot_title))
                    except: # because functions `not_quite_there`, `function squish_rate_func` are not working.
                        pass
        x.arrange_in_grid(cols=8)
        x.height = config.frame_height
        x.width = config.frame_width
        x.move_to(ORIGIN).scale(0.95)
        self.add(x)

主要有3种标准缓动函数

  1. 缓入 (Ease In) - 动画平滑启动。

  2. 缓出 (Ease Out) - 动画平滑结束。

  3. 缓入缓出 (Ease In Out) - 动画平滑启动且平滑结束。

注意

标准函数未导出,因此要使用它们,您需要这样做:rate_func=rate_functions.ease_in_sine 另一方面,更常用的非标准函数已导出,可以直接使用。

示例:RateFunctions1Example

from manim import *

class RateFunctions1Example(Scene):
    def construct(self):
        line1 = Line(3*LEFT, 3*RIGHT).shift(UP).set_color(RED)
        line2 = Line(3*LEFT, 3*RIGHT).set_color(GREEN)
        line3 = Line(3*LEFT, 3*RIGHT).shift(DOWN).set_color(BLUE)

        dot1 = Dot().move_to(line1.get_left())
        dot2 = Dot().move_to(line2.get_left())
        dot3 = Dot().move_to(line3.get_left())

        label1 = Tex("Ease In").next_to(line1, RIGHT)
        label2 = Tex("Ease out").next_to(line2, RIGHT)
        label3 = Tex("Ease In Out").next_to(line3, RIGHT)

        self.play(
            FadeIn(VGroup(line1, line2, line3)),
            FadeIn(VGroup(dot1, dot2, dot3)),
            Write(VGroup(label1, label2, label3)),
        )
        self.play(
            MoveAlongPath(dot1, line1, rate_func=rate_functions.ease_in_sine),
            MoveAlongPath(dot2, line2, rate_func=rate_functions.ease_out_sine),
            MoveAlongPath(dot3, line3, rate_func=rate_functions.ease_in_out_sine),
            run_time=7
        )
        self.wait()
class RateFunctions1Example(Scene):
    def construct(self):
        line1 = Line(3*LEFT, 3*RIGHT).shift(UP).set_color(RED)
        line2 = Line(3*LEFT, 3*RIGHT).set_color(GREEN)
        line3 = Line(3*LEFT, 3*RIGHT).shift(DOWN).set_color(BLUE)

        dot1 = Dot().move_to(line1.get_left())
        dot2 = Dot().move_to(line2.get_left())
        dot3 = Dot().move_to(line3.get_left())

        label1 = Tex("Ease In").next_to(line1, RIGHT)
        label2 = Tex("Ease out").next_to(line2, RIGHT)
        label3 = Tex("Ease In Out").next_to(line3, RIGHT)

        self.play(
            FadeIn(VGroup(line1, line2, line3)),
            FadeIn(VGroup(dot1, dot2, dot3)),
            Write(VGroup(label1, label2, label3)),
        )
        self.play(
            MoveAlongPath(dot1, line1, rate_func=rate_functions.ease_in_sine),
            MoveAlongPath(dot2, line2, rate_func=rate_functions.ease_out_sine),
            MoveAlongPath(dot3, line3, rate_func=rate_functions.ease_in_out_sine),
            run_time=7
        )
        self.wait()

函数

double_smooth(t)[source]
参数:

t (浮点数)

返回类型:

浮点数

ease_in_back(t)[source]
参数:

t (浮点数)

返回类型:

浮点数

ease_in_bounce(t)[source]
参数:

t (浮点数)

返回类型:

浮点数

ease_in_circ(t)[source]
参数:

t (浮点数)

返回类型:

浮点数

ease_in_cubic(t)[source]
参数:

t (浮点数)

返回类型:

浮点数

ease_in_elastic(t)[source]
参数:

t (浮点数)

返回类型:

浮点数

ease_in_expo(t)[source]
参数:

t (浮点数)

返回类型:

浮点数

ease_in_out_back(t)[source]
参数:

t (浮点数)

返回类型:

浮点数

ease_in_out_bounce(t)[source]
参数:

t (浮点数)

返回类型:

浮点数

ease_in_out_circ(t)[source]
参数:

t (浮点数)

返回类型:

浮点数

ease_in_out_cubic(t)[source]
参数:

t (浮点数)

返回类型:

浮点数

ease_in_out_elastic(t)[source]
参数:

t (浮点数)

返回类型:

浮点数

ease_in_out_expo(t)[source]
参数:

t (浮点数)

返回类型:

浮点数

ease_in_out_quad(t)[source]
参数:

t (浮点数)

返回类型:

浮点数

ease_in_out_quart(t)[source]
参数:

t (浮点数)

返回类型:

浮点数

ease_in_out_quint(t)[source]
参数:

t (浮点数)

返回类型:

浮点数

ease_in_out_sine(t)[source]
参数:

t (浮点数)

返回类型:

浮点数

ease_in_quad(t)[source]
参数:

t (浮点数)

返回类型:

浮点数

ease_in_quart(t)[source]
参数:

t (浮点数)

返回类型:

浮点数

ease_in_quint(t)[source]
参数:

t (浮点数)

返回类型:

浮点数

ease_in_sine(t)[source]
参数:

t (浮点数)

返回类型:

浮点数

ease_out_back(t)[source]
参数:

t (浮点数)

返回类型:

浮点数

ease_out_bounce(t)[source]
参数:

t (浮点数)

返回类型:

浮点数

ease_out_circ(t)[source]
参数:

t (浮点数)

返回类型:

浮点数

ease_out_cubic(t)[source]
参数:

t (浮点数)

返回类型:

浮点数

ease_out_elastic(t)[source]
参数:

t (浮点数)

返回类型:

浮点数

ease_out_expo(t)[source]
参数:

t (浮点数)

返回类型:

浮点数

ease_out_quad(t)[source]
参数:

t (浮点数)

返回类型:

浮点数

ease_out_quart(t)[source]
参数:

t (浮点数)

返回类型:

浮点数

ease_out_quint(t)[source]
参数:

t (浮点数)

返回类型:

浮点数

ease_out_sine(t)[source]
参数:

t (浮点数)

返回类型:

浮点数

exponential_decay(t, half_life=0.1)[source]
参数:
  • t (浮点数)

  • half_life (浮点数)

返回类型:

浮点数

linear(t)[source]
参数:

t (浮点数)

返回类型:

浮点数

lingering(t)[source]
参数:

t (浮点数)

返回类型:

浮点数

not_quite_there(func=<function smooth>, proportion=0.7)[source]
参数:
返回类型:

速率函数

running_start(t, pull_factor=-0.5)[source]
参数:
  • t (浮点数)

  • pull_factor (浮点数)

返回类型:

浮点数

rush_from(t, inflection=10.0)[source]
参数:
  • t (浮点数)

  • inflection (浮点数)

返回类型:

浮点数

rush_into(t, inflection=10.0)[source]
参数:
  • t (浮点数)

  • inflection (浮点数)

返回类型:

浮点数

slow_into(t)[source]
参数:

t (浮点数)

返回类型:

浮点数

smooth(t, inflection=10.0)[source]
参数:
  • t (浮点数)

  • inflection (浮点数)

返回类型:

浮点数

smoothererstep(t)[source]

三阶平滑阶跃(SmoothStep)S形函数的实现。其一阶、二阶和三阶导数(速度、加速度和加加速度)在端点处均为零。https://en.wikipedia.org/wiki/Smoothstep

参数:

t (浮点数)

返回类型:

浮点数

smootherstep(t)[source]

二阶平滑阶跃(SmoothStep)S形函数的实现。其一阶和二阶导数(速度和加速度)在端点处均为零。https://en.wikipedia.org/wiki/Smoothstep

参数:

t (浮点数)

返回类型:

浮点数

smoothstep(t)[source]

一阶平滑阶跃(SmoothStep)S形函数的实现。其一阶导数(速度)在端点处为零。https://en.wikipedia.org/wiki/Smoothstep

参数:

t (浮点数)

返回类型:

浮点数

squish_rate_func(func, a=0.4, b=0.6)[source]
参数:
返回类型:

速率函数

there_and_back(t, inflection=10.0)[source]
参数:
  • t (浮点数)

  • inflection (浮点数)

返回类型:

浮点数

there_and_back_with_pause(t, pause_ratio=0.3333333333333333)[source]
参数:
  • t (浮点数)

  • pause_ratio (浮点数)

返回类型:

浮点数

unit_interval(function)[source]
参数:

function (速率函数)

返回类型:

速率函数

wiggle(t, wiggles=2)[source]
参数:
  • t (浮点数)

  • wiggles (浮点数)

返回类型:

浮点数

zero(function)[source]
参数:

function (速率函数)

返回类型:

速率函数