diff options
author | Filip Weiss <me@fiws.net> | 2020-07-11 13:06:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-11 14:06:43 +0300 |
commit | d4fb1f7c357822c4331c60e112decdf25b282bd5 (patch) | |
tree | f201f1983998aa049305afd4006284b68b6e585f /src/main/java | |
parent | 7bcbdfbe43638ea217e4301f487ca8962d77204a (diff) | |
download | LibGui-d4fb1f7c357822c4331c60e112decdf25b282bd5.tar.gz LibGui-d4fb1f7c357822c4331c60e112decdf25b282bd5.tar.bz2 LibGui-d4fb1f7c357822c4331c60e112decdf25b282bd5.zip |
RGB: add interpolate method (#64)
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/io/github/cottonmc/cotton/gui/widget/data/Color.java | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/data/Color.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/data/Color.java index 3dbbe39..92c27ce 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/data/Color.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/data/Color.java @@ -163,6 +163,23 @@ public interface Color { float c = getChroma()/255f; return c / (1 - Math.abs(2*l - 1)); } + + /** + * Calculates an interpolated value along the fraction t between 0.0 and 1.0. When t = 1.0, endVal is returned. + * Eg.: If this color is black, your endColor is white and t = 0.5 you get gray. + * + * @param endColor a Color to interpolate with + * @param t fraction between 0.0 and 1.0 + * + * @since 2.0.0 + */ + public RGB interpolate(RGB endColor, double t){ + double a = (endColor.getA() - this.getA()) * t + this.getA(); + double r = (endColor.getR() - this.getR()) * t + this.getR(); + double g = (endColor.getG() - this.getG()) * t + this.getG(); + double b = (endColor.getB() - this.getB()) * t + this.getB(); + return new RGB((int)a, (int)r, (int)g, (int)b); + } } public static class HSL implements Color { |