|
@@ -3,7 +3,6 @@ package squidpony.squidgrid.gui.gdx;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
|
|
import com.badlogic.gdx.graphics.Color;
|
|
import com.badlogic.gdx.graphics.Color;
|
|
-import com.badlogic.gdx.math.Interpolation;
|
|
|
|
|
|
|
|
import squidpony.IColorCenter;
|
|
import squidpony.IColorCenter;
|
|
import squidpony.IFilter;
|
|
import squidpony.IFilter;
|
|
@@ -65,27 +64,6 @@ public class SquidColorCenter extends IColorCenter.Skeleton<Color> {
|
|
return get(Math.round(255 * r), Math.round(255 * g), Math.round(255 * b), Math.round(255 * a));
|
|
return get(Math.round(255 * r), Math.round(255 * g), Math.round(255 * b), Math.round(255 * a));
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Gets the linear interpolation from Color start to Color end, changing by the
|
|
|
|
- * fraction given by change.
|
|
|
|
- *
|
|
|
|
- * @param start
|
|
|
|
- * the initial Color
|
|
|
|
- * @param end
|
|
|
|
- * the "target" color
|
|
|
|
- * @param change
|
|
|
|
- * the degree to change closer to end; a change of 0.0f produces
|
|
|
|
- * start, 1.0f produces end
|
|
|
|
- * @return a new Color
|
|
|
|
- */
|
|
|
|
- @Override
|
|
|
|
- public Color lerp(Color start, Color end, float change) {
|
|
|
|
- if (start == null || end == null)
|
|
|
|
- return Color.CLEAR;
|
|
|
|
- return get(start.r + change * (end.r - start.r), start.g + change * (end.g - start.g),
|
|
|
|
- start.b + change * (end.b - start.b), start.a + change * (end.a - start.a));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
@Override
|
|
@Override
|
|
public int getRed(Color c) {
|
|
public int getRed(Color c) {
|
|
return Math.round(c.r * 255f);
|
|
return Math.round(c.r * 255f);
|
|
@@ -127,114 +105,6 @@ public class SquidColorCenter extends IColorCenter.Skeleton<Color> {
|
|
return filter(color.cpy().mul(light));
|
|
return filter(color.cpy().mul(light));
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Lightens a color by degree and returns the new color (mixed with white).
|
|
|
|
- *
|
|
|
|
- * @param color
|
|
|
|
- * the color to lighten
|
|
|
|
- * @param degree
|
|
|
|
- * a float between 0.0f and 1.0f; more makes it lighter
|
|
|
|
- * @return the lightened (and if a filter is used, also filtered) new color
|
|
|
|
- */
|
|
|
|
- public Color light(Color color, float degree) {
|
|
|
|
- return lerp(color, Color.WHITE, degree);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Lightens a color slightly and returns the new color (10% mix with white).
|
|
|
|
- *
|
|
|
|
- * @param color
|
|
|
|
- * the color to lighten
|
|
|
|
- * @return the lightened (and if a filter is used, also filtered) new color
|
|
|
|
- */
|
|
|
|
- public Color light(Color color) {
|
|
|
|
- return lerp(color, Color.WHITE, 0.1f);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Lightens a color significantly and returns the new color (30% mix with
|
|
|
|
- * white).
|
|
|
|
- *
|
|
|
|
- * @param color
|
|
|
|
- * the color to lighten
|
|
|
|
- * @return the lightened (and if a filter is used, also filtered) new color
|
|
|
|
- */
|
|
|
|
- public Color lighter(Color color) {
|
|
|
|
- return lerp(color, Color.WHITE, 0.3f);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Lightens a color massively and returns the new color (70% mix with white).
|
|
|
|
- *
|
|
|
|
- * @param color
|
|
|
|
- * the color to lighten
|
|
|
|
- * @return the lightened (and if a filter is used, also filtered) new color
|
|
|
|
- */
|
|
|
|
- public Color lightest(Color color) {
|
|
|
|
- return lerp(color, Color.WHITE, 0.7f);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Darkens a color by the specified degree and returns the new color (mixed with
|
|
|
|
- * black).
|
|
|
|
- *
|
|
|
|
- * @param color
|
|
|
|
- * the color to darken
|
|
|
|
- * @param degree
|
|
|
|
- * a float between 0.0f and 1.0f; more makes it darker
|
|
|
|
- * @return the darkened (and if a filter is used, also filtered) new color
|
|
|
|
- */
|
|
|
|
- public Color dim(Color color, float degree) {
|
|
|
|
- return lerp(color, Color.BLACK, degree);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Darkens a color slightly and returns the new color (10% mix with black).
|
|
|
|
- *
|
|
|
|
- * @param color
|
|
|
|
- * the color to darken
|
|
|
|
- * @return the darkened (and if a filter is used, also filtered) new color
|
|
|
|
- */
|
|
|
|
- public Color dim(Color color) {
|
|
|
|
- return lerp(color, Color.BLACK, 0.1f);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Darkens a color significantly and returns the new color (30% mix with black).
|
|
|
|
- *
|
|
|
|
- * @param color
|
|
|
|
- * the color to darken
|
|
|
|
- * @return the darkened (and if a filter is used, also filtered) new color
|
|
|
|
- */
|
|
|
|
- public Color dimmer(Color color) {
|
|
|
|
- return lerp(color, Color.BLACK, 0.3f);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Darkens a color massively and returns the new color (70% mix with black).
|
|
|
|
- *
|
|
|
|
- * @param color
|
|
|
|
- * the color to darken
|
|
|
|
- * @return the darkened (and if a filter is used, also filtered) new color
|
|
|
|
- */
|
|
|
|
- public Color dimmest(Color color) {
|
|
|
|
- return lerp(color, Color.BLACK, 0.7f);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Gets a fully-desaturated version of the given color (keeping its brightness,
|
|
|
|
- * but making it grayscale).
|
|
|
|
- *
|
|
|
|
- * @param color
|
|
|
|
- * the color to desaturate (will not be modified)
|
|
|
|
- * @return the grayscale version of color
|
|
|
|
- */
|
|
|
|
- @Override
|
|
|
|
- public Color desaturated(Color color) {
|
|
|
|
- float f = color.r * 0.299f + color.g * 0.587f + color.b * 0.114f;
|
|
|
|
- return get(f, f, f, color.a);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Gets a fully random color that is only required to be opaque.
|
|
* Gets a fully random color that is only required to be opaque.
|
|
*
|
|
*
|
|
@@ -245,173 +115,6 @@ public class SquidColorCenter extends IColorCenter.Skeleton<Color> {
|
|
return get(rng.nextFloat(), rng.nextFloat(), rng.nextFloat(), 1f);
|
|
return get(rng.nextFloat(), rng.nextFloat(), rng.nextFloat(), 1f);
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Blends a color with a random (opaque) color by a factor of 10% random.
|
|
|
|
- *
|
|
|
|
- * @param color
|
|
|
|
- * the color to randomize
|
|
|
|
- * @return the randomized (and if a filter is used, also filtered) new color
|
|
|
|
- */
|
|
|
|
- public Color randomize(Color color) {
|
|
|
|
- return lerp(color, random(), 0.1f);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Blends a color with a random (opaque) color by a factor of 30% random.
|
|
|
|
- *
|
|
|
|
- * @param color
|
|
|
|
- * the color to randomize
|
|
|
|
- * @return the randomized (and if a filter is used, also filtered) new color
|
|
|
|
- */
|
|
|
|
- public Color randomizeMore(Color color) {
|
|
|
|
- return lerp(color, random(), 0.3f);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Blends a color with a random (opaque) color by a factor of 70% random.
|
|
|
|
- *
|
|
|
|
- * @param color
|
|
|
|
- * the color to randomize
|
|
|
|
- * @return the randomized (and if a filter is used, also filtered) new color
|
|
|
|
- */
|
|
|
|
- public Color randomizeMost(Color color) {
|
|
|
|
- return lerp(color, random(), 0.7f);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Blends the colors A and B by a random degree.
|
|
|
|
- *
|
|
|
|
- * @param a
|
|
|
|
- * a color to mix in
|
|
|
|
- * @param b
|
|
|
|
- * another color to mix in
|
|
|
|
- * @return a random blend of a and b.
|
|
|
|
- */
|
|
|
|
- public Color randomBlend(Color a, Color b) {
|
|
|
|
- return lerp(a, b, DefaultResources.getGuiRandom().nextFloat());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Finds a 16-step gradient going from fromColor to toColor, both included in
|
|
|
|
- * the gradient.
|
|
|
|
- *
|
|
|
|
- * @param fromColor
|
|
|
|
- * the color to start with, included in the gradient
|
|
|
|
- * @param toColor
|
|
|
|
- * the color to end on, included in the gradient
|
|
|
|
- * @return a 16-element ArrayList composed of the blending steps from fromColor
|
|
|
|
- * to toColor
|
|
|
|
- */
|
|
|
|
- public ArrayList<Color> gradient(Color fromColor, Color toColor) {
|
|
|
|
- ArrayList<Color> colors = new ArrayList<>(16);
|
|
|
|
- for (int i = 0; i < 16; i++) {
|
|
|
|
- colors.add(lerp(fromColor, toColor, i / 15f));
|
|
|
|
- }
|
|
|
|
- return colors;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Finds a gradient with the specified number of steps going from fromColor to
|
|
|
|
- * toColor, both included in the gradient.
|
|
|
|
- *
|
|
|
|
- * @param fromColor
|
|
|
|
- * the color to start with, included in the gradient
|
|
|
|
- * @param toColor
|
|
|
|
- * the color to end on, included in the gradient
|
|
|
|
- * @param steps
|
|
|
|
- * the number of elements to use in the gradient
|
|
|
|
- * @return an ArrayList composed of the blending steps from fromColor to
|
|
|
|
- * toColor, with length equal to steps
|
|
|
|
- */
|
|
|
|
- public ArrayList<Color> gradient(Color fromColor, Color toColor, int steps) {
|
|
|
|
- return gradient(fromColor, toColor, steps, Interpolation.linear);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Finds a gradient with the specified number of steps going from fromColor to
|
|
|
|
- * midColor, then midColor to (possibly) fromColor, with both included in the
|
|
|
|
- * gradient but fromColor only repeated at the end if the number of steps is
|
|
|
|
- * odd.
|
|
|
|
- *
|
|
|
|
- * @param fromColor
|
|
|
|
- * the color to start with (and end with, if steps is an odd number),
|
|
|
|
- * included in the gradient
|
|
|
|
- * @param midColor
|
|
|
|
- * the color to use in the middle of the loop, included in the
|
|
|
|
- * gradient
|
|
|
|
- * @param steps
|
|
|
|
- * the number of elements to use in the gradient, will be at least 3
|
|
|
|
- * @return an ArrayList composed of the blending steps from fromColor to
|
|
|
|
- * midColor to fromColor again, with length equal to steps
|
|
|
|
- */
|
|
|
|
- public ArrayList<Color> loopingGradient(Color fromColor, Color midColor, int steps) {
|
|
|
|
- return loopingGradient(fromColor, midColor, steps, Interpolation.linear);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Finds a gradient with the specified number of steps going from fromColor to
|
|
|
|
- * toColor, both included in the gradient. The interpolation argument can be
|
|
|
|
- * used to make the color stay close to fromColor and/or toColor longer than it
|
|
|
|
- * would normally, or shorter if the middle colors are desirable.
|
|
|
|
- *
|
|
|
|
- * @param fromColor
|
|
|
|
- * the color to start with, included in the gradient
|
|
|
|
- * @param toColor
|
|
|
|
- * the color to end on, included in the gradient
|
|
|
|
- * @param steps
|
|
|
|
- * the number of elements to use in the gradient
|
|
|
|
- * @param interpolation
|
|
|
|
- * a libGDX Interpolation that defines how quickly the color changes
|
|
|
|
- * during the transition
|
|
|
|
- * @return an ArrayList composed of the blending steps from fromColor to
|
|
|
|
- * toColor, with length equal to steps
|
|
|
|
- */
|
|
|
|
- public ArrayList<Color> gradient(Color fromColor, Color toColor, int steps, Interpolation interpolation) {
|
|
|
|
- ArrayList<Color> colors = new ArrayList<>((steps > 1) ? steps : 1);
|
|
|
|
- colors.add(filter(fromColor));
|
|
|
|
- if (steps < 2)
|
|
|
|
- return colors;
|
|
|
|
- for (float i = 1; i < steps; i++) {
|
|
|
|
- colors.add(lerp(fromColor, toColor, interpolation.apply(i / (steps - 1))));
|
|
|
|
- }
|
|
|
|
- return colors;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Finds a gradient with the specified number of steps going from fromColor to
|
|
|
|
- * midColor, then midColor to (possibly) fromColor, with both included in the
|
|
|
|
- * gradient but fromColor only repeated at the end if the number of steps is
|
|
|
|
- * odd. The interpolation argument can be used to make the color linger for a
|
|
|
|
- * while with colors close to fromColor or midColor, or to do the opposite and
|
|
|
|
- * quickly change from one and spend more time in the middle.
|
|
|
|
- *
|
|
|
|
- * @param fromColor
|
|
|
|
- * the color to start with (and end with, if steps is an odd number),
|
|
|
|
- * included in the gradient
|
|
|
|
- * @param midColor
|
|
|
|
- * the color to use in the middle of the loop, included in the
|
|
|
|
- * gradient
|
|
|
|
- * @param steps
|
|
|
|
- * the number of elements to use in the gradient, will be at least 3
|
|
|
|
- * @param interpolation
|
|
|
|
- * a libGDX Interpolation that defines how quickly the color changes
|
|
|
|
- * at the start and end of each transition, both from fromColor to
|
|
|
|
- * midColor as well as back to fromColor
|
|
|
|
- * @return an ArrayList composed of the blending steps from fromColor to
|
|
|
|
- * midColor to fromColor again, with length equal to steps
|
|
|
|
- */
|
|
|
|
- public ArrayList<Color> loopingGradient(Color fromColor, Color midColor, int steps, Interpolation interpolation) {
|
|
|
|
- ArrayList<Color> colors = new ArrayList<>((steps > 3) ? steps : 3);
|
|
|
|
- colors.add(filter(fromColor));
|
|
|
|
- for (float i = 1; i < steps / 2; i++) {
|
|
|
|
- colors.add(lerp(fromColor, midColor, interpolation.apply(i / (steps / 2))));
|
|
|
|
- }
|
|
|
|
- for (float i = 0, c = steps / 2; c < steps; i++, c++) {
|
|
|
|
- colors.add(lerp(midColor, fromColor, interpolation.apply(i / (steps / 2))));
|
|
|
|
- }
|
|
|
|
- return colors;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Finds a gradient with the specified number of steps going from fromColor to
|
|
* Finds a gradient with the specified number of steps going from fromColor to
|
|
* toColor, both included in the gradient. This does not typically take a direct
|
|
* toColor, both included in the gradient. This does not typically take a direct
|