Generates a monochromatic color pallet of the passed color - Android Graphics

Android examples for Graphics:Color Operation

Description

Generates a monochromatic color pallet of the passed color

Demo Code


import android.graphics.Color;

public class Main {
  /**//from  w  ww.  j a  va  2s  .c  o  m
   * Generates a monochromatic color pallet of the passed color
   * 
   * @param color
   * @return color pallet
   */
  public static Integer[] getMonochromaticColorPallet(int color) {
    Integer[] colorPallet = new Integer[20];

    colorPallet[0] = shiftColorHSV(color, 0f, -0.5f, 0.5f);
    colorPallet[1] = shiftColorHSV(color, 0f, -0.4f, 0.4f);
    colorPallet[2] = shiftColorHSV(color, 0f, -0.3f, 0.3f);
    colorPallet[3] = shiftColorHSV(color, 0f, -0.2f, 0.2f);
    colorPallet[4] = shiftColorHSV(color, 0f, -0.1f, 0.1f);
    colorPallet[5] = shiftColorHSV(color, 0f, 0f, 0.1f);
    colorPallet[6] = shiftColorHSV(color, 0f, 0.1f, 0.2f);
    colorPallet[7] = shiftColorHSV(color, 0f, 0.2f, 0.3f);
    colorPallet[8] = shiftColorHSV(color, 0f, 0.3f, 0.4f);
    colorPallet[9] = shiftColorHSV(color, 0f, 0.4f, 0.5f);

    colorPallet[10] = shiftColorHSV(color, 0f, 0.5f, -0.5f);
    colorPallet[11] = shiftColorHSV(color, 0f, 0.4f, -0.4f);
    colorPallet[12] = shiftColorHSV(color, 0f, 0.3f, -0.3f);
    colorPallet[13] = shiftColorHSV(color, 0f, 0.2f, -0.2f);
    colorPallet[14] = shiftColorHSV(color, 0f, 0.1f, -0.1f);
    colorPallet[15] = shiftColorHSV(color, 0f, 0f, -0.1f);
    colorPallet[16] = shiftColorHSV(color, 0f, -0.1f, -0.2f);
    colorPallet[17] = shiftColorHSV(color, 0f, -0.2f, -0.3f);
    colorPallet[18] = shiftColorHSV(color, 0f, -0.3f, -0.4f);
    colorPallet[19] = shiftColorHSV(color, 0f, -0.4f, -0.5f);

    return colorPallet;
  }

  /**
   * Shifts the hsv of the color
   * 
   * @param color
   * @param offsetHue
   * @param offsetSaturation
   * @param offsetValue
   * @return shifted color
   */
  public static int shiftColorHSV(int color, float offsetHue, float offsetSaturation, float offsetValue) {
    float[] colorShiftHSV = new float[3];
    Color.colorToHSV(color, colorShiftHSV);

    colorShiftHSV[0] = (colorShiftHSV[0] + offsetHue) % 360;
    colorShiftHSV[1] = colorShiftHSV[1] + offsetSaturation;
    colorShiftHSV[2] = colorShiftHSV[2] + offsetValue;

    return Color.HSVToColor(colorShiftHSV);
  }
}

Related Tutorials