Colouring.java :  » UnTagged » sirius-android » org » mips » Sirius » ui » Android Open Source

Android Open Source » UnTagged » sirius android 
sirius android » org » mips » Sirius » ui » Colouring.java
/**
 * 
 */
package org.mips.Sirius.ui;

import android.graphics.Color;

/**
 * @author mips
 * 
 *         This class provides a fixed set of colours which can be used to
 *         colour a fixed set of items. These colours are as different as
 *         possible.
 */
public class Colouring {
  /*
   * Retrieves the colour in hex-HTML notation (no #). Numbering starts from
   * 0.
   */
  public static int getColour(int number, int divisions) {

    // check for valid input
    if ((number + 1 > divisions) || (divisions < 1))
      return 0;

    // uses the HSV colour space to evenly distribute the colours
    float[] hsv = new float[3];
    hsv[0] = (360 / divisions) * number;
    hsv[1] = .7f;
    hsv[2] = 1;

    int colour = Color.HSVToColor(hsv);

    return colour;
  }

  public static String getHTMLColour(int colour) {
    return Integer.toHexString(colour).substring(2).toUpperCase();
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.