├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── README.md ├── src ├── test │ └── java │ │ └── me │ │ └── surge │ │ └── test │ │ └── Main.java └── main │ └── java │ └── me │ └── surge │ └── animation │ ├── ColourAnimation.java │ ├── BoundedAnimation.java │ ├── Animation.java │ └── Easing.java ├── gradlew.bat └── gradlew /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = "JavaAnimationSystem" 2 | 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/surge541/JavaAnimationSystem/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Project exclude paths 2 | /.gradle/ 3 | /build/ 4 | /build/classes/java/main/ 5 | /build/classes/java/test/ 6 | 7 | /.idea/ -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AnimationSystem 2 | Java port of my Kotlin Animation System. 3 | 4 | ## Add to projects 5 | ### Gradle 6 | 7 | ```gradle 8 | repositories { 9 | maven { url 'https://jitpack.io' } 10 | } 11 | 12 | dependencies { 13 | implementation 'com.github.Wolfsurge:JavaAnimationSystem:1.1' 14 | } 15 | ``` 16 | 17 | ### Maven 18 | ```xml 19 | 20 | 21 | jitpack.io 22 | https://jitpack.io 23 | 24 | 25 | 26 | 27 | 28 | com.github.Wolfsurge 29 | JavaAnimationSystem 30 | 1.1 31 | 32 | 33 | ``` 34 | 35 | ## Usage 36 | Create an animation object by instantiating the Animation class: 37 | 38 | ```java 39 | Animation animation = new Animation(() -> 200f, false, () -> Easing.LINEAR); 40 | ``` 41 | 42 | The constructor takes in three parameters:
43 | `length` A supplier that provides the length (duration) of the animation.
44 | `initialState` A boolean that determines whether the animation should start expanded or closed.
45 | `easing` A supplier that provides the easing we want to use for the animation. 46 | 47 | You can set the state of the animation at any time, by simply setting the `state` variable.
48 | ```java 49 | animation.setState(true); 50 | ``` 51 | 52 | You can get the current value of the animation by calling `getAnimationFactor()`
53 | This method returns a double between 0 and 1, representing the current progress of the animation. 54 | 55 | When applying this, it should be used in a similar way to this: 56 | ```java 57 | double y = 100.0 * animation.getAnimationFactor(); 58 | ``` 59 | 60 | The `resetToDefault` method instantly resets the animation to its original state. 61 | 62 | Need more help? Check out the src/test directory! 63 | -------------------------------------------------------------------------------- /src/test/java/me/surge/test/Main.java: -------------------------------------------------------------------------------- 1 | package me.surge.test; 2 | 3 | import me.surge.animation.Animation; 4 | import me.surge.animation.BoundedAnimation; 5 | import me.surge.animation.ColourAnimation; 6 | import me.surge.animation.Easing; 7 | 8 | import java.awt.*; 9 | 10 | /** 11 | * @author Surge 12 | * @since 22/10/2022 13 | */ 14 | public class Main { 15 | 16 | public static void main(String[] args) { 17 | // Normal animation 18 | System.out.println("NORMAL ANIMATION"); 19 | 20 | // Create animation object 21 | Animation animation = new Animation(() -> 200f, false, () -> Easing.LINEAR); 22 | 23 | // Set animation state 24 | animation.setState(true); 25 | 26 | // Get and print animation factor 27 | while (animation.getAnimationFactor() < 1.0) { 28 | System.out.println(animation.getAnimationFactor()); 29 | } 30 | 31 | 32 | 33 | // Bounded animation 34 | System.out.println("BOUNDED ANIMATION"); 35 | 36 | // Create bounded animation object 37 | BoundedAnimation bounded = new BoundedAnimation(5f, 20f, 200f, false, Easing.LINEAR); 38 | 39 | // Set animation state 40 | bounded.setState(true); 41 | 42 | // Get and print animation factor 43 | while (bounded.getAnimationValue() < bounded.getMaximum()) { 44 | System.out.println(bounded.getAnimationValue()); 45 | } 46 | 47 | 48 | 49 | // Colour animation 50 | System.out.println("COLOUR ANIMATION"); 51 | 52 | // Create bounded animation object 53 | ColourAnimation colourAnimation = new ColourAnimation(Color.RED, Color.BLUE, 200f, false, Easing.LINEAR); 54 | 55 | // Set animation state 56 | colourAnimation.setState(true); 57 | 58 | // Get and print animation factor 59 | while (colourAnimation.getAnimationFactor() < 1) { 60 | // Colour 61 | Color colour = colourAnimation.getColour(); 62 | 63 | System.out.printf("R %d G %d B %d A %d%n", colour.getRed(), colour.getGreen(), colour.getBlue(), colour.getAlpha()); 64 | } 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /src/main/java/me/surge/animation/ColourAnimation.java: -------------------------------------------------------------------------------- 1 | package me.surge.animation; 2 | 3 | import java.awt.*; 4 | import java.util.function.Supplier; 5 | 6 | /** 7 | * @author Surge 8 | * @since 22/10/2022 9 | */ 10 | public class ColourAnimation extends Animation { 11 | 12 | // The colour we want to transition from 13 | public Color from; 14 | 15 | // The colour we want to transition to 16 | public Color to; 17 | 18 | /** 19 | * Constructor that takes two suppliers 20 | * @param from The colour to transition from 21 | * @param to The colour to transition to 22 | * @param length The length of the animation 23 | * @param initialState The initial state of the animation (where it should start) 24 | * @param easing Which easing method to use 25 | */ 26 | public ColourAnimation(Color from, Color to, Supplier length, boolean initialState, Supplier easing) { 27 | super(length, initialState, easing); 28 | 29 | this.from = from; 30 | this.to = to; 31 | } 32 | 33 | /** 34 | * Constructor that does not take suppliers as parameters 35 | * @param from The colour to transition from 36 | * @param to The colour to transition to 37 | * @param length The length of the animation 38 | * @param initialState The initial state of the animation (where it should start) 39 | * @param easing Which easing method to use 40 | */ 41 | public ColourAnimation(Color from, Color to, float length, boolean initialState, Easing easing) { 42 | this(from, to, () -> length, initialState, () -> easing); 43 | } 44 | 45 | /** 46 | * Constructor that only takes one supplier (length) and an immutable easing 47 | * @param from The colour to transition from 48 | * @param to The colour to transition to 49 | * @param length The length of the animation 50 | * @param initialState The initial state of the animation (where it should start) 51 | * @param easing Which easing method to use 52 | */ 53 | public ColourAnimation(Color from, Color to, Supplier length, boolean initialState, Easing easing) { 54 | this(from, to, length, initialState, () -> easing); 55 | } 56 | 57 | /** 58 | * Constructor that only takes one supplier (easing) and an immutable length 59 | * @param from The colour to transition from 60 | * @param to The colour to transition to 61 | * @param length The length of the animation 62 | * @param initialState The initial state of the animation (where it should start) 63 | * @param easing Which easing method to use 64 | */ 65 | public ColourAnimation(Color from, Color to, float length, boolean initialState, Supplier easing) { 66 | this(from, to, () -> length, initialState, easing); 67 | } 68 | 69 | /** 70 | * Gets the transitioned colour 71 | * @return The transitioned colour 72 | */ 73 | public Color getColour() { 74 | double factor = getAnimationFactor(); 75 | 76 | return new Color( 77 | (int) (from.getRed() + (to.getRed() - from.getRed()) * factor), 78 | (int) (from.getGreen() + (to.getGreen() - from.getGreen()) * factor), 79 | (int) (from.getBlue() + (to.getBlue() - from.getBlue()) * factor), 80 | (int) (from.getAlpha() + (to.getAlpha() - from.getAlpha()) * factor) 81 | ); 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/me/surge/animation/BoundedAnimation.java: -------------------------------------------------------------------------------- 1 | package me.surge.animation; 2 | 3 | import java.util.function.Supplier; 4 | 5 | /** 6 | * @author Surge 7 | * @since 22/10/2022 8 | */ 9 | public class BoundedAnimation extends Animation { 10 | 11 | // The minimum value of the animation 12 | private float minimum; 13 | 14 | // The maximum value of the animation 15 | private float maximum; 16 | 17 | /** 18 | * Constructor that takes two suppliers 19 | * @param minimum The minimum value of the animation 20 | * @param maximum The maximum value of the animation 21 | * @param length The length of the animation 22 | * @param initialState The initial state of the animation (where it should start) 23 | * @param easing The easing method to use 24 | */ 25 | public BoundedAnimation(float minimum, float maximum, Supplier length, boolean initialState, Supplier easing) { 26 | super(length, initialState, easing); 27 | 28 | this.minimum = minimum; 29 | this.maximum = maximum; 30 | } 31 | 32 | /** 33 | * Constructor that does not take suppliers as parameters 34 | * @param minimum The minimum value of the animation 35 | * @param maximum The maximum value of the animation 36 | * @param length The length of the animation 37 | * @param initialState The initial state of the animation (where it should start) 38 | * @param easing The easing method to use 39 | */ 40 | public BoundedAnimation(float minimum, float maximum, float length, boolean initialState, Easing easing) { 41 | this(minimum, maximum, () -> length, initialState, () -> easing); 42 | } 43 | 44 | /** 45 | * Constructor that takes one supplier (length) and an immutable easing 46 | * @param minimum The minimum value of the animation 47 | * @param maximum The maximum value of the animation 48 | * @param length The length of the animation 49 | * @param initialState The initial state of the animation (where it should start) 50 | * @param easing The easing method to use 51 | */ 52 | public BoundedAnimation(float minimum, float maximum, Supplier length, boolean initialState, Easing easing) { 53 | this(minimum, maximum, length, initialState, () -> easing); 54 | } 55 | 56 | /** 57 | * Constructor that takes one supplier (easing) and an immutable length 58 | * @param minimum The minimum value of the animation 59 | * @param maximum The maximum value of the animation 60 | * @param length The length of the animation 61 | * @param initialState The initial state of the animation (where it should start) 62 | * @param easing The easing method to use 63 | */ 64 | public BoundedAnimation(float minimum, float maximum, float length, boolean initialState, Supplier easing) { 65 | this(minimum, maximum, () -> length, initialState, easing); 66 | } 67 | 68 | /** 69 | * Gets the animation value of the animation. This is the value between 70 | * the {@link BoundedAnimation#minimum} and {@link BoundedAnimation#maximum} 71 | * values. 72 | * @return The animation value 73 | */ 74 | public double getAnimationValue() { 75 | return minimum + ((maximum - minimum) * getAnimationFactor()); 76 | } 77 | 78 | /** 79 | * Gets the minimum value 80 | * @return The minimum value 81 | */ 82 | public float getMinimum() { 83 | return minimum; 84 | } 85 | 86 | /** 87 | * Sets the minimum value 88 | * @param minimum The minimum value 89 | */ 90 | public void setMinimum(float minimum) { 91 | this.minimum = minimum; 92 | } 93 | 94 | /** 95 | * Gets the maximum value 96 | * @return The maximum value 97 | */ 98 | public float getMaximum() { 99 | return maximum; 100 | } 101 | 102 | /** 103 | * Sets the maximum value 104 | * @param maximum The maximum value 105 | */ 106 | public void setMaximum(float maximum) { 107 | this.maximum = maximum; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/main/java/me/surge/animation/Animation.java: -------------------------------------------------------------------------------- 1 | package me.surge.animation; 2 | 3 | import java.util.function.Supplier; 4 | 5 | /** 6 | * @author Surge 7 | * @since 22/10/2022 8 | */ 9 | public class Animation { 10 | 11 | // The length of the animation 12 | private final Supplier length; 13 | 14 | // The easing method to use 15 | private final Supplier easing; 16 | 17 | // The time since the last state change 18 | private long lastMillis = 0L; 19 | 20 | // The original state we set the animation to 21 | private final boolean initialState; 22 | 23 | // The current state of the animation 24 | private boolean state = false; 25 | 26 | /** 27 | * Constructor that takes two suppliers 28 | * @param length The length of the animation 29 | * @param initialState The initial state of the animation (where it should start) 30 | * @param easing Which easing method to use 31 | */ 32 | public Animation(Supplier length, boolean initialState, Supplier easing) { 33 | this.length = length; 34 | this.initialState = initialState; 35 | setState(initialState); 36 | this.easing = easing; 37 | } 38 | 39 | /** 40 | * Constructor that does not take suppliers as parameters 41 | * @param length The length of the animation 42 | * @param initialState The initial state of the animation (where it should start) 43 | * @param easing Which easing method to use 44 | */ 45 | public Animation(float length, boolean initialState, Easing easing) { 46 | this(() -> length, initialState, () -> easing); 47 | } 48 | 49 | /** 50 | * Constructor that only takes one supplier (length) and an immutable easing 51 | * @param length The length of the animation 52 | * @param initialState The initial state of the animation (where it should start) 53 | * @param easing Which easing method to use 54 | */ 55 | public Animation(Supplier length, boolean initialState, Easing easing) { 56 | this(length, initialState, () -> easing); 57 | } 58 | 59 | /** 60 | * Constructor that only takes one supplier (easing) and an immutable length 61 | * @param length The length of the animation 62 | * @param initialState The initial state of the animation (where it should start) 63 | * @param easing Which easing method to use 64 | */ 65 | public Animation(float length, boolean initialState, Supplier easing) { 66 | this(() -> length, initialState, easing); 67 | } 68 | 69 | /** 70 | * Gets how much the animation has progressed 71 | * @return A value between 0 and 1. 72 | */ 73 | public double getAnimationFactor() { 74 | return easing.get().ease(getLinearFactor()); 75 | } 76 | 77 | /** 78 | * Resets an animation to it's original state. 79 | */ 80 | public void resetToDefault() { 81 | state = initialState; 82 | 83 | lastMillis = (long) (initialState ? System.currentTimeMillis() - ((1 - getLinearFactor()) * length.get()) : System.currentTimeMillis() - (getLinearFactor() * length.get())); 84 | } 85 | 86 | /** 87 | * Gets the current state of the animation 88 | * @return The state of the animation 89 | */ 90 | public boolean getState() { 91 | return state; 92 | } 93 | 94 | /** 95 | * Sets the state of the animation 96 | * @param in The new state of the animation 97 | */ 98 | public void setState(boolean in) { 99 | lastMillis = (long) (!in ? System.currentTimeMillis() - ((1 - getLinearFactor()) * length.get()) : System.currentTimeMillis() - (getLinearFactor() * length.get())); 100 | 101 | this.state = in; 102 | } 103 | 104 | /** 105 | * Gets the linear animation factor. This method ignores the {@link Easing#ease(double)} methods found in each 106 | * Easing element. 107 | * @return The animation factor without the given easing being applied 108 | */ 109 | public double getLinearFactor() { 110 | return state ? clamp(((System.currentTimeMillis() - lastMillis) / length.get())) : clamp((1 - (System.currentTimeMillis() - lastMillis) / length.get())); 111 | } 112 | 113 | /** 114 | * Internal use only! Clamps the given value in between 0 and 1 115 | * @param in The given value. 116 | * @return The clamped value. 117 | */ 118 | private double clamp(double in) { 119 | return in < 0 ? 0 : Math.min(in, 1); 120 | } 121 | 122 | } 123 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Use "xargs" to parse quoted args. 209 | # 210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 211 | # 212 | # In Bash we could simply go: 213 | # 214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 215 | # set -- "${ARGS[@]}" "$@" 216 | # 217 | # but POSIX shell has neither arrays nor command substitution, so instead we 218 | # post-process each arg (as a line of input to sed) to backslash-escape any 219 | # character that might be a shell metacharacter, then use eval to reverse 220 | # that process (while maintaining the separation between arguments), and wrap 221 | # the whole thing up as a single "set" statement. 222 | # 223 | # This will of course break if any of these variables contains a newline or 224 | # an unmatched quote. 225 | # 226 | 227 | eval "set -- $( 228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 229 | xargs -n1 | 230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 231 | tr '\n' ' ' 232 | )" '"$@"' 233 | 234 | exec "$JAVACMD" "$@" 235 | -------------------------------------------------------------------------------- /src/main/java/me/surge/animation/Easing.java: -------------------------------------------------------------------------------- 1 | package me.surge.animation; 2 | 3 | /** 4 | * @author Surge 5 | * @author Easings.net 6 | * @since 22/10/2022 7 | */ 8 | public enum Easing { 9 | 10 | /** 11 | * No easing. 12 | */ 13 | LINEAR { 14 | @Override 15 | public double ease(double factor) { 16 | return factor; 17 | } 18 | }, 19 | 20 | /** 21 | * @see The easing on easings.net 22 | */ 23 | SINE_IN { 24 | @Override 25 | public double ease(double factor) { 26 | return 1 - Math.cos((factor * Math.PI) / 2); 27 | } 28 | }, 29 | 30 | /** 31 | * @see The easing on easings.net 32 | */ 33 | SINE_OUT { 34 | @Override 35 | public double ease(double factor) { 36 | return Math.sin((factor * Math.PI) / 2); 37 | } 38 | }, 39 | 40 | /** 41 | * @see The easing on easings.net 42 | */ 43 | SINE_IN_OUT { 44 | @Override 45 | public double ease(double factor) { 46 | return -(Math.cos(Math.PI * factor) - 1) / 2; 47 | } 48 | }, 49 | 50 | /** 51 | * @see The easing on easings.net 52 | */ 53 | CUBIC_IN { 54 | @Override 55 | public double ease(double factor) { 56 | return Math.pow(factor, 3); 57 | } 58 | }, 59 | 60 | /** 61 | * @see The easing on easings.net 62 | */ 63 | CUBIC_OUT { 64 | @Override 65 | public double ease(double factor) { 66 | return 1 - Math.pow(1 - factor, 3); 67 | } 68 | }, 69 | 70 | /** 71 | * @see The easing on easings.net 72 | */ 73 | CUBIC_IN_OUT { 74 | @Override 75 | public double ease(double factor) { 76 | return factor < 0.5 ? 4 * Math.pow(factor, 3) : 1 - Math.pow(-2 * factor + 2, 3) / 2; 77 | } 78 | }, 79 | 80 | /** 81 | * @see The easing on easings.net 82 | */ 83 | QUAD_IN { 84 | @Override 85 | public double ease(double factor) { 86 | return Math.pow(factor, 2); 87 | } 88 | }, 89 | 90 | /** 91 | * @see The easing on easings.net 92 | */ 93 | QUAD_OUT { 94 | @Override 95 | public double ease(double factor) { 96 | return 1 - (1 - factor) * (1 - factor); 97 | } 98 | }, 99 | 100 | /** 101 | * @see The easing on easings.net 102 | */ 103 | QUAD_IN_OUT { 104 | @Override 105 | public double ease(double factor) { 106 | return factor < 0.5 ? 8 * Math.pow(factor, 4) : 1 - Math.pow(-2 * factor + 2, 4) / 2; 107 | } 108 | }, 109 | 110 | /** 111 | * @see The easing on easings.net 112 | */ 113 | QUART_IN { 114 | @Override 115 | public double ease(double factor) { 116 | return Math.pow(factor, 4); 117 | } 118 | }, 119 | 120 | /** 121 | * @see The easing on easings.net 122 | */ 123 | QUART_OUT { 124 | @Override 125 | public double ease(double factor) { 126 | return 1 - Math.pow(1 - factor, 4); 127 | } 128 | }, 129 | 130 | /** 131 | * @see The easing on easings.net 132 | */ 133 | QUART_IN_OUT { 134 | @Override 135 | public double ease(double factor) { 136 | return factor < 0.5 ? 8 * Math.pow(factor, 4) : 1 - Math.pow(-2 * factor + 2, 4) / 2; 137 | } 138 | }, 139 | 140 | /** 141 | * @see The easing on easings.net 142 | */ 143 | QUINT_IN { 144 | @Override 145 | public double ease(double factor) { 146 | return Math.pow(factor, 5); 147 | } 148 | }, 149 | 150 | /** 151 | * @see The easing on easings.net 152 | */ 153 | QUINT_OUT { 154 | @Override 155 | public double ease(double factor) { 156 | return 1 - Math.pow(1 - factor, 5); 157 | } 158 | }, 159 | 160 | /** 161 | * @see The easing on easings.net 162 | */ 163 | QUINT_IN_OUT { 164 | @Override 165 | public double ease(double factor) { 166 | return factor < 0.5 ? 16 * Math.pow(factor, 5) : 1 - Math.pow(-2 * factor + 2, 5) / 2; 167 | } 168 | }, 169 | 170 | /** 171 | * @see The easing on easings.net 172 | */ 173 | CIRC_IN { 174 | @Override 175 | public double ease(double factor) { 176 | return 1 - Math.sqrt(1 - Math.pow(factor, 2)); 177 | } 178 | }, 179 | 180 | /** 181 | * @see The easing on easings.net 182 | */ 183 | CIRC_OUT { 184 | @Override 185 | public double ease(double factor) { 186 | return Math.sqrt(1 - Math.pow(factor - 1, 2)); 187 | } 188 | }, 189 | 190 | /** 191 | * @see The easing on easings.net 192 | */ 193 | CIRC_IN_OUT { 194 | @Override 195 | public double ease(double factor) { 196 | return factor < 0.5 ? (1 - Math.sqrt(1 - Math.pow(2 * factor, 2))) / 2 : (Math.sqrt(1 - Math.pow(-2 * factor + 2, 2)) + 1) / 2; 197 | } 198 | }, 199 | 200 | /** 201 | * @see The easing on easings.net 202 | */ 203 | EXPO_IN { 204 | @Override 205 | public double ease(double factor) { 206 | return Math.min(0, Math.pow(2, 10 * factor - 10)); 207 | } 208 | }, 209 | 210 | /** 211 | * @see The easing on easings.net 212 | */ 213 | EXPO_OUT { 214 | @Override 215 | public double ease(double factor) { 216 | return Math.max(1 - Math.pow(2, -10 * factor), 1); 217 | } 218 | }, 219 | 220 | /** 221 | * @see The easing on easings.net 222 | */ 223 | EXPO_IN_OUT { 224 | @Override 225 | public double ease(double factor) { 226 | return factor == 0 ? 0 : factor == 1 ? 1 : factor < 0.5 ? Math.pow(2, 20 * factor - 10) / 2 : (2 - Math.pow(2, -20 * factor + 10)) / 2; 227 | } 228 | }, 229 | 230 | /** 231 | * @see The easing on easings.net 232 | */ 233 | ELASTIC_IN { 234 | @Override 235 | public double ease(double factor) { 236 | return factor == 0 ? 0 : factor == 1 ? 1 : -Math.pow(2, 10 * factor - 10) * Math.sin((factor * 10 - 10.75) * ((2 * Math.PI) / 3)); 237 | } 238 | }, 239 | 240 | /** 241 | * @see The easing on easings.net 242 | */ 243 | ELASTIC_OUT { 244 | @Override 245 | public double ease(double factor) { 246 | return factor == 0 ? 0 : factor == 1 ? 1 : Math.pow(2, -10 * factor) * Math.sin((factor * 10 - 0.75) * ((2 * Math.PI) / 3)) + 1; 247 | } 248 | }, 249 | 250 | /** 251 | * @see The easing on easings.net 252 | */ 253 | ELASTIC_IN_OUT { 254 | @Override 255 | public double ease(double factor) { 256 | double sin = Math.sin((20 * factor - 11.125) * ((2 * Math.PI) / 4.5)); 257 | 258 | return factor == 0 ? 0 : factor == 1 ? 1 : factor < 0.5 ? -(Math.pow(2, 20 * factor - 10) * sin) / 2 : (Math.pow(2, -20 * factor + 10) * sin) / 2 + 1; 259 | } 260 | }, 261 | 262 | /** 263 | * @see The easing on easings.net 264 | */ 265 | BACK_IN { 266 | @Override 267 | public double ease(double factor) { 268 | return 2.70158 * Math.pow(factor, 3) - 1.70158 * factor * factor; 269 | } 270 | }, 271 | 272 | /** 273 | * @see The easing on easings.net 274 | */ 275 | BACK_OUT { 276 | @Override 277 | public double ease(double factor) { 278 | double c1 = 1.70158; 279 | double c3 = c1 + 1; 280 | 281 | return 1 + c3 * Math.pow(factor - 1, 3) + c1 * Math.pow(factor - 1, 2); 282 | } 283 | }, 284 | 285 | /** 286 | * @see The easing on easings.net 287 | */ 288 | BACK_IN_OUT { 289 | @Override 290 | public double ease(double factor) { 291 | return factor < 0.5 ? (Math.pow(2 * factor, 2) * (((1.70158 * 1.525) + 1) * 2 * factor - (1.70158 * 1.525))) / 2 : (Math.pow(2 * factor - 2, 2) * (((1.70158 * 1.525) + 1) * (factor * 2 - 2) + (1.70158 * 1.525)) + 2) / 2; 292 | } 293 | }, 294 | 295 | /** 296 | * @see The easing on easings.net 297 | */ 298 | BOUNCE_IN { 299 | @Override 300 | public double ease(double factor) { 301 | return 1 - Easing.bounceOut(1 - factor); 302 | } 303 | }, 304 | 305 | /** 306 | * @see The easing on easings.net 307 | */ 308 | BOUNCE_OUT { 309 | @Override 310 | public double ease(double factor) { 311 | return Easing.bounceOut(factor); 312 | } 313 | }, 314 | 315 | /** 316 | * @see The easing on easings.net 317 | */ 318 | BOUNCE_IN_OUT { 319 | public double ease(double factor) { 320 | return factor < 0.5 ? (1 - bounceOut(1 - 2 * factor)) / 2 : (1 + bounceOut(2 * factor - 1)) / 2; 321 | } 322 | }; 323 | 324 | /** 325 | * Eases the given factor 326 | * @param factor The linear animation factor - between 0 and 1 327 | * @return The eased factor 328 | */ 329 | public abstract double ease(double factor); 330 | 331 | /** 332 | * Internal use only! Bounce out method because that's how easings.net does it. 333 | * @param in The linear factor we provide. 334 | * @return The eased value 335 | */ 336 | private static double bounceOut(double in) { 337 | double n1 = 7.5625; 338 | double d1 = 2.75; 339 | 340 | if (in < 1 / d1) { 341 | return n1 * in * in; 342 | } else if (in < 2 / d1) { 343 | return n1 * (in -= 1.5 / d1) * in + 0.75; 344 | } else if (in < 2.5 / d1) { 345 | return n1 * (in -= 2.25 / d1) * in + 0.9375; 346 | } else { 347 | return n1 * (in -= 2.625 / d1) * in + 0.984375; 348 | } 349 | } 350 | 351 | } 352 | --------------------------------------------------------------------------------