Skip to content

Commit

Permalink
UI: transitions - use existing ease functions
Browse files Browse the repository at this point in the history
  • Loading branch information
eruvanos committed Nov 30, 2022
1 parent 3817d16 commit 45b769d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
2 changes: 0 additions & 2 deletions arcade/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
)
from arcade.gui.widgets import UIDummy, Rect
from arcade.gui.transition import (
EaseFunctions,
TransitionBase,
EventTransitionBase,
TransitionAttr,
Expand Down Expand Up @@ -100,7 +99,6 @@
"Rect",
"NinePatchTexture",
# Transitions
"EaseFunctions",
"TransitionBase",
"EventTransitionBase",
"TransitionAttr",
Expand Down
17 changes: 4 additions & 13 deletions arcade/gui/transition.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
import math
from abc import ABC, abstractmethod
from typing import Callable, Any, Optional, List, TypeVar

from pyglet.event import EventDispatcher

T = TypeVar("T", bound="TransitionBase")

from arcade import linear

class EaseFunctions:
@staticmethod
def linear(x: float):
return x

@staticmethod
def sine(x: float):
return 1 - math.cos((x * math.pi) / 2)
T = TypeVar("T", bound="TransitionBase")


class TransitionBase(ABC):
Expand Down Expand Up @@ -109,7 +100,7 @@ def __init__(
attribute,
duration: float,
start=None,
ease_function=EaseFunctions.linear,
ease_function=linear,
delay=0.0,
mutation_function: Callable[[Any, str, float], None] = setattr,
):
Expand Down Expand Up @@ -149,7 +140,7 @@ def __init__(
increment: float,
attribute,
duration: float,
ease_function=EaseFunctions.linear,
ease_function=linear,
delay=0.0,
mutation_function: Callable[[Any, str, float], None] = setattr,
):
Expand Down
21 changes: 20 additions & 1 deletion doc/programming_guide/gui/concept.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Transitions

To animate a UIWidget, use :meth:`UIWidget.add_transition` and add a :class:`Transition`.
A :class:`Transition` can be used to manipulate a value over time.
:class:`EaseFunctions` provides a few easing functions.
Arcade provides a few easing functions listed below.

.. code-block::
Expand All @@ -83,6 +83,25 @@ Arcade provides following transitions:
> Be aware, that transitions may interfere with :class:`UILayout` positioning.


Easing functions
................

You can check out all of these functions using `python -m arcade.examples.easing_example_1`

- :meth:`arcade.linear`
- :meth:`arcade.smoothstep`
- :meth:`arcade.ease_in`
- :meth:`arcade.ease_out`
- :meth:`arcade.ease_in_out`
- :meth:`arcade.ease_out_elastic`
- :meth:`arcade.ease_out_bounce`
- :meth:`arcade.ease_in_back`
- :meth:`arcade.ease_out_back`
- :meth:`arcade.ease_in_sin`
- :meth:`arcade.ease_out_sin`
- :meth:`arcade.ease_in_out_sin`


UILayout
========

Expand Down

0 comments on commit 45b769d

Please sign in to comment.