Grayscale extends ScaledContinuousColorMapper { @Override public Paint get(double value) { Double v = scale(value); v = applyMode(v, 0.0, 1.0); if (!MathUtils.isCalculatable(v)) { return null; } double lightness = 100.0*v; double[] rgb = GraphicsUtils.luv2rgb(new double[] {lightness, 0.0, 0.0}, null); return new Color( (float) MathUtils.limit(rgb[0], 0.0, 1.0), (float) MathUtils.limit(rgb[1], 0.0, 1.0), (float) MathUtils.limit(rgb[2], 0.0, 1.0) ); }  @Override Paint get(double value); @Override void setMode(Mode mode);  }
@Test public void testGet() { Grayscale c = new Grayscale(); assertEquals(new Color( 0, 0, 0), c.get(0.0)); assertEquals(new Color(119, 119, 119), c.get(0.5)); assertEquals(new Color(255, 255, 255), c.get(1.0)); }
@Test public void testSerialization() throws IOException, ClassNotFoundException { ScaledContinuousColorMapper original = new Grayscale(); ScaledContinuousColorMapper deserialized = TestUtils.serializeAndDeserialize(original); assertEquals(original.getMode(), deserialized.getMode()); for (double x=0.0; x<=1.0; x+=0.5) { assertEquals(original.get(x), deserialized.get(x)); } }