跳转至

maliang.animation

字数 11 个   阅读时间不到 1 分钟   访问量

源代码:maliang/animation/__init__.py

A subpackage that provides animation-related features.

A highly customizable animation base class and related subclasses are provided, as well as highly customizable control functions. In addition, control functions also applies to the related functions of the color subpackage.

模块:

  • animations

    Base and standard animation classes.

  • controllers

    Controller generator and standard control functions.

类:

  • Animation

    Base animation class.

  • MoveWindow

    Animation of moving the window.

  • MoveTkWidget

    Animation of moving tkinter.Widget.

  • MoveWidget

    Animation of moving virtual.Widget.

  • MoveElement

    Animation of moving virtual.Element.

  • MoveItem

    Animation of moving a item of tkinter.Canvas.

  • GradientTkWidget

    Animation of making the color of tkinter.Widget to be gradient.

  • GradientItem

    Animation of making the color of canvas item to be gradient.

  • ScaleFontSize

    Animation of scaling the font size of virtual.Text.

函数:

  • generate

    Generate a control function from an ordinary mathematical function.

  • linear

    Speed remains the same.

  • smooth

    Speed is slow first, then fast and then slow. (slow -> fast -> slow)

  • rebound

    Before the end, displacement will bounce off a bit.

  • ease_in

    Gradually accelerate. (slow -> fast)

  • ease_out

    Gradually decelerate. (fast -> slow)

Animation

Animation(
    duration: int,
    command: collections.abc.Callable[[float], typing.Any],
    *,
    controller: collections.abc.Callable[[float], float] = controllers.linear,
    end: collections.abc.Callable[[], typing.Any] | None = None,
    fps: int = 30,
    repeat: int = 0,
    repeat_delay: int = 0,
    derivation: bool = False
)

Base animation class.

  • duration: duration of the animation, in milliseconds
  • command: callback function, which will be called once per frame
  • controller: a function that controls the animation process
  • end: end function, which is called once at the end of the animation
  • fps: frame rate of the animation
  • repeat: number of repetitions of the animation
  • repeat_delay: length of the delay before the animation repeats
  • derivation: whether the callback function is derivative

方法:

  • start

    Start the animation.

  • stop

    Stop the animation.

  • skip

    Skip some loops.

属性:

  • active (bool) –

    Returns the active state of the animation.

  • count (int) –

    Returns the number of loops remaining.

active property

active: bool

Returns the active state of the animation.

count property

count: int

Returns the number of loops remaining.

start

start() -> None
start(*, delay: int) -> str
start(*, delay: int = 0) -> str | None

Start the animation.

  • delay: length of the delay before the animation starts

stop

stop() -> None
stop(*, delay: int) -> str
stop(*, delay: int = 0) -> str | None

Stop the animation.

  • delay: length of the delay before the animation stops

skip

skip(count: int = 1) -> None

Skip some loops.

  • count: count of skipping

MoveWindow

MoveWindow(
    window: tkinter.Tk | tkinter.Toplevel | containers.Tk | containers.Toplevel,
    offset: tuple[float, float],
    duration: int,
    *,
    controller: collections.abc.Callable[[float], float] = controllers.linear,
    end: collections.abc.Callable[[], typing.Any] | None = None,
    fps: int = 30,
    repeat: int = 0,
    repeat_delay: int = 0
)

Bases: Animation

Animation of moving the window.

  • window: the window to be moved
  • offset: relative offset of the coordinates
  • duration: duration of the animation, in milliseconds
  • controller: a function that controls the animation process
  • end: end function, which is called once at the end of the animation
  • fps: frame rate of the animation
  • repeat: number of repetitions of the animation
  • repeat_delay: length of the delay before the animation repeats

MoveTkWidget

MoveTkWidget(
    widget: tkinter.Widget,
    offset: tuple[float, float],
    duration: int,
    *,
    controller: collections.abc.Callable[[float], float] = controllers.linear,
    end: collections.abc.Callable[[], typing.Any] | None = None,
    fps: int = 30,
    repeat: int = 0,
    repeat_delay: int = 0
)

Bases: Animation

Animation of moving tkinter.Widget.

  • widget: the tkinter.Widget to be moved
  • offset: relative offset of the coordinates
  • duration: duration of the animation, in milliseconds
  • controller: a function that controls the animation process
  • end: end function, which is called once at the end of the animation
  • fps: frame rate of the animation
  • repeat: number of repetitions of the animation
  • repeat_delay: length of the delay before the animation repeats

MoveWidget

MoveWidget(
    widget: virtual.Widget,
    offset: tuple[float, float],
    duration: int,
    *,
    controller: collections.abc.Callable[[float], float] = controllers.linear,
    end: collections.abc.Callable[[], typing.Any] | None = None,
    fps: int = 30,
    repeat: int = 0,
    repeat_delay: int = 0
)

Bases: Animation

Animation of moving virtual.Widget.

  • widget: the virtual.Widget to be moved
  • offset: relative offset of the coordinates
  • duration: duration of the animation, in milliseconds
  • controller: a function that controls the animation process
  • end: end function, which is called once at the end of the animation
  • fps: frame rate of the animation
  • repeat: number of repetitions of the animation
  • repeat_delay: length of the delay before the animation repeats

MoveElement

MoveElement(
    element: virtual.Element,
    offset: tuple[float, float],
    duration: int,
    *,
    controller: collections.abc.Callable[[float], float] = controllers.linear,
    end: collections.abc.Callable[[], typing.Any] | None = None,
    fps: int = 30,
    repeat: int = 0,
    repeat_delay: int = 0
)

Bases: Animation

Animation of moving virtual.Element.

  • element: the virtual.Element to be moved
  • offset: relative offset of the coordinates
  • duration: duration of the animation, in milliseconds
  • controller: a function that controls the animation process
  • end: end function, which is called once at the end of the animation
  • fps: frame rate of the animation
  • repeat: number of repetitions of the animation
  • repeat_delay: length of the delay before the animation repeats

MoveItem

MoveItem(
    canvas: tkinter.Canvas | containers.Canvas,
    item: int,
    offset: tuple[float, float],
    duration: int,
    *,
    controller: collections.abc.Callable[[float], float] = controllers.linear,
    end: collections.abc.Callable[[], typing.Any] | None = None,
    fps: int = 30,
    repeat: int = 0,
    repeat_delay: int = 0
)

Bases: Animation

Animation of moving a item of tkinter.Canvas.

  • canvas: an instance of tkinter.Canvas that contains the item
  • item: the item to be moved
  • offset: relative offset of the coordinates
  • duration: duration of the animation, in milliseconds
  • controller: a function that controls the animation process
  • end: end function, which is called once at the end of the animation
  • fps: frame rate of the animation
  • repeat: number of repetitions of the animation
  • repeat_delay: length of the delay before the animation repeats

GradientTkWidget

GradientTkWidget(
    widget: tkinter.Widget,
    parameter: str,
    colors: tuple[str, str],
    duration: int,
    *,
    controller: collections.abc.Callable[[float], float] = controllers.linear,
    end: collections.abc.Callable[[], typing.Any] | None = None,
    fps: int = 30,
    repeat: int = 0,
    repeat_delay: int = 0,
    derivation: bool = False
)

Bases: Animation

Animation of making the color of tkinter.Widget to be gradient.

  • widget: the tkinter.Widget whose color is to be gradient
  • parameter: parameter name of widget that is to be modified in color
  • colors: a tuple of the initial and ending colors
  • duration: duration of the animation, in milliseconds
  • controller: a function that controls the animation process
  • end: end function, which is called once at the end of the animation
  • fps: frame rate of the animation
  • repeat: number of repetitions of the animation
  • repeat_delay: length of the delay before the animation repeats
  • derivation: whether the callback function is derivative

GradientItem

GradientItem(
    canvas: tkinter.Canvas | containers.Canvas,
    item: int,
    parameter: str,
    colors: tuple[str, str],
    duration: int,
    *,
    controller: collections.abc.Callable[[float], float] = controllers.linear,
    end: collections.abc.Callable[[], typing.Any] | None = None,
    fps: int = 30,
    repeat: int = 0,
    repeat_delay: int = 0,
    derivation: bool = False
)

Bases: Animation

Animation of making the color of canvas item to be gradient.

  • canvas: an instance of tkinter.Canvas that contains the item
  • item: item whose color is to be gradient
  • parameter: parameter name of item that is to be modified in color
  • colors: a tuple of the initial and ending colors
  • duration: duration of the animation, in milliseconds
  • controller: a function that controls the animation process
  • end: end function, which is called once at the end of the animation
  • fps: frame rate of the animation
  • repeat: number of repetitions of the animation
  • repeat_delay: length of the delay before the animation repeats
  • derivation: whether the callback function is derivative

ScaleFontSize

ScaleFontSize(
    text: virtual.Text,
    sizes: float,
    duration: int,
    *,
    controller: collections.abc.Callable[[float], float] = controllers.linear,
    end: collections.abc.Callable[[], typing.Any] | None = None,
    fps: int = 30,
    repeat: int = 0,
    repeat_delay: int = 0,
    derivation: bool = False
)
ScaleFontSize(
    text: virtual.Text,
    sizes: tuple[float, float],
    duration: int,
    *,
    controller: collections.abc.Callable[[float], float] = controllers.linear,
    end: collections.abc.Callable[[], typing.Any] | None = None,
    fps: int = 30,
    repeat: int = 0,
    repeat_delay: int = 0,
    derivation: bool = False
)
ScaleFontSize(
    text: virtual.Text,
    sizes: float | tuple[float, float],
    duration: int,
    *,
    controller: collections.abc.Callable[[float], float] = controllers.linear,
    end: collections.abc.Callable[[], typing.Any] | None = None,
    fps: int = 30,
    repeat: int = 0,
    repeat_delay: int = 0,
    derivation: bool = False
)

Bases: Animation

Animation of scaling the font size of virtual.Text.

  • text: an instance of virtual.Text that needs to be scaled
  • sizes: a tuple of the initial and ending sizes or target font size
  • duration: duration of the animation, in milliseconds
  • controller: a function that controls the animation process
  • end: end function, which is called once at the end of the animation
  • fps: frame rate of the animation
  • repeat: number of repetitions of the animation
  • repeat_delay: length of the delay before the animation repeats
  • derivation: whether the callback function is derivative

generate

generate(
    base: collections.abc.Callable[[float], float], start: float, end: float
) -> collections.abc.Callable[[float], float]
generate(
    base: collections.abc.Callable[[float], float],
    start: float,
    end: float,
    *,
    map_y: typing.Literal[False] = False
) -> collections.abc.Callable[[float], float]
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

linear(t: int) -> int
linear(t: float) -> float
linear(t: float) -> float

Speed remains the same.

  • t: the percentage of time

smooth

smooth(t: float) -> float

Speed is slow first, then fast and then slow. (slow -> fast -> slow)

  • t: the percentage of time

rebound

rebound(t: float) -> float

Before the end, displacement will bounce off a bit.

  • t: the percentage of time

ease_in

ease_in(t: float) -> float

Gradually accelerate. (slow -> fast)

  • t: the percentage of time

ease_out

ease_out(t: float) -> float

Gradually decelerate. (fast -> slow)

  • t: the percentage of time