Get hue ring color array - Android Graphics

Android examples for Graphics:Color Hue

Description

Get hue ring color array

Demo Code


import android.graphics.Color;

public class Main{
    /**//from  w  ww .ja v  a  2 s .  co  m
     * Get hue ring color array
     * @param n number of colors in array
     * @return hue color array
     */
    public static int[] getHueRingColors(int n) {
        int[] c = new int[n];

        for (int i = 0; i < n; i++)
            c[i] = Color
                    .HSVToColor(new float[] { (float) i / n * 360, 1, 1 });

        return c;
    }
    public static int[] getHueRingColors(int n, float saturation,
            float value) {
        int[] c = new int[n];

        for (int i = 0; i < n; i++)
            c[i] = getColorFromHSV(i / (n - 1f) * 360f, saturation, value);

        return c;
    }
    /**
     * Get color at specific hue angle, saturation and value
     * @param angle angle in degrees
     * @param saturation color saturation
     * @param value color value
     * @return color at specific hue angle, saturation and value
     */
    public static int getColorFromHSV(float angle, float saturation,
            float value) {
        angle = Utils.normalizeAngle(angle);
        return Color.HSVToColor(new float[] { angle, saturation, value });
    }
}

Related Tutorials