Example #1
0
 public synchronized void drawHeight(LGraphics g, int x, int y) {
   try {
     if (drawHeight == null) {
       drawHeight = new LImage(width, height, true);
       LGraphics gl = drawHeight.getLGraphics();
       for (int i = 0; i < height; i++) {
         gl.setColor(
             new Color(
                 (start.getRed() * (height - i)) / height + (end.getRed() * i) / height,
                 (start.getGreen() * (height - i)) / height + (end.getGreen() * i) / height,
                 (start.getBlue() * (height - i)) / height + (end.getBlue() * i) / height,
                 alpha));
         gl.drawLine(0, i, width, i);
       }
       gl.dispose();
       gl = null;
     }
     g.drawImage(drawHeight, x, y);
   } catch (Exception e) {
     for (int i = 0; i < height; i++) {
       g.setColor(
           new Color(
               (start.getRed() * (height - i)) / height + (end.getRed() * i) / height,
               (start.getGreen() * (height - i)) / height + (end.getGreen() * i) / height,
               (start.getBlue() * (height - i)) / height + (end.getBlue() * i) / height,
               alpha));
       g.drawLine(x, i + y, x + width, i + y);
     }
   }
 }
Example #2
0
 public synchronized void drawWidth(LGraphics g, int x, int y) {
   try {
     if (drawWidth == null) {
       drawWidth = new LImage(width, height, true);
       LGraphics gl = drawWidth.getLGraphics();
       for (int i = 0; i < width; i++) {
         gl.setColor(
             new Color(
                 (start.getRed() * (width - i)) / width + (end.getRed() * i) / width,
                 (start.getGreen() * (width - i)) / width + (end.getGreen() * i) / width,
                 (start.getBlue() * (width - i)) / width + (end.getBlue() * i) / width,
                 alpha));
         gl.drawLine(i, 0, i, height);
       }
       gl.dispose();
       gl = null;
     }
     g.drawImage(drawWidth, x, y);
   } catch (Exception e) {
     for (int i = 0; i < width; i++) {
       g.setColor(
           new Color(
               (start.getRed() * (width - i)) / width + (end.getRed() * i) / width,
               (start.getGreen() * (width - i)) / width + (end.getGreen() * i) / width,
               (start.getBlue() * (width - i)) / width + (end.getBlue() * i) / width,
               alpha));
       g.drawLine(i + x, y, i + x, y + height);
     }
   }
 }
Example #3
0
 private Color rgbAverage(Color color1, Color color2, float rgb1amt) {
   float rgb2amt = 1 - rgb1amt;
   int red = (int) (color1.getRed() * rgb2amt + color2.getRed() * (1 - rgb2amt));
   int green = (int) (color1.getGreen() * rgb2amt + color2.getGreen() * (1 - rgb2amt));
   int blue = (int) (color1.getBlue() * rgb2amt + color2.getBlue() * (1 - rgb2amt));
   return new Color(red, green, blue);
 }
Example #4
0
  /**
   * Create a <code>LookupOp</code> object (lookup table) mapping the original pixels to the
   * background and foreground colors, respectively.
   *
   * @param bgColor the background color
   * @param fgColor the foreground color
   * @return the <code>LookupOp</code> object (lookup table)
   */
  private LookupOp setColors(Color bgColor, Color fgColor) {
    short[] a = new short[256];
    short[] r = new short[256];
    short[] g = new short[256];
    short[] b = new short[256];

    byte bgr = (byte) (bgColor.getRed());
    byte bgg = (byte) (bgColor.getGreen());
    byte bgb = (byte) (bgColor.getBlue());

    byte fgr = (byte) (fgColor.getRed());
    byte fgg = (byte) (fgColor.getGreen());
    byte fgb = (byte) (fgColor.getBlue());

    for (int i = 0; i < 256; i++) {
      if (i == 0) {
        a[i] = (byte) 255;
        r[i] = bgr;
        g[i] = bgg;
        b[i] = bgb;
      } else {
        a[i] = (byte) 255;
        r[i] = fgr;
        g[i] = fgg;
        b[i] = fgb;
      }
    }

    short[][] table = {r, g, b, a};
    return new LookupOp(new ShortLookupTable(0, table), null);
  }
    public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {

      Color shadow = UIManager.getColor("controlShadow");
      if (shadow == null) {
        shadow = Color.GRAY;
      }
      Color lightShadow = new Color(shadow.getRed(), shadow.getGreen(), shadow.getBlue(), 170);
      Color lighterShadow = new Color(shadow.getRed(), shadow.getGreen(), shadow.getBlue(), 70);
      g.translate(x, y);

      g.setColor(shadow);
      g.fillRect(0, 0, w - 3, 1);
      g.fillRect(0, 0, 1, h - 3);
      g.fillRect(w - 3, 1, 1, h - 3);
      g.fillRect(1, h - 3, w - 3, 1);
      // Shadow line 1
      g.setColor(lightShadow);
      g.fillRect(w - 3, 0, 1, 1);
      g.fillRect(0, h - 3, 1, 1);
      g.fillRect(w - 2, 1, 1, h - 3);
      g.fillRect(1, h - 2, w - 3, 1);
      // Shadow line2
      g.setColor(lighterShadow);
      g.fillRect(w - 2, 0, 1, 1);
      g.fillRect(0, h - 2, 1, 1);
      g.fillRect(w - 2, h - 2, 1, 1);
      g.fillRect(w - 1, 1, 1, h - 2);
      g.fillRect(1, h - 1, w - 2, 1);
      g.translate(-x, -y);
    }
  private static Color[] toColorsForLineMarkers(Color[] baseColors) {
    final Color[] colors = new Color[baseColors.length];
    final Color tagBackground = Gray._239;
    final double transparency = 0.4;
    final double factor = 0.8;

    for (int i = 0; i < colors.length; i++) {
      final Color color = baseColors[i];

      if (color == null) {
        colors[i] = null;
        continue;
      }

      int r = (int) (color.getRed() * factor);
      int g = (int) (color.getGreen() * factor);
      int b = (int) (color.getBlue() * factor);

      r = (int) (tagBackground.getRed() * (1 - transparency) + r * transparency);
      g = (int) (tagBackground.getGreen() * (1 - transparency) + g * transparency);
      b = (int) (tagBackground.getBlue() * (1 - transparency) + b * transparency);

      colors[i] = new Color(r, g, b);
    }

    return colors;
  }
Example #7
0
 public double getLightness() {
   int M = Math.max(color.getRed(), color.getGreen());
   M = Math.max(M, color.getBlue());
   int m = Math.min(color.getRed(), color.getGreen());
   m = Math.min(m, color.getBlue());
   return 0.5 * M + 0.5 * m;
 }
Example #8
0
 private Color tween(Color c1, Color c2, float p) {
   return new Color(
       (int) (c1.getRed() * (1 - p) + c2.getRed() * (p)),
       (int) (c1.getGreen() * (1 - p) + c2.getGreen() * (p)),
       (int) (c1.getBlue() * (1 - p) + c2.getBlue() * (p)),
       (int) (c1.getAlpha() * (1 - p) + c2.getAlpha() * (p)));
 }
Example #9
0
 private void paintBell(Graphics g) {
   P9TermPreferences preferences = P9Term.getPreferences();
   if (preferences.getBoolean(P9TermPreferences.VISUAL_BELL) == false) {
     return;
   }
   Color foreground = preferences.getColor(P9TermPreferences.FOREGROUND_COLOR);
   if (preferences.getBoolean(P9TermPreferences.FANCY_BELL)) {
     // On decent hardware, we can produce a really tasteful effect by compositing a
     // semi-transparent rectangle over the terminal.
     // We need to choose a color that will show up against the background.
     // A reasonable assumption is that the user has already chosen such a color for the
     // foreground.
     Color color =
         new Color(foreground.getRed(), foreground.getGreen(), foreground.getBlue(), 100);
     g.setColor(color);
     g.fillRect(0, 0, getWidth(), getHeight());
   } else {
     // On a remote X11 display (or really rubbish hardware) the compositing effect is
     // prohibitively expensive, so we offer XOR instead.
     Color background = preferences.getColor(P9TermPreferences.BACKGROUND_COLOR);
     ;
     final int R = blend(background.getRed(), foreground.getRed());
     final int G = blend(background.getGreen(), foreground.getGreen());
     final int B = blend(background.getBlue(), foreground.getBlue());
     g.setColor(background);
     g.setXORMode(new Color(R, G, B));
     g.fillRect(0, 0, getWidth(), getHeight());
     g.setPaintMode();
   }
 }
Example #10
0
  /**
   * @param one
   * @param two
   * @param three
   * @return
   *     <p>return new color RBG
   */
  private Color colorGenerator(Color one, Color two, Color three) {
    int red = (int) (one.getRed() + one.getBlue() + one.getGreen() / 3);
    int blue = (int) (two.getBlue() + two.getRed() + two.getGreen() / 3);
    int green = (int) (three.getGreen() + three.getRed() + three.getBlue() / 3);

    return new Color(red, blue, green);
  }
Example #11
0
  protected void computeColorsAndSpaces() {
    double space = 0;
    DataModel1D model1 = (DataModel1D) this.getDataModel();
    int stop = model1.getSize();
    colors = new Color[stop];
    spaces = new double[stop];
    Color origine = this.getColor(0);

    double mR = origine.getRed();
    double mV = origine.getGreen();
    double mB = origine.getBlue();
    double dR = (255D - origine.getRed()) / stop;
    double dV = (255D - origine.getGreen()) / stop;
    double dB = (255D - origine.getBlue()) / stop;
    for (int i = 0; i < stop; i++) {
      colors[i] = new Color((int) mR, (int) mV, (int) mB);
      mR += dR;
      mV += dV;
      mB += dB;
      spaces[i] = space;
    }
    // Apply user colors
    for (int i = 0; i < stop; i++) {
      if (i < labels.size()) {
        final Label label = labels.get(i);
        final Color color = colorMap.get(label);
        if (color != null) {
          colors[i] = color;
        }
      }
    }
  }
 public static void drawGradientRect(
     int x, int y, float z, int toX, int toY, Color color, Color colorFade) {
   GL11.glDisable(GL11.GL_TEXTURE_2D);
   GL11.glEnable(GL11.GL_BLEND);
   GL11.glDisable(GL11.GL_ALPHA_TEST);
   GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
   GL11.glShadeModel(GL11.GL_SMOOTH);
   Tessellator tes = Tessellator.getInstance();
   VertexBuffer vb = tes.getBuffer();
   vb.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
   vb.pos(toX, y, z)
       .color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha())
       .endVertex();
   vb.pos(x, y, z)
       .color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha())
       .endVertex();
   vb.pos(x, toY, z)
       .color(colorFade.getRed(), colorFade.getGreen(), colorFade.getBlue(), colorFade.getAlpha())
       .endVertex();
   vb.pos(toX, toY, z)
       .color(colorFade.getRed(), colorFade.getGreen(), colorFade.getBlue(), colorFade.getAlpha())
       .endVertex();
   tes.draw();
   GL11.glShadeModel(GL11.GL_FLAT);
   GL11.glDisable(GL11.GL_BLEND);
   GL11.glEnable(GL11.GL_ALPHA_TEST);
   GL11.glEnable(GL11.GL_TEXTURE_2D);
 }
 @Override
 public void storePreferences(Preferences prefs) {
   // app panel
   prefs.putBoolean("showPoints", appearancePanel.isShowPoints());
   prefs.putDouble("pointRadius", appearancePanel.getPointRadius());
   Color c = appearancePanel.getPointColor();
   prefs.putInt("pointColorRed", c.getRed());
   prefs.putInt("pointColorGreen", c.getGreen());
   prefs.putInt("pointColorBlue", c.getBlue());
   prefs.putBoolean("showLines", appearancePanel.isShowLines());
   prefs.putDouble("tubeRadius", appearancePanel.getTubeRadius());
   c = appearancePanel.getLineColor();
   prefs.putInt("lineColorRed", c.getRed());
   prefs.putInt("lineColorGreen", c.getGreen());
   prefs.putInt("lineColorBlue", c.getBlue());
   prefs.putBoolean("showFaces", appearancePanel.isShowFaces());
   prefs.putBoolean("facesReflecting", appearancePanel.isFacesReflecting());
   prefs.putBoolean("linesReflecting", appearancePanel.isLinesReflecting());
   prefs.putBoolean("pointsReflecting", appearancePanel.isPointsReflecting());
   prefs.putDouble("faceReflection", appearancePanel.getFaceReflection());
   prefs.putDouble("lineReflection", appearancePanel.getLineReflection());
   prefs.putDouble("pointReflection", appearancePanel.getPointReflection());
   c = appearancePanel.getFaceColor();
   prefs.putInt("faceColorRed", c.getRed());
   prefs.putInt("faceColorGreen", c.getGreen());
   prefs.putInt("faceColorBlue", c.getBlue());
   prefs.putBoolean("transparencyEnabled", appearancePanel.isTransparencyEnabled());
   prefs.putDouble("transparency", appearancePanel.getTransparency());
   prefs.putBoolean("facesFlat", appearancePanel.isFacesFlat());
   prefs.putBoolean("tubes", appearancePanel.getTubes());
   prefs.putBoolean("spheres", appearancePanel.getSpheres());
 }
Example #14
0
  /**
   * Return a color interpolated within the color list of this paint scale. The interpolation is a
   * linear one between the two colors in the list whose associated values frame the one given.
   */
  @Override
  public Color getPaint(double value) {
    if (colors.isEmpty()) return defaultColor;
    if (colors.size() == 1) return colors.get(colors.firstKey());

    if (value > upperBound) value = upperBound;
    if (value < lowerBound) value = lowerBound;
    Set<Double> keys = colors.keySet();
    double bottom = colors.firstKey();
    double top = colors.lastKey();
    for (double key : keys) {
      top = key;
      if (value < key) break;
      else bottom = top;
    }

    double alpha;
    if (top == bottom) alpha = 0; // we reached the end of the list
    else alpha = (value - bottom) / (top - bottom);

    Color colorBottom = colors.get(bottom);
    Color colorTop = colors.get(top);
    int red = (int) ((1 - alpha) * colorBottom.getRed() + alpha * colorTop.getRed());
    int green = (int) ((1 - alpha) * colorBottom.getGreen() + alpha * colorTop.getGreen());
    int blue = (int) ((1 - alpha) * colorBottom.getBlue() + alpha * colorTop.getBlue());
    return new Color(red, green, blue);
  }
Example #15
0
  public void animate() {
    // calculate gradient based on health percentage
    int gradient = 130 - (100 * p.health / p.maxHealth);

    if (animating == false) {
      animating = true;
      for (Tile[] tileRow : tiles)
        for (Tile t : tileRow) t.setBackground(new Color(gradient, 0, 0));
      return;
    }

    Color cur = tiles[0][0].getBackground();
    Color dest = new Color(0, 0, 0);

    // Calculate dif to about 20 iterations
    int dif = gradient / 20;

    if (cur.getRed() <= dest.getRed() || cur.getRed() < dif) {
      cur = dest;
      animating = false;
    }

    if (cur.getRGB() != dest.getRGB()) {
      cur = new Color(cur.getRed() - dif, cur.getGreen(), cur.getBlue());
      for (Tile[] tileRow : tiles)
        for (Tile t : tileRow) {
          t.setBackground(cur);
          Tile.setFade(
              new Color(cur.getRed(), cur.getGreen(), cur.getBlue(), Tile.getFade().getAlpha()));
        }
    }
  }
Example #16
0
 @NotNull
 private static Color getMiddleColor(Color fg, Color bg, double factor) {
   int red = avg(fg.getRed(), bg.getRed(), factor);
   int green = avg(fg.getGreen(), bg.getGreen(), factor);
   int blue = avg(fg.getBlue(), bg.getBlue(), factor);
   return new Color(red, green, blue);
 }
Example #17
0
  public void save() {
    Rectangle rect = this.getBounds();
    prefs.putInt(LOCATION_X, rect.x);
    prefs.putInt(LOCATION_Y, rect.y);
    prefs.putInt(WIDTH, rect.width);
    prefs.putInt(HEIGHT, rect.height);

    prefs.put(FONTSTYLE, this.myMenu.fontStyle);
    prefs.putInt(FONTSIZE, this.myMenu.fontSize);

    Color fColor = this.myMenu.fontColor;
    fRed = fColor.getRed();
    fGreen = fColor.getGreen();
    fBlue = fColor.getBlue();
    prefs.putInt(FRED, fRed);
    prefs.putInt(FGREEN, fGreen);
    prefs.putInt(FBLUE, fBlue);

    Color color = this.myMenu.getBackground();
    bgRed = color.getRed();
    bgGreen = color.getGreen();
    bgBlue = color.getBlue();
    prefs.putInt(BGRED, bgRed);
    prefs.putInt(BGGREEN, bgGreen);
    prefs.putInt(BGBLUE, bgBlue);
  }
Example #18
0
  /**
   * Allocates colors across a range.
   *
   * @param suggestedNumberOfColors palette resolution; if colorPalette.length does not evenly
   *     divide into this number, the actual number of colors in the palette will be rounded down.
   * @param colorMap the simplest color map is { minColor, maxColor }; you might, however, want to
   *     go through intermediate colors instead of following a straight-line route through the color
   *     space.
   * @return Color[] the color palette
   */
  protected Color[] createColorPalette(int suggestedNumberOfColors, Color[] colorMap) {

    Color[] colorPalette;
    Color minColor;
    Color maxColor;

    // number of segments is one less than the number of points
    // dividing the line into segments; the color map contains points,
    // not segments, so for example, if the color map is trivially
    // { minColor, maxColor }, then there is only one segment
    int totalSegments = m_currentColorMap.length - 1;

    // allocate colors across a range; distribute evenly
    // between intermediate points, if there are any
    int colorsPerSegment = suggestedNumberOfColors / totalSegments;

    // make sure all segments are equal by rounding down
    // the total number of colors if necessary
    int totalColors = totalSegments * colorsPerSegment;

    // create color map to return
    colorPalette = new Color[totalColors];

    for (int segment = 0; segment < totalSegments; segment++) {
      // the minimum color for each segment as defined by the current color
      // map
      minColor = colorMap[segment];
      int r = minColor.getRed();
      int g = minColor.getGreen();
      int b = minColor.getBlue();

      // the maximum color for each segment and the step sizes
      maxColor = colorMap[segment + 1];
      int redStepSize = getStepSize(r, maxColor.getRed(), colorsPerSegment);
      int greenStepSize = getStepSize(g, maxColor.getGreen(), colorsPerSegment);
      int blueStepSize = getStepSize(b, maxColor.getBlue(), colorsPerSegment);

      for (int k, i = 0; i < colorsPerSegment; i++) {
        // clip
        r = Math.min(r, 255);
        g = Math.min(g, 255);
        b = Math.min(b, 255);

        // but also make sure it's not less than zero
        r = Math.max(r, 0);
        g = Math.max(g, 0);
        b = Math.max(b, 0);

        k = segment * colorsPerSegment + i;
        colorPalette[k] = new Color(r, g, b);

        r += redStepSize;
        g += greenStepSize;
        b += blueStepSize;
      }
    }

    return colorPalette;
  } // end createColorPalette
Example #19
0
 public void fillRect(int x, int y, int width, int height) {
   HSSFSimpleShape shape =
       escherGroup.createShape(new HSSFChildAnchor(x, y, x + width, y + height));
   shape.setShapeType(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE);
   shape.setLineStyle(HSSFShape.LINESTYLE_NONE);
   shape.setFillColor(foreground.getRed(), foreground.getGreen(), foreground.getBlue());
   shape.setLineStyleColor(foreground.getRed(), foreground.getGreen(), foreground.getBlue());
 }
Example #20
0
 public double getIntensity() {
   return Math.sqrt(
           color.getRed() * color.getRed()
               + color.getBlue() * color.getBlue()
               + color.getGreen() * color.getGreen())
       / 443.405
       * 256;
 }
Example #21
0
 public Color evaluate(Color v0, Color v1, float fraction) {
   int r = v0.getRed() + (int) ((v1.getRed() - v0.getRed()) * fraction + 0.5f);
   int g = v0.getGreen() + (int) ((v1.getGreen() - v0.getGreen()) * fraction + 0.5f);
   int b = v0.getBlue() + (int) ((v1.getBlue() - v0.getBlue()) * fraction + 0.5f);
   int a = v0.getAlpha() + (int) ((v1.getAlpha() - v0.getAlpha()) * fraction + 0.5f);
   Color value = new Color(r, g, b, a);
   return value;
 }
Example #22
0
  private BufferedImage figureOutDrawImage(Sprite[] imgs) {

    Sprite img;
    if (dead) {
      return imgs[5].getBuffer();
    }

    if (Math.abs((int) (vel.y * 100)) > 0 && !piped) {
      img = imgs[1];
    } else if (!(movingRight || movingLeft) && vel.x == 0) img = imgs[0];
    else {
      if (movingRight && vel.x < 0 || movingLeft && vel.x > 0) img = imgs[4];
      else {
        if (rightFoot) img = imgs[3];
        else img = imgs[2];
      }
    }

    if (star && (starTime < 8000 / 15 || System.currentTimeMillis() % 60 > 30)) {
      int width = img.getBuffer().getWidth(), height = img.getBuffer().getHeight();
      Sprite limg = new Sprite(img.getBuffer());
      for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
          Color pixel = limg.getPixel(x, y);
          if (pixel.getAlpha() != 0) {
            limg.setPixel(
                x,
                y,
                new Color(
                    255 - pixel.getRed(),
                    255 - pixel.getGreen(),
                    255 - pixel.getBlue(),
                    pixel.getAlpha()));
          }
        }
      }
      img = limg;
    } else if (metal) {
      int width = img.getBuffer().getWidth(), height = img.getBuffer().getHeight();
      Sprite limg = new Sprite(img.getBuffer());
      for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
          Color pixel = limg.getPixel(x, y);
          if (pixel.getAlpha() != 0) {
            int gray = (pixel.getRed() + pixel.getBlue() + pixel.getGreen()) / 3;
            limg.setPixel(x, y, new Color(gray, gray, gray, pixel.getAlpha()));
          }
        }
      }
      img = limg;
    }

    if (facingRight) {
      return img.flipX();
    } else {
      return img.getBuffer();
    }
  }
Example #23
0
 public static final Color premultiplyAlpha(Color fgColor, Color bgColor) {
   int r, g, b;
   int fgAlpha = fgColor.getAlpha();
   r = fgColor.getRed() * fgAlpha + bgColor.getRed() * (255 - fgAlpha);
   g = fgColor.getGreen() * fgAlpha + bgColor.getGreen() * (255 - fgAlpha);
   b = fgColor.getBlue() * fgAlpha + bgColor.getBlue() * (255 - fgAlpha);
   Color result = new Color(r / 255, g / 255, b / 255);
   return result;
 }
Example #24
0
 public static Color blendcol(Color in, Color bl) {
   int f1 = bl.getAlpha();
   int f2 = 255 - bl.getAlpha();
   return (new Color(
       ((in.getRed() * f2) + (bl.getRed() * f1)) / 255,
       ((in.getGreen() * f2) + (bl.getGreen() * f1)) / 255,
       ((in.getBlue() * f2) + (bl.getBlue() * f1)) / 255,
       in.getAlpha()));
 }
Example #25
0
 /**
  * Blend the high and low value colors
  *
  * <p>The colors will be blended such that a value of 1.0 is high color, a value of 0.0 is low
  * color, and values in between have the appropriate blend.
  *
  * @param val The weight given to the high value color
  */
 public static Color forValue(double val) {
   int red =
       (int) (((1.0 - val) * (double) lowValue.getRed()) + (val * (double) highValue.getRed()));
   int green =
       (int)
           (((1.0 - val) * (double) lowValue.getGreen()) + (val * (double) highValue.getGreen()));
   int blue =
       (int) (((1.0 - val) * (double) lowValue.getBlue()) + (val * (double) highValue.getBlue()));
   return new Color(red, green, blue);
 }
Example #26
0
 /** colcom = color-compare */
 private static boolean colcom(Color color1, Color color2) {
   int unterschied = 50;
   if ((color1.getRed() + unterschied > color2.getRed()
           && color1.getRed() - unterschied < color2.getRed())
       && (color1.getBlue() + unterschied > color2.getBlue()
           && color1.getBlue() - unterschied < color2.getBlue())
       && (color1.getGreen() + unterschied > color2.getGreen()
           && color1.getGreen() - unterschied < color2.getGreen())) return true;
   else return false;
 }
Example #27
0
 private void setResultColor(
     Color colorA, Color colorB, Composite resultColorComposite, Label resultColor) {
   KMColor mix =
       new KMColor(new java.awt.Color(colorA.getRed(), colorA.getGreen(), colorA.getBlue()));
   mix.mix(new java.awt.Color(colorB.getRed(), colorB.getGreen(), colorB.getBlue()));
   java.awt.Color result = mix.getColor();
   resultColorComposite.setBackground(
       new Color(Display.getCurrent(), result.getRed(), result.getGreen(), result.getBlue()));
   resultColor.setText(
       "R: " + result.getRed() + ", G: " + result.getGreen() + ", B: " + result.getBlue());
 }
Example #28
0
 /**
  * Method to compute the color distances between two color objects
  *
  * @param color1 a color object
  * @param color2 a color object
  * @return the distance between the two colors
  */
 public static double colorDistance(Color color1, Color color2) {
   double redDistance = color1.getRed() - color2.getRed();
   double greenDistance = color1.getGreen() - color2.getGreen();
   double blueDistance = color1.getBlue() - color2.getBlue();
   double distance =
       Math.sqrt(
           redDistance * redDistance
               + greenDistance * greenDistance
               + blueDistance * blueDistance);
   return distance;
 }
Example #29
0
 public static Color contrast(Color col) {
   int max = Math.max(col.getRed(), Math.max(col.getGreen(), col.getBlue()));
   if (max > 128) {
     return (new Color(col.getRed() / 2, col.getGreen() / 2, col.getBlue() / 2, col.getAlpha()));
   } else if (max == 0) {
     return (Color.WHITE);
   } else {
     int f = 128 / max;
     return (new Color(col.getRed() * f, col.getGreen() * f, col.getBlue() * f, col.getAlpha()));
   }
 }
Example #30
0
 public double getHue() {
   double h =
       Math.atan(
           1.73205080757
               * (color.getGreen() - color.getBlue())
               / (2 * color.getRed() - color.getGreen() - color.getBlue()));
   h = h * 57.29578; // *360/2/3.1415926
   if (h < -180) h = -180;
   if (h > 179) h = 179;
   return h;
 }