-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAnimacion.java
More file actions
36 lines (28 loc) · 1 KB
/
Animacion.java
File metadata and controls
36 lines (28 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import java.awt.*;
public class Animacion {
public static Point lerp(Point inicio, Point fin, double porcentaje) {
porcentaje = Math.clamp(porcentaje, 0.0, 1.0);
return new Point(
(int)(inicio.x + (fin.x - inicio.x) * porcentaje),
(int)(inicio.y + (fin.y - inicio.y) * porcentaje)
);
}
public static Point ease_in(Point inicio, Point fin, double porcentaje) {
return lerp(inicio, fin, ease_in_value(porcentaje));
}
public static Point ease_out(Point inicio, Point fin, double porcentaje) {
return lerp(inicio, fin, ease_out_value(porcentaje));
}
public static Point clamp_pos(Point punto, Point min, Point max) {
return new Point(Math.clamp(punto.x, min.x, max.x), Math.clamp(punto.y, min.y, max.y));
}
private static double ease_in_value(double t) {
return t*t;
}
private static double ease_out_value(double t) {
return flip(flip(t) * flip(t));
}
private static double flip(double x) {
return 1 - x;
}
}