/** * Copyright (c) 2021 Dominic Masters * * This software is released under the MIT License. * https://opensource.org/licenses/MIT */ #pragma once /** * Returns the ease time for a given real time duration span. * @param start At what point in time the animation started * @param current The current point in time the animation is at. * @param duration The total duration on the animation. * @returns The easing time (0-1 time) that the animation is at. */ #define easeTimeToEase(start, current, duration) ((current-start)/duration) /** * Animation tool for converting 0-1 space into a 0-0.5 back to zero space. This * is intended to make a "Forward then backwards" effect for animation. This * method will not scale t. * @param t Time in space to back and fourth on between 0 and 1. * @returns Forward and backwards time. 0 to 0.5 are as such, 0.5 to 1 are from * 0.5 to 0. */ #define easeTimeToForwardAndBackward(t) (t < 0.5 ? t : 1 - t) // Easing Functions, most were sourced from https://gist.github.com/gre/1650294 #define easeLinear(t) t #define easeInQuad(t) (t*t) #define easeOutQuad(t) (t*(2-t)) #define easeInOutQuad(t) (t < .5 ? 2*t*t : -1+(4-2*t)*t) #define easeInCubic(t) (t*t*t) #define easeOutCubic(t) ((t-1)*(t-1)*(t-1)+1) #define easeInOutCubic(t) (t < .5 ? 4*t*t*t : (t-1)*(2*t-2)*(2*t-2)+1) #define easeInQuart(t) (t*t*t*t) #define easeOutQuart(t) (1 - (t-1)*(t-1)*(t-1)*(t-1)) #define easeInOutQuart(t) (t < .5 ? 8*t*t*t*t : 1-8*(t-1)*(t-1)*(t-1)*(t-1)) #define easeInQuint(t) (t*t*t*t*t) #define easeOutQuint(t) (1 + (t-1)*(t-1)*(t-1)*(t-1)*(t-1)) #define easeInOutQuint(t) (t<.5 ? 16*t*t*t*t*t : 1+16*(t-1)*(t-1)*(t-1)*(t-1)*(t-1))