parent
5c261c4513
commit
e2e5576664
@ -1,167 +0,0 @@ |
|||||||
package mightypork.rogue.display; |
|
||||||
|
|
||||||
|
|
||||||
import org.lwjgl.input.Keyboard; |
|
||||||
import org.lwjgl.opengl.Display; |
|
||||||
|
|
||||||
import mightypork.rogue.App; |
|
||||||
import mightypork.rogue.input.KeyStroke; |
|
||||||
import mightypork.rogue.input.events.MouseButtonEvent; |
|
||||||
import mightypork.rogue.input.events.MouseMotionEvent; |
|
||||||
import mightypork.rogue.util.RenderUtils; |
|
||||||
import mightypork.utils.math.Polar; |
|
||||||
import mightypork.utils.math.color.RGB; |
|
||||||
import mightypork.utils.math.coord.Coord; |
|
||||||
import mightypork.utils.math.easing.Easing; |
|
||||||
import mightypork.utils.time.AnimDouble; |
|
||||||
import mightypork.utils.time.AnimDoubleDeg; |
|
||||||
|
|
||||||
|
|
||||||
public class ScreenSplash extends Screen { |
|
||||||
|
|
||||||
private AnimDoubleDeg degAnim = new AnimDoubleDeg(0, Easing.SINE); |
|
||||||
|
|
||||||
//@formatter:off
|
|
||||||
private AnimDouble[] anims = new AnimDouble[] { |
|
||||||
new AnimDouble(0, Easing.NONE), |
|
||||||
new AnimDouble(0, Easing.LINEAR), |
|
||||||
|
|
||||||
new AnimDouble(0, Easing.QUADRATIC_IN), |
|
||||||
new AnimDouble(0, Easing.QUADRATIC_OUT), |
|
||||||
new AnimDouble(0, Easing.QUADRATIC), |
|
||||||
|
|
||||||
new AnimDouble(0, Easing.CUBIC_IN), |
|
||||||
new AnimDouble(0, Easing.CUBIC_OUT), |
|
||||||
new AnimDouble(0, Easing.CUBIC), |
|
||||||
|
|
||||||
new AnimDouble(0, Easing.QUADRATIC_IN), |
|
||||||
new AnimDouble(0, Easing.QUADRATIC_OUT), |
|
||||||
new AnimDouble(0, Easing.QUADRATIC), |
|
||||||
|
|
||||||
new AnimDouble(0, Easing.QUINTIC_IN), |
|
||||||
new AnimDouble(0, Easing.QUINTIC_OUT), |
|
||||||
new AnimDouble(0, Easing.QUINTIC_IN_OUT), |
|
||||||
|
|
||||||
new AnimDouble(0, Easing.EXPO_IN), |
|
||||||
new AnimDouble(0, Easing.EXPO_OUT), |
|
||||||
new AnimDouble(0, Easing.EXPO), |
|
||||||
|
|
||||||
new AnimDouble(0, Easing.SINE_IN), |
|
||||||
new AnimDouble(0, Easing.SINE_OUT), |
|
||||||
new AnimDouble(0, Easing.SINE), |
|
||||||
|
|
||||||
new AnimDouble(0, Easing.CIRC_IN), |
|
||||||
new AnimDouble(0, Easing.CIRC_OUT), |
|
||||||
new AnimDouble(0, Easing.CIRC), |
|
||||||
}; |
|
||||||
//@formatter:on
|
|
||||||
|
|
||||||
@Override |
|
||||||
public void initialize() |
|
||||||
{ |
|
||||||
bindKeyStroke(new KeyStroke(Keyboard.KEY_RIGHT), new Runnable() { |
|
||||||
|
|
||||||
@Override |
|
||||||
public void run() |
|
||||||
{ |
|
||||||
for (AnimDouble a : anims) { |
|
||||||
a.animate(0, 1, 3); |
|
||||||
} |
|
||||||
} |
|
||||||
}); |
|
||||||
|
|
||||||
bindKeyStroke(new KeyStroke(Keyboard.KEY_LEFT), new Runnable() { |
|
||||||
|
|
||||||
@Override |
|
||||||
public void run() |
|
||||||
{ |
|
||||||
for (AnimDouble a : anims) { |
|
||||||
a.animate(1, 0, 3); |
|
||||||
} |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
@Override |
|
||||||
protected void renderScreen() |
|
||||||
{ |
|
||||||
double screenH = Display.getHeight(); |
|
||||||
double screenW = Display.getWidth(); |
|
||||||
double perBoxH = screenH / anims.length; |
|
||||||
double padding = perBoxH*0.1; |
|
||||||
double boxSide = perBoxH-padding*2; |
|
||||||
|
|
||||||
for (int i = 0; i < anims.length; i++) { |
|
||||||
AnimDouble a = anims[i]; |
|
||||||
|
|
||||||
RenderUtils.setColor(i%3==0?RGB.GREEN:RGB.BLUE); |
|
||||||
RenderUtils.quadSize( |
|
||||||
padding + a.getCurrentValue() * (screenW - perBoxH - padding*2), |
|
||||||
screenH - perBoxH * i - perBoxH + padding, |
|
||||||
boxSide, |
|
||||||
boxSide |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
RenderUtils.setColor(RGB.YELLOW); |
|
||||||
RenderUtils.translate(new Coord(Display.getWidth() / 2, Display.getHeight() / 2)); |
|
||||||
RenderUtils.rotateZ(degAnim.getCurrentValue()); |
|
||||||
RenderUtils.quadSize(-10, -10, 20, 200); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
@Override |
|
||||||
public void receive(MouseMotionEvent event) |
|
||||||
{ |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
@Override |
|
||||||
public void receive(MouseButtonEvent event) |
|
||||||
{ |
|
||||||
if(event.isDown()) { |
|
||||||
Coord vec = App.disp().getSize().half().vecTo(event.getPos()); |
|
||||||
|
|
||||||
Polar p = Polar.fromCoord(vec); |
|
||||||
|
|
||||||
degAnim.fadeTo(p.getAngleDeg() - 90, 0.2); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
@Override |
|
||||||
protected void onEnter() |
|
||||||
{ |
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
@Override |
|
||||||
protected void onLeave() |
|
||||||
{ |
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
@Override |
|
||||||
protected void onSizeChanged(Coord size) |
|
||||||
{ |
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
@Override |
|
||||||
protected void updateScreen(double delta) |
|
||||||
{ |
|
||||||
degAnim.update(delta); |
|
||||||
|
|
||||||
for (AnimDouble a : anims) { |
|
||||||
a.update(delta); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -0,0 +1,200 @@ |
|||||||
|
package mightypork.rogue.display; |
||||||
|
|
||||||
|
|
||||||
|
import java.util.Random; |
||||||
|
|
||||||
|
import mightypork.rogue.App; |
||||||
|
import mightypork.rogue.input.KeyStroke; |
||||||
|
import mightypork.rogue.input.events.MouseButtonEvent; |
||||||
|
import mightypork.rogue.input.events.MouseMotionEvent; |
||||||
|
import mightypork.rogue.util.RenderUtils; |
||||||
|
import mightypork.utils.math.Polar; |
||||||
|
import mightypork.utils.math.color.RGB; |
||||||
|
import mightypork.utils.math.coord.Coord; |
||||||
|
import mightypork.utils.math.easing.Easing; |
||||||
|
import mightypork.utils.time.animation.AnimDouble; |
||||||
|
import mightypork.utils.time.animation.AnimDoubleDeg; |
||||||
|
|
||||||
|
import org.lwjgl.input.Keyboard; |
||||||
|
import org.lwjgl.opengl.Display; |
||||||
|
|
||||||
|
|
||||||
|
public class ScreenTestAnimations extends Screen { |
||||||
|
|
||||||
|
private Random rand = new Random(); |
||||||
|
|
||||||
|
private AnimDoubleDeg degAnim = new AnimDoubleDeg(0, Easing.ELASTIC_OUT); |
||||||
|
|
||||||
|
//@formatter:off
|
||||||
|
private AnimDouble[] anims = new AnimDouble[] { |
||||||
|
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||||
|
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||||
|
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||||
|
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||||
|
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||||
|
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||||
|
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||||
|
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||||
|
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||||
|
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||||
|
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||||
|
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||||
|
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||||
|
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||||
|
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||||
|
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||||
|
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||||
|
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||||
|
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||||
|
new AnimDouble(0, Easing.BOUNCE_OUT), |
||||||
|
|
||||||
|
// new AnimDouble(0, Easing.NONE),
|
||||||
|
// new AnimDouble(0, Easing.LINEAR),
|
||||||
|
//
|
||||||
|
// new AnimDouble(0, Easing.QUADRATIC_IN),
|
||||||
|
// new AnimDouble(0, Easing.QUADRATIC_OUT),
|
||||||
|
// new AnimDouble(0, Easing.QUADRATIC_IN_OUT),
|
||||||
|
//
|
||||||
|
// new AnimDouble(0, Easing.CUBIC_IN),
|
||||||
|
// new AnimDouble(0, Easing.CUBIC_OUT),
|
||||||
|
// new AnimDouble(0, Easing.CUBIC_IN_OUT),
|
||||||
|
//
|
||||||
|
// new AnimDouble(0, Easing.QUADRATIC_IN),
|
||||||
|
// new AnimDouble(0, Easing.QUADRATIC_OUT),
|
||||||
|
// new AnimDouble(0, Easing.QUADRATIC_IN_OUT),
|
||||||
|
//
|
||||||
|
// new AnimDouble(0, Easing.QUINTIC_IN),
|
||||||
|
// new AnimDouble(0, Easing.QUINTIC_OUT),
|
||||||
|
// new AnimDouble(0, Easing.QUINTIC_IN_OUT),
|
||||||
|
//
|
||||||
|
// new AnimDouble(0, Easing.EXPO_IN),
|
||||||
|
// new AnimDouble(0, Easing.EXPO_OUT),
|
||||||
|
// new AnimDouble(0, Easing.EXPO_IN_OUT),
|
||||||
|
//
|
||||||
|
// new AnimDouble(0, Easing.SINE_IN),
|
||||||
|
// new AnimDouble(0, Easing.SINE_OUT),
|
||||||
|
// new AnimDouble(0, Easing.SINE_IN_OUT),
|
||||||
|
//
|
||||||
|
// new AnimDouble(0, Easing.CIRC_IN),
|
||||||
|
// new AnimDouble(0, Easing.CIRC_OUT),
|
||||||
|
// new AnimDouble(0, Easing.CIRC_IN_OUT),
|
||||||
|
//
|
||||||
|
// new AnimDouble(0, Easing.BOUNCE_IN),
|
||||||
|
// new AnimDouble(0, Easing.BOUNCE_OUT),
|
||||||
|
// new AnimDouble(0, Easing.BOUNCE_IN_OUT),
|
||||||
|
//
|
||||||
|
// new AnimDouble(0, Easing.BACK_IN),
|
||||||
|
// new AnimDouble(0, Easing.BACK_OUT),
|
||||||
|
// new AnimDouble(0, Easing.BACK_IN_OUT),
|
||||||
|
//
|
||||||
|
// new AnimDouble(0, Easing.ELASTIC_IN),
|
||||||
|
// new AnimDouble(0, Easing.ELASTIC_OUT),
|
||||||
|
// new AnimDouble(0, Easing.ELASTIC_IN_OUT),
|
||||||
|
}; |
||||||
|
//@formatter:on
|
||||||
|
|
||||||
|
@Override |
||||||
|
public void initialize() |
||||||
|
{ |
||||||
|
bindKeyStroke(new KeyStroke(Keyboard.KEY_RIGHT), new Runnable() { |
||||||
|
|
||||||
|
@Override |
||||||
|
public void run() |
||||||
|
{ |
||||||
|
for (AnimDouble a : anims) { |
||||||
|
a.animate(0, 1, 1+rand.nextDouble()*1); |
||||||
|
} |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
bindKeyStroke(new KeyStroke(Keyboard.KEY_LEFT), new Runnable() { |
||||||
|
|
||||||
|
@Override |
||||||
|
public void run() |
||||||
|
{ |
||||||
|
for (AnimDouble a : anims) { |
||||||
|
a.animate(1, 0, 1+rand.nextDouble()*1); |
||||||
|
} |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@Override |
||||||
|
protected void renderScreen() |
||||||
|
{ |
||||||
|
double screenH = Display.getHeight(); |
||||||
|
double screenW = Display.getWidth(); |
||||||
|
double perBoxH = screenH / anims.length; |
||||||
|
double padding = perBoxH * 0.1; |
||||||
|
double boxSide = perBoxH - padding * 2; |
||||||
|
|
||||||
|
for (int i = 0; i < anims.length; i++) { |
||||||
|
AnimDouble a = anims[i]; |
||||||
|
|
||||||
|
RenderUtils.setColor(RGB.GREEN); |
||||||
|
RenderUtils.quadSize(padding + a.getCurrentValue() * (screenW - perBoxH), screenH - perBoxH * i - perBoxH + padding, boxSide, boxSide); |
||||||
|
} |
||||||
|
|
||||||
|
RenderUtils.setColor(RGB.YELLOW); |
||||||
|
RenderUtils.translate(new Coord(Display.getWidth() / 2, Display.getHeight() / 2)); |
||||||
|
RenderUtils.rotateZ(degAnim.getCurrentValue()); |
||||||
|
RenderUtils.quadSize(-10, -10, 20, 200); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@Override |
||||||
|
public void receive(MouseMotionEvent event) |
||||||
|
{ |
||||||
|
//
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@Override |
||||||
|
public void receive(MouseButtonEvent event) |
||||||
|
{ |
||||||
|
if (event.isDown()) { |
||||||
|
Coord vec = App.disp().getSize().half().vecTo(event.getPos()); |
||||||
|
|
||||||
|
Polar p = Polar.fromCoord(vec); |
||||||
|
|
||||||
|
degAnim.fadeTo(p.getAngleDeg() - 90, 1.5); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@Override |
||||||
|
protected void onEnter() |
||||||
|
{ |
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@Override |
||||||
|
protected void onLeave() |
||||||
|
{ |
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@Override |
||||||
|
protected void onSizeChanged(Coord size) |
||||||
|
{ |
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@Override |
||||||
|
protected void updateScreen(double delta) |
||||||
|
{ |
||||||
|
degAnim.update(delta); |
||||||
|
|
||||||
|
for (AnimDouble a : anims) { |
||||||
|
a.update(delta); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -1,9 +1,10 @@ |
|||||||
package mightypork.rogue.display.constraints; |
package mightypork.rogue.display.constraints; |
||||||
|
|
||||||
import mightypork.utils.math.coord.Coord; |
|
||||||
import mightypork.utils.math.coord.Rect; |
import mightypork.utils.math.coord.Rect; |
||||||
|
|
||||||
|
|
||||||
public interface ConstraintContext { |
public interface ConstraintContext { |
||||||
|
|
||||||
public Rect getRect(); |
public Rect getRect(); |
||||||
} |
} |
||||||
|
@ -1,322 +1,311 @@ |
|||||||
package mightypork.utils.math.easing; |
package mightypork.utils.math.easing; |
||||||
|
|
||||||
|
|
||||||
import mightypork.utils.math.Calc; |
|
||||||
|
|
||||||
|
|
||||||
/** |
/** |
||||||
* Easing function.<br> |
* EasingFunction function. |
||||||
* The easing function must be time-invariant and it's domain is [0-1]. |
|
||||||
* |
* |
||||||
* @author MightyPork |
* @author MightyPork |
||||||
*/ |
*/ |
||||||
public interface Easing { |
public abstract class Easing { |
||||||
|
|
||||||
/** |
/** |
||||||
* Get value of the easing function at given time. |
* Get value at time t. |
||||||
* |
* |
||||||
* @param time number in range 0..1 |
* @param t time parameter (t = 1..1) |
||||||
* @return value at given time |
* @return value at given t (0..1, can exceed if needed) |
||||||
*/ |
*/ |
||||||
public double get(double time); |
public abstract double get(double t); |
||||||
|
|
||||||
public static final Easing NONE = new Easing() { |
|
||||||
|
|
||||||
@Override |
/** |
||||||
public double get(double time) |
* Reverse an easing |
||||||
|
* |
||||||
|
* @param original original easing |
||||||
|
* @return reversed easing |
||||||
|
*/ |
||||||
|
public static Easing reverse(Easing original) |
||||||
{ |
{ |
||||||
double t = Calc.clampd(time, 0, 1); |
return new Reverse(original); |
||||||
|
|
||||||
return (t < 0.5 ? 0 : 1); |
|
||||||
} |
} |
||||||
}; |
|
||||||
|
|
||||||
public static final Easing LINEAR = new Easing() { |
|
||||||
|
|
||||||
@Override |
/** |
||||||
public double get(double time) |
* Combine two easings |
||||||
|
* |
||||||
|
* @param in initial easing |
||||||
|
* @param out terminal easing |
||||||
|
* @return product |
||||||
|
*/ |
||||||
|
public static Easing combine(Easing in, Easing out) |
||||||
{ |
{ |
||||||
double t = Calc.clampd(time, 0, 1); |
return new Composite(in, out); |
||||||
|
|
||||||
return t; |
|
||||||
} |
} |
||||||
}; |
|
||||||
|
|
||||||
public static final Easing QUADRATIC_IN = new Easing() { |
|
||||||
|
|
||||||
@Override |
/** |
||||||
public double get(double time) |
* Create "bilinear" easing - compose of straight and reverse. |
||||||
|
* |
||||||
|
* @param in initial easing |
||||||
|
* @return product |
||||||
|
*/ |
||||||
|
public static Easing inOut(Easing in) |
||||||
{ |
{ |
||||||
double t = Calc.clampd(time, 0, 1); |
return combine(in, reverse(in)); |
||||||
|
|
||||||
return t * t; |
|
||||||
} |
} |
||||||
}; |
|
||||||
|
|
||||||
public static final Easing QUADRATIC_OUT = new Easing() { |
/** |
||||||
|
* Reverse EasingFunction |
||||||
|
* |
||||||
|
* @author MightyPork |
||||||
|
*/ |
||||||
|
private static class Reverse extends Easing { |
||||||
|
|
||||||
|
private Easing ea; |
||||||
|
|
||||||
@Override |
|
||||||
public double get(double time) |
|
||||||
{ |
|
||||||
double t = Calc.clampd(time, 0, 1); |
|
||||||
|
|
||||||
return 1 - (t - 1) * (t - 1); |
/** |
||||||
|
* @param in Easing to reverse |
||||||
|
*/ |
||||||
|
public Reverse(Easing in) { |
||||||
|
this.ea = in; |
||||||
} |
} |
||||||
}; |
|
||||||
|
|
||||||
public static final Easing QUADRATIC = new Easing() { |
|
||||||
|
|
||||||
@Override |
@Override |
||||||
public double get(double time) |
public double get(double t) |
||||||
{ |
{ |
||||||
double t = Calc.clampd(time, 0, 1); |
return 1 - ea.get(1 - t); |
||||||
|
} |
||||||
if (t < 0.5) return QUADRATIC_IN.get(2 * t) * 0.5; |
|
||||||
return 0.5 + QUADRATIC_OUT.get(2 * t - 1) * 0.5; |
|
||||||
} |
} |
||||||
}; |
|
||||||
|
|
||||||
public static final Easing CUBIC_IN = new Easing() { |
|
||||||
|
|
||||||
@Override |
/** |
||||||
public double get(double time) |
* Composite EasingFunction (0-0.5 EasingFunction A, 0.5-1 EasingFunction B) |
||||||
{ |
* |
||||||
double t = Calc.clampd(time, 0, 1); |
* @author MightyPork |
||||||
|
*/ |
||||||
|
private static class Composite extends Easing { |
||||||
|
|
||||||
return t * t * t; |
private Easing in; |
||||||
} |
private Easing out; |
||||||
}; |
|
||||||
public static final Easing CUBIC_OUT = new Easing() { |
|
||||||
|
|
||||||
@Override |
|
||||||
public double get(double time) |
|
||||||
{ |
|
||||||
double t = Calc.clampd(time, 0, 1); |
|
||||||
|
|
||||||
return (t - 1) * (t - 1) * (t - 1) + 1; |
/** |
||||||
|
* Create a composite EasingFunction |
||||||
|
* |
||||||
|
* @param in initial EasingFunction |
||||||
|
* @param out terminal EasingFunction |
||||||
|
*/ |
||||||
|
public Composite(Easing in, Easing out) { |
||||||
|
this.in = in; |
||||||
|
this.out = out; |
||||||
} |
} |
||||||
}; |
|
||||||
public static final Easing CUBIC = new Easing() { |
|
||||||
|
|
||||||
@Override |
@Override |
||||||
public double get(double time) |
public double get(double t) |
||||||
{ |
{ |
||||||
double d = 1; |
if (t < 0.5) return in.get(2 * t) * 0.5; |
||||||
double t = time; |
return 0.5 + out.get(2 * t - 1) * 0.5; |
||||||
double b = 0; |
} |
||||||
double c = (1 - 0); |
|
||||||
t /= d / 2; |
|
||||||
if (t < 1) return c / 2 * t * t * t + b; |
|
||||||
t -= 2; |
|
||||||
return c / 2 * (t * t * t + 2) + b; |
|
||||||
} |
} |
||||||
}; |
|
||||||
public static final Easing QUARTIC_IN = new Easing() { |
/** No easing; At t=0.5 goes high. */ |
||||||
|
public static final Easing NONE = new Easing() { |
||||||
|
|
||||||
@Override |
@Override |
||||||
public double get(double time) |
public double get(double t) |
||||||
{ |
{ |
||||||
double d = 1; |
return (t < 0.5 ? 0 : 1); |
||||||
double t = time; |
|
||||||
double b = 0; |
|
||||||
double c = (1 - 0); |
|
||||||
t /= d; |
|
||||||
return c * t * t * t * t + b; |
|
||||||
} |
} |
||||||
}; |
}; |
||||||
public static final Easing QUARTIC_OUT = new Easing() { |
|
||||||
|
/** Linear (y=t) easing */ |
||||||
|
public static final Easing LINEAR = new Easing() { |
||||||
|
|
||||||
@Override |
@Override |
||||||
public double get(double time) |
public double get(double t) |
||||||
{ |
{ |
||||||
double d = 1; |
return t; |
||||||
double t = time; |
|
||||||
double b = 0; |
|
||||||
double c = (1 - 0); |
|
||||||
|
|
||||||
t /= d; |
|
||||||
t--; |
|
||||||
return -c * (t * t * t * t - 1) + b; |
|
||||||
} |
} |
||||||
}; |
}; |
||||||
public static final Easing QUARTIC = new Easing() { |
|
||||||
|
/** Quadratic (y=t^2) easing in */ |
||||||
|
public static final Easing QUADRATIC_IN = new Easing() { |
||||||
|
|
||||||
@Override |
@Override |
||||||
public double get(double time) |
public double get(double t) |
||||||
{ |
{ |
||||||
double d = 1; |
return t * t; |
||||||
double t = time; |
|
||||||
double b = 0; |
|
||||||
double c = (1 - 0); |
|
||||||
|
|
||||||
t /= d / 2; |
|
||||||
if (t < 1) return c / 2 * t * t * t * t + b; |
|
||||||
t -= 2; |
|
||||||
return -c / 2 * (t * t * t * t - 2) + b; |
|
||||||
} |
} |
||||||
}; |
}; |
||||||
public static final Easing QUINTIC_IN = new Easing() { |
|
||||||
|
/** Quadratic (y=t^2) easing out */ |
||||||
|
public static final Easing QUADRATIC_OUT = reverse(QUADRATIC_IN); |
||||||
|
|
||||||
|
/** Quadratic (y=t^2) easing both */ |
||||||
|
public static final Easing QUADRATIC_IN_OUT = inOut(QUADRATIC_IN); |
||||||
|
|
||||||
|
/** Cubic (y=t^3) easing in */ |
||||||
|
public static final Easing CUBIC_IN = new Easing() { |
||||||
|
|
||||||
@Override |
@Override |
||||||
public double get(double time) |
public double get(double t) |
||||||
{ |
{ |
||||||
double d = 1; |
return t * t * t; |
||||||
double t = time; |
|
||||||
double b = 0; |
|
||||||
double c = (1 - 0); |
|
||||||
t /= d; |
|
||||||
return c * t * t * t * t * t + b; |
|
||||||
} |
} |
||||||
}; |
}; |
||||||
public static final Easing QUINTIC_OUT = new Easing() { |
|
||||||
|
/** Cubic (y=t^3) easing out */ |
||||||
|
public static final Easing CUBIC_OUT = reverse(CUBIC_IN); |
||||||
|
|
||||||
|
/** Cubic (y=t^3) easing both */ |
||||||
|
public static final Easing CUBIC_IN_OUT = inOut(CUBIC_IN); |
||||||
|
|
||||||
|
/** Quartic (y=t^4) easing in */ |
||||||
|
public static final Easing QUARTIC_IN = new Easing() { |
||||||
|
|
||||||
@Override |
@Override |
||||||
public double get(double time) |
public double get(double t) |
||||||
{ |
{ |
||||||
double d = 1; |
return t * t * t * t; |
||||||
double t = time; |
|
||||||
double b = 0; |
|
||||||
double c = (1 - 0); |
|
||||||
t /= d; |
|
||||||
t--; |
|
||||||
return c * (t * t * t * t * t + 1) + b; |
|
||||||
} |
} |
||||||
}; |
}; |
||||||
public static final Easing QUINTIC_IN_OUT = new Easing() { |
|
||||||
|
/** Quartic (y=t^4) easing out */ |
||||||
|
public static final Easing QUARTIC_OUT = reverse(QUADRATIC_IN); |
||||||
|
|
||||||
|
/** Quartic (y=t^4) easing both */ |
||||||
|
public static final Easing QUARTIC_IN_OUT = inOut(QUADRATIC_IN); |
||||||
|
|
||||||
|
/** Quintic (y=t^5) easing in */ |
||||||
|
public static final Easing QUINTIC_IN = new Easing() { |
||||||
|
|
||||||
@Override |
@Override |
||||||
public double get(double time) |
public double get(double t) |
||||||
{ |
{ |
||||||
double d = 1; |
return t * t * t * t * t; |
||||||
double t = time; |
|
||||||
double b = 0; |
|
||||||
double c = (1 - 0); |
|
||||||
t /= d / 2; |
|
||||||
if (t < 1) return c / 2 * t * t * t * t * t + b; |
|
||||||
t -= 2; |
|
||||||
return c / 2 * (t * t * t * t * t + 2) + b; |
|
||||||
} |
} |
||||||
}; |
}; |
||||||
|
|
||||||
|
/** Quintic (y=t^5) easing out */ |
||||||
|
public static final Easing QUINTIC_OUT = reverse(QUINTIC_IN); |
||||||
|
|
||||||
|
/** Quintic (y=t^5) easing both */ |
||||||
|
public static final Easing QUINTIC_IN_OUT = inOut(QUINTIC_IN); |
||||||
|
|
||||||
|
/** Sine easing in */ |
||||||
public static final Easing SINE_IN = new Easing() { |
public static final Easing SINE_IN = new Easing() { |
||||||
|
|
||||||
@Override |
@Override |
||||||
public double get(double time) |
public double get(double t) |
||||||
{ |
{ |
||||||
double d = 1; |
return 1 - Math.cos(t * (Math.PI / 2)); |
||||||
double t = time; |
|
||||||
double b = 0; |
|
||||||
double c = (1 - 0); |
|
||||||
return -c * Math.cos(t / d * (Math.PI / 2)) + c + b; |
|
||||||
} |
} |
||||||
}; |
}; |
||||||
public static final Easing SINE_OUT = new Easing() { |
|
||||||
|
|
||||||
@Override |
/** Sine easing out */ |
||||||
public double get(double time) |
public static final Easing SINE_OUT = reverse(SINE_IN); |
||||||
{ |
|
||||||
double d = 1; |
|
||||||
double t = time; |
|
||||||
double b = 0; |
|
||||||
double c = (1 - 0); |
|
||||||
|
|
||||||
return c * Math.sin(t / d * (Math.PI / 2)) + b; |
/** Sine easing both */ |
||||||
} |
public static final Easing SINE_IN_OUT = inOut(SINE_IN); |
||||||
}; |
|
||||||
public static final Easing SINE = new Easing() { |
|
||||||
|
|
||||||
@Override |
/** Exponential easing in */ |
||||||
public double get(double time) |
|
||||||
{ |
|
||||||
double d = 1; |
|
||||||
double t = time; |
|
||||||
double b = 0; |
|
||||||
double c = (1 - 0); |
|
||||||
return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b; |
|
||||||
} |
|
||||||
}; |
|
||||||
public static final Easing EXPO_IN = new Easing() { |
public static final Easing EXPO_IN = new Easing() { |
||||||
|
|
||||||
@Override |
@Override |
||||||
public double get(double time) |
public double get(double t) |
||||||
{ |
{ |
||||||
double d = 1; |
return Math.pow(2, 10 * (t - 1)); |
||||||
double t = time; |
|
||||||
double b = 0; |
|
||||||
double c = (1 - 0); |
|
||||||
|
|
||||||
return c * Math.pow(2, 10 * (t / d - 1)) + b; |
|
||||||
} |
} |
||||||
}; |
}; |
||||||
public static final Easing EXPO_OUT = new Easing() { |
|
||||||
|
|
||||||
@Override |
/** Exponential easing out */ |
||||||
public double get(double time) |
public static final Easing EXPO_OUT = reverse(EXPO_IN); |
||||||
{ |
|
||||||
double d = 1; |
|
||||||
double t = time; |
|
||||||
double b = 0; |
|
||||||
double c = (1 - 0); |
|
||||||
|
|
||||||
return c * (-Math.pow(2, -10 * t / d) + 1) + b; |
/** Exponential easing both */ |
||||||
} |
public static final Easing EXPO_IN_OUT = inOut(EXPO_IN); |
||||||
}; |
|
||||||
public static final Easing EXPO = new Easing() { |
/** Circular easing in */ |
||||||
|
public static final Easing CIRC_IN = new Easing() { |
||||||
|
|
||||||
@Override |
@Override |
||||||
public double get(double time) |
public double get(double t) |
||||||
{ |
{ |
||||||
double d = 1; |
return 1 - Math.sqrt(1 - t * t); |
||||||
double t = time; |
|
||||||
double b = 0; |
|
||||||
double c = (1 - 0); |
|
||||||
|
|
||||||
t /= d / 2; |
|
||||||
if (t < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) + b; |
|
||||||
t--; |
|
||||||
return c / 2 * (-Math.pow(2, -10 * t) + 2) + b; |
|
||||||
} |
} |
||||||
}; |
}; |
||||||
public static final Easing CIRC_IN = new Easing() { |
|
||||||
|
/** Circular easing out */ |
||||||
|
public static final Easing CIRC_OUT = reverse(CIRC_IN); |
||||||
|
|
||||||
|
/** Circular easing both */ |
||||||
|
public static final Easing CIRC_IN_OUT = inOut(CIRC_IN); |
||||||
|
|
||||||
|
/** Bounce easing in */ |
||||||
|
public static final Easing BOUNCE_OUT = new Easing() { |
||||||
|
|
||||||
@Override |
@Override |
||||||
public double get(double time) |
public double get(double t) |
||||||
{ |
{ |
||||||
double d = 1; |
if (t < (1 / 2.75f)) { |
||||||
double t = time; |
return (7.5625f * t * t); |
||||||
double b = 0; |
|
||||||
double c = (1 - 0); |
} else if (t < (2 / 2.75f)) { |
||||||
t /= d; |
t -= (1.5f / 2.75f); |
||||||
return -c * (Math.sqrt(1 - t * t) - 1) + b; |
return (7.5625f * t * t + 0.75f); |
||||||
|
|
||||||
|
} else if (t < (2.5 / 2.75)) { |
||||||
|
t -= (2.25f / 2.75f); |
||||||
|
return (7.5625f * t * t + 0.9375f); |
||||||
|
|
||||||
|
} else { |
||||||
|
t -= (2.625f / 2.75f); |
||||||
|
return (7.5625f * t * t + 0.984375f); |
||||||
|
} |
||||||
} |
} |
||||||
}; |
}; |
||||||
public static final Easing CIRC_OUT = new Easing() { |
|
||||||
|
/** Bounce easing out */ |
||||||
|
public static final Easing BOUNCE_IN = reverse(BOUNCE_OUT); |
||||||
|
|
||||||
|
/** Bounce easing both */ |
||||||
|
public static final Easing BOUNCE_IN_OUT = inOut(BOUNCE_IN); |
||||||
|
|
||||||
|
/** Back easing in */ |
||||||
|
public static final Easing BACK_IN = new Easing() { |
||||||
|
|
||||||
@Override |
@Override |
||||||
public double get(double time) |
public double get(double t) |
||||||
{ |
{ |
||||||
double d = 1; |
float s = 1.70158f; |
||||||
double t = time; |
return t * t * ((s + 1) * t - s); |
||||||
double b = 0; |
|
||||||
double c = (1 - 0); |
|
||||||
|
|
||||||
t--; |
|
||||||
return c * Math.sqrt(1 - t * t) + b; |
|
||||||
} |
} |
||||||
}; |
}; |
||||||
public static final Easing CIRC = new Easing() { |
|
||||||
|
/** Back easing out */ |
||||||
|
public static final Easing BACK_OUT = reverse(BACK_IN); |
||||||
|
|
||||||
|
/** Back easing both */ |
||||||
|
public static final Easing BACK_IN_OUT = inOut(BACK_IN); |
||||||
|
|
||||||
|
/** Elastic easing in */ |
||||||
|
public static final Easing ELASTIC_IN = new Easing() { |
||||||
|
|
||||||
@Override |
@Override |
||||||
public double get(double time) |
public double get(double t) |
||||||
{ |
{ |
||||||
double d = 1; |
if (t == 0) return 0; |
||||||
double t = time; |
if (t == 1) return 1; |
||||||
double b = 0; |
|
||||||
double c = (1 - 0); |
double p = .3f; |
||||||
|
double s = p / 4; |
||||||
t /= d / 2; |
return -(Math.pow(2, 10 * (t -= 1)) * Math.sin((t - s) * (2 * Math.PI) / p)); |
||||||
if (t < 1) return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b; |
|
||||||
t -= 2; |
|
||||||
return c / 2 * (Math.sqrt(1 - t * t) + 1) + b; |
|
||||||
} |
} |
||||||
}; |
}; |
||||||
|
|
||||||
|
/** Elastic easing out */ |
||||||
|
public static final Easing ELASTIC_OUT = reverse(ELASTIC_IN); |
||||||
|
|
||||||
|
/** Elastic easing both */ |
||||||
|
public static final Easing ELASTIC_IN_OUT = inOut(ELASTIC_IN); |
||||||
} |
} |
||||||
|
@ -1,4 +1,4 @@ |
|||||||
package mightypork.utils.time; |
package mightypork.utils.time.animation; |
||||||
|
|
||||||
|
|
||||||
import mightypork.utils.math.Calc; |
import mightypork.utils.math.Calc; |
@ -1,4 +1,4 @@ |
|||||||
package mightypork.utils.time; |
package mightypork.utils.time.animation; |
||||||
|
|
||||||
|
|
||||||
import mightypork.utils.math.Calc; |
import mightypork.utils.math.Calc; |
Loading…
Reference in new issue