public BRColorRamp (boolean inverted, double opacity) { super(inverted, Arrays.asList(new FixedPoint(0.25, 0.0), new FixedPoint(0.50, 0.5), new FixedPoint(1.00, 1.0)), Arrays.asList(new FixedPoint(0.25, 0.0), new FixedPoint(0.375, 0.25), new FixedPoint(0.625, 0.25), new FixedPoint(0.75, 0.0)), Arrays.asList(new FixedPoint(0.00, 0.5), new FixedPoint(0.25, 1.0), new FixedPoint(0.75, 0.0)), null, opacity); } }
public WareColorRamp (boolean inverted, double opacity) { super(inverted, Arrays.asList(new FixedPoint(0, 0.25), new FixedPoint(0.25, 0.9), new FixedPoint(0.5, 0.1), new FixedPoint(0.75, 1)), new ArrayList<FixedPoint>(), Arrays.asList(new FixedPoint(0, 0.25), new FixedPoint(0.25, 0), new FixedPoint(0.85, 0), new FixedPoint(1, 1)), null, opacity); } }
public GreyColorRamp (boolean inverted, double opacity) { super(inverted, Arrays.asList(new FixedPoint(0.0, 0.0), new FixedPoint(1.0, 1.0)), Arrays.asList(new FixedPoint(0.0, 0.0), new FixedPoint(1.0, 1.0)), Arrays.asList(new FixedPoint(0.0, 0.0), new FixedPoint(1.0, 1.0)), null, opacity); } }
public SingleGradientColorRamp (Color from, Color to) { super(false, Arrays.asList(new FixedPoint(0.0, from.getRed()/255.0), new FixedPoint(1.0, to.getRed()/255.0)), Arrays.asList(new FixedPoint(0.0, from.getGreen()/255.0), new FixedPoint(1.0, to.getGreen()/255.0)), Arrays.asList(new FixedPoint(0.0, from.getBlue()/255.0), new FixedPoint(1.0, to.getBlue()/255.0)), Arrays.asList(new FixedPoint(0.0, from.getAlpha()/255.0), new FixedPoint(1.0, to.getAlpha()/255.0)), 255); } }
public AbstractColorRamp (boolean inverted, List<FixedPoint> reds, List<FixedPoint> greens, List<FixedPoint> blues, List<FixedPoint> alphas, double opacity){ this.isInverted = inverted; this.reds = reds; this.greens = greens; this.blues = blues; if (null == alphas) { //there's no alphas, so initialize them with the single opacity field this.alphas = new ArrayList<>(); this.alphas.add(new FixedPoint(0, opacity)); this.alphas.add(new FixedPoint(1, opacity)); } else { this.alphas = alphas; } }
@Override public FixedPoint unencode (String string) throws ConfigurationException { String[] parts = string.split("by"); return new FixedPoint(Double.parseDouble(parts[0]), Double.parseDouble(parts[1])); }
@Override public FixedPoint unencodeJSON (JSONNode propertyNode) throws JSONException, ConfigurationException { JSONObject node = propertyNode.getAsJSONObject(); return new FixedPoint(node.getDouble("scale"), node.getDouble("value")); }
/** * Creates a stepped gradient from a list of colors. * * @param colors * The list of colors to step through at even intervals. * @return * The new ramp. */ public static SteppedGradientColorRamp from(List<Color> colors) { List<FixedPoint> red = new ArrayList<>(); List<FixedPoint> grn = new ArrayList<>(); List<FixedPoint> blu = new ArrayList<>(); List<FixedPoint> alp = new ArrayList<>(); int n = colors.size()-1; int i = 0; double point = 0.0; double interval = 1.0/n; for (Color c: colors) { red.add(new FixedPoint(point, c.getRed()/255.0)); grn.add(new FixedPoint(point, c.getGreen()/255.0)); blu.add(new FixedPoint(point, c.getBlue()/255.0)); alp.add(new FixedPoint(point, c.getAlpha()/255.0)); i++; point = i < n? i*interval : 1.0; } return new SteppedGradientColorRamp(red, grn, blu, alp); }
protected static List<FixedPoint> getFixedPointList(List<?> list) { int numPoints = list.size(); List<FixedPoint> pointList = new ArrayList<FixedPoint>(numPoints); for (int i = 0; i < numPoints; ++i) { Object obj = list.get(i); if (obj != null) { FixedPoint point = null; if (obj instanceof List) { //the element is a list, so it should be 2 numbers that form a FixedPoint point = getFixedPointFromList((List<?>)obj); } else if (obj instanceof Map) { point = getFixedPointFromMap((Map<?, ?>)obj); } else { point = new FixedPoint(0, 0); } pointList.add(point); } } return pointList; }
/** * Converts a list of items into a {@link FixedPoint}. * Uses the first element in the list as the scale, and the second element * as the value. * If the list doesn't have enough items, or the elements are not numbers, * then it treats them as 0. * * @param list * A list of numbers. * @return * Returns a {@link FixedPoint} based on the values in the list. */ protected static FixedPoint getFixedPointFromList(List<?> list) { double scale = 0; double value = 0; int numItems = list.size(); if (numItems >= 1) { //the scale should be the first item scale = JsonUtilities.getNumber(list.get(0)).doubleValue(); } if (numItems >= 2) { //the value should be the second item value = JsonUtilities.getNumber(list.get(1)).doubleValue(); } return new FixedPoint(scale, value); }
/** * Converts a map into a {@link FixedPoint}. * The map should contain a key labelled 'scale' or '0' for scale, * and 'value' or '1' for value. * If anything is missing, then it's considered 0. * * @param map * A string->object map to pull objects from. * @return * Returns a {@link FixedPoint} constructed from the elements of the map. */ protected static FixedPoint getFixedPointFromMap(Map<?, ?> map) { double scale = 0; double value = 0; if (map.containsKey("scale")) { scale = JsonUtilities.getNumber(map.get("scale")).doubleValue(); } else if (map.containsKey("value")) { value = JsonUtilities.getNumber(map.get("value")).doubleValue(); } else if (map.containsKey("0")) { scale = JsonUtilities.getNumber(map.get("0")).doubleValue(); } else if (map.containsKey("1")) { value = JsonUtilities.getNumber(map.get("1")).doubleValue(); } return new FixedPoint(scale, value); }
@Test public void testJSONSerialization () throws JSONException, ConfigurationException { FixedPointProperty prop = new FixedPointProperty("", ""); FixedPoint pt = new FixedPoint(3.0, 4.0); JSONObject root = new JSONObject(); JSONNode node = new JSONNode(root, "fixedpoint"); prop.encodeJSON(node, pt); FixedPoint redux = prop.unencodeJSON(node); Assert.assertEquals(pt, redux); } }
@Test public void testPropertyFileSerialization () throws ConfigurationException { FixedPointProperty prop = new FixedPointProperty("", ""); FixedPoint pt = new FixedPoint(3.0, 4.0); String encoded = prop.encode(pt); FixedPoint redux = prop.unencode(encoded); Assert.assertEquals(pt, redux); }