跳转至

maliang.animation.controllers

字数 222 个   代码 31 行   阅读时间 1 分钟   访问量

源代码:maliang/animation/controllers.py

Controller generator and standard control functions.

Definition of control function:

def f(t: float) -> float: ...
  • t: 0% ~ 100%, indicates the percentage of time
  • return: real number, indicates a multiple of the cardinality of the animation

🔵_map_t

function protected

1
2
3
4
def _map_t(
    start: float,
    end: float,
) -> collections.abc.Callable[[float], float]: ...
Map parameters in any range between 0 and 1.

  • start: the first value of the parameter of the base function
  • end: the last value of the parameter of the base function

🔵_map_y

function protected

1
2
3
4
def _map_y(
    base: collections.abc.Callable[[float], float],
    end: float,
) -> collections.abc.Callable[[float], float]: ...
Map the final return value to 1.

  • base: base function
  • end: the last value of the parameter of the base function

🔵ease_in

function public

1
2
3
def ease_in(
    t: float,
) -> float: ...
Gradually accelerate. (slow -> fast)

  • t: the percentage of time

🔵ease_out

function public

1
2
3
def ease_out(
    t: float,
) -> float: ...
Gradually decelerate. (fast -> slow)

  • t: the percentage of time

🔵generate

function public

1
2
3
4
5
6
7
def generate(
    base: collections.abc.Callable[[float], float],
    start: float,
    end: float,
    *,
    map_y: bool = True,
) -> collections.abc.Callable[[float], float]: ...
Generate a control function from an ordinary mathematical function.

  • base: base function, an ordinary mathematical function
  • start: the first value of the parameter of the base function
  • end: the last value of the parameter of the base function
  • map_y: whether map the final return value to 1

🔵linear

function public

1
2
3
def linear(
    t: float,
) -> float: ...
Speed remains the same.

  • t: the percentage of time

🔵rebound

function public

1
2
3
def rebound(
    t: float,
) -> float: ...
Before the end, displacement will bounce off a bit.

  • t: the percentage of time

🔵smooth

function public

1
2
3
def smooth(
    t: float,
) -> float: ...
Speed is slow first, then fast and then slow. (slow -> fast -> slow)

  • t: the percentage of time