From 45b769d96ed7748b7b8704f51257347fcfeb394f Mon Sep 17 00:00:00 2001 From: Maic Siemering Date: Wed, 30 Nov 2022 09:35:43 -0800 Subject: [PATCH] UI: transitions - use existing ease functions --- arcade/gui/__init__.py | 2 -- arcade/gui/transition.py | 17 ++++------------- doc/programming_guide/gui/concept.rst | 21 ++++++++++++++++++++- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/arcade/gui/__init__.py b/arcade/gui/__init__.py index 83abd72b3..186f2db55 100644 --- a/arcade/gui/__init__.py +++ b/arcade/gui/__init__.py @@ -28,7 +28,6 @@ ) from arcade.gui.widgets import UIDummy, Rect from arcade.gui.transition import ( - EaseFunctions, TransitionBase, EventTransitionBase, TransitionAttr, @@ -100,7 +99,6 @@ "Rect", "NinePatchTexture", # Transitions - "EaseFunctions", "TransitionBase", "EventTransitionBase", "TransitionAttr", diff --git a/arcade/gui/transition.py b/arcade/gui/transition.py index 7e41850bf..338ce9789 100644 --- a/arcade/gui/transition.py +++ b/arcade/gui/transition.py @@ -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): @@ -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, ): @@ -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, ): diff --git a/doc/programming_guide/gui/concept.rst b/doc/programming_guide/gui/concept.rst index 4a0cd568b..8f265f57e 100644 --- a/doc/programming_guide/gui/concept.rst +++ b/doc/programming_guide/gui/concept.rst @@ -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:: @@ -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 ========