/** * Updates the values of the given color from the specified buffer at the index provided. * * @param store * the color to set data on * @param buf * the buffer to read from * @param index * the position (in terms of colors, not floats) to read from the buf */ public static void populateFromBuffer(final ColorRGBA store, final FloatBuffer buf, final int index) { store.setRed(buf.get(index * 4)); store.setGreen(buf.get(index * 4 + 1)); store.setBlue(buf.get(index * 4 + 2)); store.setAlpha(buf.get(index * 4 + 3)); }
/** * Updates the values of the given color from the specified buffer at the index provided. * * @param store * the color to set data on * @param buf * the buffer to read from * @param index * the position (in terms of colors, not floats) to read from the buf */ public static void populateFromBuffer(final ColorRGBA store, final FloatBuffer buf, final int index) { store.setRed(buf.get(index * 4)); store.setGreen(buf.get(index * 4 + 1)); store.setBlue(buf.get(index * 4 + 2)); store.setAlpha(buf.get(index * 4 + 3)); }
/** * @param index * which field index in this color to set. * @param value * to set to one of r, g, b or a. * @throws IllegalArgumentException * if index is not one of 0, 1, 2, 3. */ public void setValue(final int index, final float value) { switch (index) { case 0: setRed(value); return; case 1: setGreen(value); return; case 2: setBlue(value); return; case 3: setAlpha(value); return; } throw new IllegalArgumentException("index must be either 0, 1, 2 or 3"); }
/** * @param index * which field index in this color to set. * @param value * to set to one of r, g, b or a. * @throws IllegalArgumentException * if index is not one of 0, 1, 2, 3. */ public void setValue(final int index, final float value) { switch (index) { case 0: setRed(value); return; case 1: setGreen(value); return; case 2: setBlue(value); return; case 3: setAlpha(value); return; } throw new IllegalArgumentException("index must be either 0, 1, 2 or 3"); }
/** * Sets the value of this color to (r, g, b, a) * * @param r * new red value, generally should be in the range [0.0f, 1.0f] * @param g * new green value, generally should be in the range [0.0f, 1.0f] * @param b * new blue value, generally should be in the range [0.0f, 1.0f] * @param a * new alpha value, generally should be in the range [0.0f, 1.0f] * @return this color for chaining */ public ColorRGBA set(final float r, final float g, final float b, final float a) { setRed(r); setGreen(g); setBlue(b); setAlpha(a); return this; }
/** * Sets the value of this color to (r, g, b, a) * * @param r * new red value, generally should be in the range [0.0f, 1.0f] * @param g * new green value, generally should be in the range [0.0f, 1.0f] * @param b * new blue value, generally should be in the range [0.0f, 1.0f] * @param a * new alpha value, generally should be in the range [0.0f, 1.0f] * @return this color for chaining */ public ColorRGBA set(final float r, final float g, final float b, final float a) { setRed(r); setGreen(g); setBlue(b); setAlpha(a); return this; }
for (int x = 0; x < colors.length; x++) { final ColorRGBA c = new ColorRGBA(defaults); c.setRed(buff.get()); if (tupleSize > 1) { c.setGreen(buff.get());
for (int x = 0; x < colors.length; x++) { final ColorRGBA c = new ColorRGBA(defaults); c.setRed(buff.get()); if (tupleSize > 1) { c.setGreen(buff.get());
@Override public void read(final InputCapsule capsule) throws IOException { setRed(capsule.readFloat("r", 1)); setGreen(capsule.readFloat("g", 1)); setBlue(capsule.readFloat("b", 1)); setAlpha(capsule.readFloat("a", 1)); }
@Override public void read(final InputCapsule capsule) throws IOException { setRed(capsule.readFloat("r", 1)); setGreen(capsule.readFloat("g", 1)); setBlue(capsule.readFloat("b", 1)); setAlpha(capsule.readFloat("a", 1)); }
/** * Used with serialization. Not to be called manually. * * @param in * ObjectInput * @throws IOException * @throws ClassNotFoundException */ @Override public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { setRed(in.readFloat()); setGreen(in.readFloat()); setBlue(in.readFloat()); setAlpha(in.readFloat()); }
/** * Used with serialization. Not to be called manually. * * @param in * ObjectInput * @throws IOException * @throws ClassNotFoundException */ @Override public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { setRed(in.readFloat()); setGreen(in.readFloat()); setBlue(in.readFloat()); setAlpha(in.readFloat()); }
/** * Performs a linear interpolation between this color and the given end color, using the given scalar as a percent. * iow, if changeAmnt is closer to 0, the result will be closer to the current value of this color and if it is * closer to 1, the result will be closer to the end value. The result is stored back in this color. * * @param endColor * @param scalar * @return this color for chaining * @throws NullPointerException * if endVec is null. */ public ColorRGBA lerpLocal(final ReadOnlyColorRGBA endColor, final float scalar) { setRed((1.0f - scalar) * getRed() + scalar * endColor.getRed()); setGreen((1.0f - scalar) * getGreen() + scalar * endColor.getGreen()); setBlue((1.0f - scalar) * getBlue() + scalar * endColor.getBlue()); setAlpha((1.0f - scalar) * getAlpha() + scalar * endColor.getAlpha()); return this; }
/** * Performs a linear interpolation between the given begin and end colors, using the given scalar as a percent. iow, * if changeAmnt is closer to 0, the result will be closer to the begin value and if it is closer to 1, the result * will be closer to the end value. The result is stored back in this color. * * @param beginColor * @param endColor * @param changeAmnt * the scalar as a percent. * @return this color for chaining * @throws NullPointerException * if beginVec or endVec are null. */ public ColorRGBA lerpLocal(final ReadOnlyColorRGBA beginColor, final ReadOnlyColorRGBA endColor, final float scalar) { setRed((1.0f - scalar) * beginColor.getRed() + scalar * endColor.getRed()); setGreen((1.0f - scalar) * beginColor.getGreen() + scalar * endColor.getGreen()); setBlue((1.0f - scalar) * beginColor.getBlue() + scalar * endColor.getBlue()); setAlpha((1.0f - scalar) * beginColor.getAlpha() + scalar * endColor.getAlpha()); return this; }
/** * Performs a linear interpolation between this color and the given end color, using the given scalar as a percent. * iow, if changeAmnt is closer to 0, the result will be closer to the current value of this color and if it is * closer to 1, the result will be closer to the end value. The result is stored back in this color. * * @param endColor * @param scalar * @return this color for chaining * @throws NullPointerException * if endVec is null. */ public ColorRGBA lerpLocal(final ReadOnlyColorRGBA endColor, final float scalar) { setRed((1.0f - scalar) * getRed() + scalar * endColor.getRed()); setGreen((1.0f - scalar) * getGreen() + scalar * endColor.getGreen()); setBlue((1.0f - scalar) * getBlue() + scalar * endColor.getBlue()); setAlpha((1.0f - scalar) * getAlpha() + scalar * endColor.getAlpha()); return this; }
/** * Performs a linear interpolation between the given begin and end colors, using the given scalar as a percent. iow, * if changeAmnt is closer to 0, the result will be closer to the begin value and if it is closer to 1, the result * will be closer to the end value. The result is stored back in this color. * * @param beginColor * @param endColor * @param changeAmnt * the scalar as a percent. * @return this color for chaining * @throws NullPointerException * if beginVec or endVec are null. */ public ColorRGBA lerpLocal(final ReadOnlyColorRGBA beginColor, final ReadOnlyColorRGBA endColor, final float scalar) { setRed((1.0f - scalar) * beginColor.getRed() + scalar * endColor.getRed()); setGreen((1.0f - scalar) * beginColor.getGreen() + scalar * endColor.getGreen()); setBlue((1.0f - scalar) * beginColor.getBlue() + scalar * endColor.getBlue()); setAlpha((1.0f - scalar) * beginColor.getAlpha() + scalar * endColor.getAlpha()); return this; }
@Test public void testGetSet() { final ColorRGBA clr1 = new ColorRGBA(); clr1.setRed(0f); assertTrue(clr1.getRed() == 0.0f); clr1.setRed(Float.POSITIVE_INFINITY); assertTrue(clr1.getRed() == Float.POSITIVE_INFINITY); clr1.setRed(Float.NEGATIVE_INFINITY); assertTrue(clr1.getRed() == Float.NEGATIVE_INFINITY); assertTrue(clr1.getValue(0) == Float.NEGATIVE_INFINITY);