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);
 }
  public int getAlpha(double level) {
    if (colors != null) {
      if (level >= 0 && level < colors.length) return colors[(int) level].getAlpha();
    }

    // else...

    final double minLevel = this.minLevel;
    final double maxLevel = this.maxLevel;
    // these next two also handle the possibility that maxLevel = minLevel
    if (level >= maxLevel) return maxColor.getAlpha();
    else if (level <= minLevel) return minColor.getAlpha();
    else {
      // now convert to between 0 and 1
      double interval = maxLevel - minLevel;
      // finally call the convert() function, then set back to between
      // minLevel and maxLevel
      level = filterLevel((level - minLevel) / interval) * interval + minLevel;
    }

    final double interpolation = (level - minLevel) / (maxLevel - minLevel);

    // TODO all messed up
    final int maxAlpha = alphas[alphas.length - 1]; // this.maxAlpha;
    final int minAlpha = alphas[0]; // this.minAlpha;
    return (maxAlpha == minAlpha
        ? minAlpha
        : (int) (interpolation * (maxAlpha - minAlpha) + minAlpha));
  }
 private static String toRGBFunctionCall(Color color) {
   StringBuffer sbuf = new StringBuffer();
   sbuf.append('#');
   String s = Integer.toHexString(color.getRed());
   if (s.length() == 1) {
     sbuf.append('0');
   }
   sbuf.append(s);
   s = Integer.toHexString(color.getGreen());
   if (s.length() == 1) {
     sbuf.append('0');
   }
   sbuf.append(s);
   s = Integer.toHexString(color.getBlue());
   if (s.length() == 1) {
     sbuf.append('0');
   }
   sbuf.append(s);
   if (color.getAlpha() != 255) {
     s = Integer.toHexString(color.getAlpha());
     if (s.length() == 1) {
       sbuf.append('0');
     }
     sbuf.append(s);
   }
   return sbuf.toString();
 }
Exemple #4
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)));
 }
Exemple #5
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;
 }
Exemple #6
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();
    }
  }
Exemple #7
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()));
 }
Exemple #8
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()));
   }
 }
Exemple #9
0
  /**
   * Paints 3 different strokes around a shape to indicate focus. The widest stroke is the most
   * transparent, so this achieves a nice "glow" effect.
   *
   * <p>The catch is that you have to render this underneath the shape, and the shape should be
   * filled completely.
   *
   * @param g the graphics to paint to
   * @param shape the shape to outline
   * @param pixelSize the number of pixels the outline should cover.
   * @param focusColor the color of the focus ring to paint
   * @param changeRenderingHints if true then the rendering hints will be modified, if false they
   *     will be left in tact
   */
  public static void paintFocus(
      Graphics2D g, Shape shape, int pixelSize, Color focusColor, boolean changeRenderingHints) {
    g = (Graphics2D) g.create();
    try {
      Color[] focusArray =
          new Color[] {
            new Color(
                focusColor.getRed(),
                focusColor.getGreen(),
                focusColor.getBlue(),
                235 * focusColor.getAlpha() / 255),
            new Color(
                focusColor.getRed(),
                focusColor.getGreen(),
                focusColor.getBlue(),
                130 * focusColor.getAlpha() / 255),
            new Color(
                focusColor.getRed(),
                focusColor.getGreen(),
                focusColor.getBlue(),
                80 * focusColor.getAlpha() / 255)
          };
      if (changeRenderingHints) {
        if (JVM.usingQuartz) {
          g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
          g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
        } else {
          g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
          g.setRenderingHint(
              RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
        }
      }

      g.setStroke(
          new BasicStroke(2 * pixelSize + 1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
      g.setColor(focusArray[2]);
      g.draw(shape);
      if (2 * pixelSize + 1 > 0) {
        g.setStroke(
            new BasicStroke(2 * pixelSize - 2 + 1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
        g.setColor(focusArray[1]);
        g.draw(shape);
      }
      if (2 * pixelSize - 4 + 1 > 0) {
        g.setStroke(
            new BasicStroke(2 * pixelSize - 4 + 1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
        g.setColor(focusArray[0]);
        g.draw(shape);
      }
    } finally {
      g.dispose();
    }
  }
  private static void configureXYDifferenceRenderer(
      FormattedXYDifferenceRenderer renderer,
      ValueSource valueSource,
      PlotConfiguration plotConfiguration) {
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    SeriesFormat seriesFormat = valueSource.getSeriesFormat();
    DimensionConfig domainConfig = valueSource.getDomainConfig();
    DimensionConfig colorDimensionConfig =
        plotConfiguration.getDimensionConfig(PlotDimension.COLOR);
    DimensionConfig shapeDimensionConfig =
        plotConfiguration.getDimensionConfig(PlotDimension.SHAPE);

    int seriesCount = 1; // valueSource.getSeriesDataForAllGroupCells().groupCellCount();

    // Loop all series and set series format.
    // Format based on dimension configs will be set later on in initFormatDelegate().
    for (int seriesIdx = 0; seriesIdx < seriesCount; ++seriesIdx) {
      // configure linestyle
      if (seriesFormat.getLineStyle() == LineStyle.NONE) {
      } else {
        renderer.setSeriesStroke(seriesIdx, seriesFormat.getStroke(), false);
      }

      // configure series shape if necessary
      if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, shapeDimensionConfig)) {
        if (seriesFormat.getItemShape() != ItemShape.NONE) {
          renderer.setSeriesShape(seriesIdx, seriesFormat.getItemShape().getShape());
        } else {
        }
      }

      // configure series color if necessary
      if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, colorDimensionConfig)) {
        Color itemColor = seriesFormat.getItemColor();
        Color halfTransparentPaint =
            DataStructureUtils.setColorAlpha(itemColor, itemColor.getAlpha() / 2);

        renderer.setSeriesPaint(0, halfTransparentPaint);
        renderer.setSeriesFillPaint(0, halfTransparentPaint);
        renderer.setPositivePaint(halfTransparentPaint);
        renderer.setNegativePaint(
            new Color(
                255 - itemColor.getRed(),
                255 - itemColor.getGreen(),
                255 - itemColor.getBlue(),
                itemColor.getAlpha() / 2));
      }
      renderer.setSeriesOutlinePaint(seriesIdx, PlotConfiguration.DEFAULT_SERIES_OUTLINE_PAINT);
    }
  }
Exemple #11
0
  public static String averageColor(Color c1, Color c2) {

    double avgR = c1.getRed() + c2.getRed();
    double avgB = c1.getBlue() + c2.getBlue();
    double avgG = c1.getGreen() + c2.getGreen();
    double avgA = c1.getAlpha() + c2.getAlpha();
    return ((int) (avgR / 2)
        + ","
        + (int) (avgG / 2)
        + ","
        + (int) (avgB / 2)
        + ","
        + (int) (avgA / 2));
  }
Exemple #12
0
  // Grab from screen, edit to work with alpha out of 1
  private Color blend(Color colorA, Color colorB, float alpha) {
    Color c0 = colorA;
    Color c1 = colorB;

    // double totalAlpha = c0.getAlpha() + c1.getAlpha();
    double weight0 = alpha; // c0.getAlpha() / totalAlpha;
    double weight1 = 1 - alpha; // c1.getAlpha() / totalAlpha;

    double r = weight0 * c0.getRed() + weight1 * c1.getRed();
    double g = weight0 * c0.getGreen() + weight1 * c1.getGreen();
    double b = weight0 * c0.getBlue() + weight1 * c1.getBlue();
    double a = Math.max(c0.getAlpha(), c1.getAlpha());

    return new Color((int) r, (int) g, (int) b, (int) a);
  }
Exemple #13
0
 public Colors(Color col) {
   this(
       new Color(
           (int) (col.getRed() * defamb[0]),
           (int) (col.getGreen() * defamb[1]),
           (int) (col.getBlue() * defamb[2]),
           col.getAlpha()),
       new Color(
           (int) (col.getRed() * defdif[0]),
           (int) (col.getGreen() * defdif[1]),
           (int) (col.getBlue() * defdif[2]),
           col.getAlpha()),
       new Color(0, 0, 0, 0),
       new Color(0, 0, 0, 0),
       0);
 }
Exemple #14
0
  public void paintComponent(Graphics g) {
    final Color bg = getBackground();
    final Insets insets = getInsets();

    if (shouldPaintBg) {
      super.paintComponent(g);

      if ((bg != null) && (bg.getAlpha() > 0)) {
        g.setColor(bg);
        g.fillRect(
            insets.left,
            insets.top,
            getWidth() - (insets.left + insets.right),
            getHeight() - (insets.top + insets.bottom));
      }
      if (!clear) {
        shouldPaintBg = false;
        setOpaque(true);
      }
    }
    if (pen != null) {
      if (pen.getAbsCoords()) {
        pen.paintIcon(this, g, 0, 0);
      } else {
        pen.paintIcon(this, g, insets.left, insets.top);
      }
    }
  }
 /** Set ARGB control point values to specified index */
 public void setARGBControlPoint(int index, Color value) {
   alpha.setControlPoint(index, (short) value.getAlpha());
   red.setControlPoint(index, (short) value.getRed());
   green.setControlPoint(index, (short) value.getGreen());
   blue.setControlPoint(index, (short) value.getBlue());
   gray.setControlPoint(index, (short) ColorUtil.getGrayMix(value));
 }
  /**
   * Paints a single bar instance.
   *
   * @param g2 the graphics target.
   * @param renderer the renderer.
   * @param row the row index.
   * @param column the column index.
   * @param bar the bar
   * @param base indicates which side of the rectangle is the base of the bar.
   * @param pegShadow peg the shadow to the base of the bar?
   */
  public void paintBarShadow(
      Graphics2D g2,
      XYBarRenderer renderer,
      int row,
      int column,
      RectangularShape bar,
      RectangleEdge base,
      boolean pegShadow) {

    // handle a special case - if the bar colour has alpha == 0, it is
    // invisible so we shouldn't draw any shadow
    Paint itemPaint = renderer.getItemPaint(row, column);
    if (itemPaint instanceof Color) {
      Color c = (Color) itemPaint;
      if (c.getAlpha() == 0) {
        return;
      }
    }

    RectangularShape shadow =
        createShadow(
            bar, renderer.getShadowXOffset(), renderer.getShadowYOffset(), base, pegShadow);
    g2.setPaint(Color.gray);
    g2.fill(shadow);
  }
  public String getComplementColour(String hexColour) throws JspException {

    String output = null;
    Integer i = null;

    if (hexColour == null || hexColour.equals("")) {
      i = 0;
    } else {
      i = Integer.parseInt(hexColour, 16);
    }

    int red = (i >> 16);
    int green = (i >> 8) & 0xFF;
    int blue = i & 0xFF;

    float[] hsl;
    float alpha;

    Color rgb = new Color(red, green, blue);
    hsl = fromRGB(rgb);
    alpha = rgb.getAlpha() / 255.0f;

    float hue = (hsl[0] + 180.0f) % 360.0f;
    Color complement = toRGB(hue, hsl[1], hsl[2], 1.0f);

    output = rgb2hex(complement.getRed(), complement.getGreen(), complement.getBlue());

    return output;
  }
Exemple #18
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 #19
0
 public static ColorRGBA toColorRGBA(Color color) {
   float r = color.getRed() / 255f;
   float g = color.getGreen() / 255f;
   float b = color.getBlue() / 255f;
   float a = color.getAlpha() / 255f;
   return new ColorRGBA(r, g, b, a);
 }
  private static Paint createTransparentCheckeredPaint(Color color, int checkerSize) {
    int s = checkerSize;
    BufferedImage bufferedImage = new BufferedImage(2 * s, 2 * s, BufferedImage.TYPE_INT_ARGB);

    Graphics2D g2 = bufferedImage.createGraphics();
    g2.setRenderingHint(
        RenderingHints.KEY_ANTIALIASING, // Anti-alias!
        RenderingHints.VALUE_ANTIALIAS_ON);

    Color c1 = DataStructureUtils.setColorAlpha(color, (int) (color.getAlpha() * .8));
    Color c2 = DataStructureUtils.setColorAlpha(color, (int) (color.getAlpha() * .2));
    g2.setStroke(new BasicStroke(0));
    g2.setPaint(c2);
    g2.setColor(c2);
    g2.fillRect(0, 0, s, s);
    g2.fillRect(s, s, s, s);
    g2.setPaint(c1);
    g2.setColor(c1);
    g2.fillRect(0, s, s, s);
    g2.fillRect(s, 0, s, s);

    // paint with the texturing brush
    Rectangle2D rect = new Rectangle2D.Double(0, 0, 2 * s, 2 * s);
    return new TexturePaint(bufferedImage, rect);
  }
Exemple #21
0
 /**
  * Remove the specified zone from the zone picker
  *
  * @param zone the zone to remove
  * @return The zone that was removed
  */
 public Zone remove(Zone zone) {
   Color color = zone.getPickColor();
   int pixelColor = color.getAlpha() + (color.getRGB() << 8);
   Zone removed = zoneMap.remove(pixelColor);
   zone.setPickColor(null);
   return removed;
 }
  protected void applyColor(DrawContext dc, java.awt.Color color, double opacity) {
    if (dc.isPickingMode()) return;

    double finalOpacity = opacity * (color.getAlpha() / 255.0);
    GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.
    OGLUtil.applyColor(gl, color, finalOpacity, true);
  }
Exemple #23
0
 public boolean hasChanges() {
   if (layerColour.getRed() != model.getRed()
       || layerColour.getGreen() != model.getGreen()
       || layerColour.getBlue() != model.getBlue()
       || ((float) layerColour.getAlpha() / 255f) != model.getOpacity()) return true;
   else return false;
 }
 public int getAlpha() {
   if (withTransp) {
     return sldTransparency.getValue();
   } else {
     return color.getAlpha();
   }
 }
 protected ColorRGBA makeColorRGBA(Color color) {
   return new ColorRGBA(
       color.getRed() / 255f,
       color.getGreen() / 255f,
       color.getBlue() / 255f,
       color.getAlpha() / 255f);
 }
Exemple #26
0
  /** Encode the 'binary' string into the pixels' r, g and b channels in that order. */
  protected void encodeBits() {

    writeMessageLength();

    char[] chars = message.toCharArray();
    int charsWritten = 0;
    for (int w = 1; w < width; w++) {
      for (int h = 0; h < height; h++) {
        if (charsWritten < messageLength) {
          char r = chars[charsWritten++];
          char g = (charsWritten < messageLength) ? chars[charsWritten++] : '0';
          char b = (charsWritten < messageLength) ? chars[charsWritten++] : '0';

          Color c = new Color(image.getRGB(w, h));
          int red = c.getRed();
          int green = c.getGreen();
          int blue = c.getBlue();
          int alpha = c.getAlpha();

          red = setSteganoBit(red, r);
          green = setSteganoBit(green, g);
          blue = setSteganoBit(blue, b);

          Color n = new Color(red, green, blue, alpha);
          image.setRGB(w, h, n.getRGB());
        }
      }
    }
  }
Exemple #27
0
 @Override
 public String toString() {
   if (value != null)
     return "rgb("
         + value.getRed()
         + ","
         + value.getGreen()
         + ","
         + value.getBlue()
         + ") "
         + (value.getAlpha() == 255 ? "" : ((value.getAlpha() * 100) / 255) + "")
         + "%";
   else if (keyword != null)
     return keyword + (opacity != 255 ? " " + ((100 * opacity + 128) / 255) + "%" : "");
   else return "transparent";
 }
Exemple #28
0
 /**
  * Converts a colour dimension to a value that is whitewashed by {@link #BACKGROUND_WHITEWASH}
  * degrees.
  */
 public static Color whitewash(Color color) {
   int red = whitewash(color.getRed());
   int green = whitewash(color.getGreen());
   int blue = whitewash(color.getBlue());
   int alpha = whitewash(color.getAlpha());
   return new Color(red, green, blue, alpha);
 }
Exemple #29
0
 private void glcolor() {
   gl.glColor4f(
       (float) color.getRed() / 255.0f,
       (float) color.getGreen() / 255.0f,
       (float) color.getBlue() / 255.0f,
       (float) color.getAlpha() / 255.0f);
 }
 private static Color shadeColor(Color color, double shade) {
   return new Color(
       (int) (color.getRed() * (1.0 - shade)),
       (int) (color.getGreen() * (1.0 - shade)),
       (int) (color.getBlue() * (1.0 - shade)),
       color.getAlpha());
 }