跳转至

tkintertools.animation.controllers

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

Standard control functions

Definition of control function:

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

The built-in control functions are:

  • flat: speed remains the same
  • smooth: speed is slow first, then fast and then slow
  • rebound: before the end, displacement will bounce off a bit

🔵_map_t

function protected

1
2
3
4
def _map_t(
    start: float,
    end: float,
) -> typing.Callable[[float], float]: ...

Map parameters in any range between 0 and 1

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

🔵_map_y

function protected

1
2
3
4
def _map_y(
    base_function: typing.Callable[[float], float],
    end: float,
) -> typing.Callable[[float], float]: ...

Map the final return value to 1

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

🔵controller_generator

function public

1
2
3
4
5
6
7
def controller_generator(
    base_function: typing.Callable[[float], float],
    start: float,
    end: float,
    *,
    map_y: bool = True,
) -> typing.Callable[[float], float]: ...

Generator of control functions

Modify the generic function to a control function suitable for animation

  • base_function: base function
  • start: the first value of the parameter of control function
  • end: the last value of the parameter of control function
  • map_y: whether map the final return value to 1

For example:

  • Before modifying: \(y = 2\sint, 0 <= t <= \pi/2\)
  • After modifying: \(y = \sin\frac{\pi}{2}t, 0 <= t <= 1\)

🔵flat

function public

1
2
3
def flat(
    t: float,
) -> float: ...
Flat animation: speed remains the same

🔵rebound

function public

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

🔵smooth

function public

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