示例#1
0
  /**
   * @param colors
   * @param step
   * @param wrap
   * @return
   */
  private int colorsBetween(final int[] colors, final float step, boolean wrap) {
    int length = colors.length - 1;

    if (wrap) {
      length = colors.length;
    }

    if (step <= 0) {
      return colors[0];
    }

    if (step >= 1) {
      return colors[colors.length - 1];
    }

    int a = (int) Math.floor(length * step);
    float f = 1.0f / length;
    float newStep = (step - (a * f)) / f;
    int nextA = Math.min(a + 1, length);

    if (wrap) {
      if (nextA >= colors.length) {
        nextA = 0;
      }
    }

    return colorBetween(colors[a], colors[nextA], newStep);
  }
示例#2
0
 // Return location at coordinates x, y on the screen
 public Location locationAt(float mousex, float mousey) {
   Location l =
       new Location((int) Math.floor((mousex - x) / dx), (int) Math.floor((mousey - y) / dy));
   return l;
 }