Compare commits
No commits in common. "1.19" and "1.16" have entirely different histories.
@ -0,0 +1,39 @@
|
|||||||
|
package me.topchetoeu.keystrokes.engine;
|
||||||
|
|
||||||
|
public class Fadeout {
|
||||||
|
public float slope;
|
||||||
|
public float duration;
|
||||||
|
|
||||||
|
private boolean near(float f) {
|
||||||
|
return near(slope, f);
|
||||||
|
}
|
||||||
|
private boolean near(float a, float b) {
|
||||||
|
return Math.abs(a - b) < 0.001f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float calculate(float delta) {
|
||||||
|
if (delta > duration) return 0;
|
||||||
|
|
||||||
|
if (near(0)) return 1;
|
||||||
|
if (near(1)) return 1 - delta / duration;
|
||||||
|
if (near(2)) return 1 - (float)Math.sqrt(delta / duration);
|
||||||
|
|
||||||
|
float pow = 1 / slope;
|
||||||
|
|
||||||
|
if (near(pow, Math.round(pow))) {
|
||||||
|
float a = delta / duration;
|
||||||
|
float b = 1;
|
||||||
|
|
||||||
|
for (int i = 0; i < pow; i++) b *= a;
|
||||||
|
|
||||||
|
return 1 - b;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1 - (float)Math.pow(delta / duration, pow);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Fadeout(float slope, float duration) {
|
||||||
|
this.slope = slope;
|
||||||
|
this.duration = duration;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user