Browse Source

Remove stuff I don't use and which I didn't write in IColorCenter (adapted SquidColorCenter because I cannot get rid of it yet)

smelc 7 years ago
parent
commit
e03dd660be

+ 0 - 190
squidlib-util/src/main/java/squidpony/IColorCenter.java

@@ -124,16 +124,6 @@ public interface IColorCenter<T> {
 	 */
 	int getAlpha(T c);
 
-	/**
-	 *
-	 * @param c
-	 *            a concrete color
-	 * @return the value (essentially lightness) of the color from 0.0 (black,
-	 *         inclusive) to 1.0 (inclusive) for screen colors or arbitrarily high
-	 *         for HDR colors.
-	 */
-	float getValue(T c);
-
 	/**
 	 * @param c
 	 * @return The color that {@code this} shows when {@code c} is requested. May be
@@ -184,46 +174,6 @@ public interface IColorCenter<T> {
 			this.filter = filter;
 		}
 
-		/**
-		 * It clears the cache. You may need to do this to limit the cache to the colors
-		 * used in a specific section. This is also useful if a Filter changes what
-		 * colors it should return on a frame-by-frame basis; in that case, you can call
-		 * clearCache() at the start or end of a frame to ensure the next frame gets
-		 * different colors.
-		 */
-		public void clearCache() {
-			cache.clear();
-		}
-
-		/**
-		 * You may want to copy colors between IColorCenter instances that have
-		 * different create() methods -- and as such, will have different values for the
-		 * same keys in the cache. This allows you to copy the cache from other into
-		 * this Skeleton, but using this Skeleton's create() method.
-		 * 
-		 * @param other
-		 *            another Skeleton of the same type that will have its cache copied
-		 *            into this Skeleton
-		 */
-		public void copyCache(Skeleton<T> other) {
-			for (Map.Entry<Long, T> k : other.cache.entrySet()) {
-				cache.put(k.getKey(), create(getRed(k.getValue()), getGreen(k.getValue()), getBlue(k.getValue()),
-						getAlpha(k.getValue())));
-			}
-		}
-
-		/**
-		 * If you're changing the filter, you should likely call {@link #clearCache()}.
-		 * 
-		 * @param filter
-		 *            The filter to use, or {@code null} to turn filtering OFF.
-		 * @return {@code this}
-		 */
-		public Skeleton<T> setFilter(IFilter<T> filter) {
-			this.filter = filter;
-			return this;
-		}
-
 		@Override
 		public T get(int red, int green, int blue, int opacity) {
 			final Long value = getUniqueIdentifier((short) red, (short) green, (short) blue, (short) opacity);
@@ -262,106 +212,6 @@ public interface IColorCenter<T> {
 			return get(rng.nextInt(256), rng.nextInt(256), rng.nextInt(256), opacity);
 		}
 
-		/**
-		 * @param r
-		 *            the red component in 0.0 to 1.0 range, typically
-		 * @param g
-		 *            the green component in 0.0 to 1.0 range, typically
-		 * @param b
-		 *            the blue component in 0.0 to 1.0 range, typically
-		 * @return the saturation of the color from 0.0 (a grayscale color; inclusive)
-		 *         to 1.0 (a bright color, exclusive)
-		 */
-		public float getSaturation(float r, float g, float b) {
-			float min = Math.min(Math.min(r, g), b); // Min. value of RGB
-			float max = Math.max(Math.max(r, g), b); // Min. value of RGB
-			float delta = max - min; // Delta RGB value
-
-			float saturation;
-
-			if (delta < 0.0001f) // This is a gray, no chroma...
-			{
-				saturation = 0;
-			} else // Chromatic data...
-			{
-				saturation = delta / max;
-			}
-			return saturation;
-		}
-
-		/**
-		 * @param r
-		 *            the red component in 0.0 to 1.0 range, typically
-		 * @param g
-		 *            the green component in 0.0 to 1.0 range, typically
-		 * @param b
-		 *            the blue component in 0.0 to 1.0 range, typically
-		 * @return the value (essentially lightness) of the color from 0.0 (black,
-		 *         inclusive) to 1.0 (inclusive) for screen colors or arbitrarily high
-		 *         for HDR colors.
-		 */
-		public float getValue(float r, float g, float b) {
-			return Math.max(Math.max(r, g), b);
-		}
-
-		/**
-		 * @param c
-		 *            a concrete color
-		 * @return the value (essentially lightness) of the color from 0.0 (black,
-		 *         inclusive) to 1.0 (inclusive) for screen colors or arbitrarily high
-		 *         for HDR colors.
-		 */
-		@Override
-		public float getValue(T c) {
-			float r = getRed(c) / 255f; // RGB from 0 to 255
-			float g = getGreen(c) / 255f;
-			float b = getBlue(c) / 255f;
-
-			return Math.max(Math.max(r, g), b);
-		}
-
-		/**
-		 * @param r
-		 *            the red component in 0.0 to 1.0 range, typically
-		 * @param g
-		 *            the green component in 0.0 to 1.0 range, typically
-		 * @param b
-		 *            the blue component in 0.0 to 1.0 range, typically
-		 * @return The hue of the color from 0.0 (red, inclusive) towards orange, then
-		 *         yellow, and eventually to purple before looping back to almost the
-		 *         same red (1.0, exclusive)
-		 */
-		public float getHue(float r, float g, float b) {
-			float min = Math.min(Math.min(r, g), b); // Min. value of RGB
-			float max = Math.max(Math.max(r, g), b); // Min. value of RGB
-			float delta = max - min; // Delta RGB value
-
-			float hue;
-
-			if (delta < 0.0001f) // This is a gray, no chroma...
-			{
-				hue = 0; // HSV results from 0 to 1
-			} else // Chromatic data...
-			{
-				float rDelta = (((max - r) / 6f) + (delta / 2f)) / delta;
-				float gDelta = (((max - g) / 6f) + (delta / 2f)) / delta;
-				float bDelta = (((max - b) / 6f) + (delta / 2f)) / delta;
-
-				if (r == max)
-					hue = bDelta - gDelta;
-				else if (g == max)
-					hue = (1f / 3f) + rDelta - bDelta;
-				else
-					hue = (2f / 3f) + gDelta - rDelta;
-
-				if (hue < 0)
-					hue += 1f;
-				else if (hue > 1)
-					hue -= 1;
-			}
-			return hue;
-		}
-
 		@Override
 		public T filter(T c) {
 			return c == null ? c : get(getRed(c), getGreen(c), getBlue(c), getAlpha(c));
@@ -435,46 +285,6 @@ public interface IColorCenter<T> {
 			return get(mean, mean, mean, newAlpha);
 		}
 
-		/**
-		 * Gets the linear interpolation from Color start to Color end, changing by the
-		 * fraction given by change. This implementation tries to work with colors in a
-		 * way that is as general as possible, using getRed() instead of some specific
-		 * detail that depends on how a color is implemented. Other implementations that
-		 * specialize in a specific type of color may be able to be more efficient.
-		 * 
-		 * @param start
-		 *            the initial color T
-		 * @param end
-		 *            the "target" color T
-		 * @param change
-		 *            the degree to change closer to end; a change of 0.0f produces
-		 *            start, 1.0f produces end
-		 * @return a new T between start and end
-		 */
-		public T lerp(T start, T end, float change) {
-			if (start == null || end == null)
-				return null;
-			final int sr = getRed(start), sg = getGreen(start), sb = getBlue(start), sa = getAlpha(start),
-					er = getRed(end), eg = getGreen(end), eb = getBlue(end), ea = getAlpha(end);
-			return get((int) (sr + change * (er - sr)), (int) (sg + change * (eg - sg)),
-					(int) (sb + change * (eb - sb)), (int) (sa + change * (ea - sa)));
-		}
-
-		/**
-		 * Gets a fully-desaturated version of the given color (keeping its brightness,
-		 * but making it grayscale). Keeps alpha the same; if you want alpha to be
-		 * considered (and brightness to be calculated differently), then you can use
-		 * greify() in this class instead.
-		 * 
-		 * @param color
-		 *            the color T to desaturate (will not be modified)
-		 * @return the grayscale version of color
-		 */
-		public T desaturated(T color) {
-			int f = (int) Math.min(255, getRed(color) * 0.299f + getGreen(color) * 0.587f + getBlue(color) * 0.114f);
-			return get(f, f, f, getAlpha(color));
-		}
-
 		/**
 		 * Create a concrete instance of the color type given as a type parameter.
 		 * That's the place to use the {@link #filter}.

+ 0 - 297
squidlib/src/main/java/squidpony/squidgrid/gui/gdx/SquidColorCenter.java

@@ -3,7 +3,6 @@ package squidpony.squidgrid.gui.gdx;
 import java.util.ArrayList;
 
 import com.badlogic.gdx.graphics.Color;
-import com.badlogic.gdx.math.Interpolation;
 
 import squidpony.IColorCenter;
 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));
 	}
 
-	/**
-	 * 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
 	public int getRed(Color c) {
 		return Math.round(c.r * 255f);
@@ -127,114 +105,6 @@ public class SquidColorCenter extends IColorCenter.Skeleton<Color> {
 		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.
 	 * 
@@ -245,173 +115,6 @@ public class SquidColorCenter extends IColorCenter.Skeleton<Color> {
 		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
 	 * toColor, both included in the gradient. This does not typically take a direct