Exemple #1
0
  /**
   * Find the color band that this value falls in and assign that color.
   *
   * @param v
   * @param color
   */
  private final void absoluteValue(final double v, final int[] color) {
    final double search;
    switch (scaling) {
      case Absolute:
        search = v;
        break;
      case MinMax:
        search = (v - min) / (max - min);
        break;
      case Modulo:
        search = v % (max - min);
        break;
      default:
        search = 0;
        break;
    }

    final Map.Entry<Double, Color> lower = floorEntry(search);

    Color c;
    if (lower == null) {
      c = entrySet().iterator().next().getValue();
    } else {
      c = lower.getValue();
    }

    color[R] = c.getRed();
    color[G] = c.getGreen();
    color[B] = c.getBlue();
    color[A] = c.getAlpha();
  }
Exemple #2
0
  /**
   * Interpolate the color value for the given scalar value. The result is placed in color.
   *
   * @param v
   * @param color
   * @return
   */
  private final void interpolateValue(final double v, final int[] color) {
    final double search;
    switch (scaling) {
      case Absolute:
        search = v;
        break;
      case MinMax:
        search = (v - min) / (max - min);
        break;
      case Modulo:
        search = (v - min) % (max - min);
        break;
      default:
        search = 0;
        break;
    }

    final Map.Entry<Double, Color> lower = floorEntry(search);
    final Map.Entry<Double, Color> upper = higherEntry(search);

    assert (upper != null || lower != null);

    if (upper == null) {
      final Color c = lower.getValue();
      color[R] = c.getRed();
      color[G] = c.getGreen();
      color[B] = c.getBlue();
      color[A] = c.getAlpha();
    } else if (lower == null) {
      final Color c = upper.getValue();
      color[R] = c.getRed();
      color[G] = c.getGreen();
      color[B] = c.getBlue();
      color[A] = c.getAlpha();
    } else {
      final double diff = upper.getKey().doubleValue() - lower.getKey().doubleValue();
      final double lw = 1.0 - ((search - lower.getKey().doubleValue()) / diff);
      final double uw = 1.0 - lw;

      final Color lc = lower.getValue();
      final Color uc = upper.getValue();
      color[R] = (int) Math.round(lc.getRed() * lw + uc.getRed() * uw);
      color[G] = (int) Math.round(lc.getGreen() * lw + uc.getGreen() * uw);
      color[B] = (int) Math.round(lc.getBlue() * lw + uc.getBlue() * uw);
      color[A] = (int) Math.round(lc.getAlpha() * lw + uc.getAlpha() * uw);
    }
  }
 @Override
 public void write(final OutputStream out) throws IOException {
   out.write(TYPE_COLOR);
   super.write(out);
   out.write(color.getRed());
   out.write(color.getGreen());
   out.write(color.getBlue());
   out.write(color.getAlpha());
 }
Exemple #4
0
 public void drawTileNumC(int tileNum, int x, int y, Color c, Graphics g) {
   BufferedImage coloredTile = tiles[tileNum];
   for (int i = 0; i < this.tW; i++) {
     for (int j = 0; j < this.tH; j++) {
       Color originalColor = new Color(coloredTile.getRGB(i, j), true);
       Color nc = new Color(c.getRed(), c.getGreen(), c.getBlue(), originalColor.getAlpha());
       coloredTile.setRGB(i, j, nc.getRGB());
     }
   }
   g.drawImage(tiles[tileNum], x, y, null);
 }