List of usage examples for java.awt Color getGreen
public int getGreen()
From source file:savant.view.tracks.VariantTrackRenderer.java
/** * If we're homozygotic, accumulate a rectangle for this variant. If we're heterozygotic, accumulate a triangle for each parent. * @param vars array of one or two variant types * @param accumulator a colour accumulator * @param rect bounding box used for rendering both zygotes *///from w ww. j a va 2 s. co m public static void accumulateZygoteShapes(VariantType[] vars, ColourAccumulator accumulator, Rectangle2D rect) { ColourScheme scheme = accumulator.getScheme(); if (vars != null) { if (vars.length == 1) { accumulator.addShape(scheme.getVariantColor(vars[0]), rect); } else { Color color0 = scheme.getVariantColor(vars[0]); Color color1 = scheme.getVariantColor(vars[1]); Color blend; if (color0 == null) { blend = new Color(color1.getRed(), color1.getGreen(), color1.getBlue(), 128); } else if (color1 == null) { blend = new Color(color0.getRed(), color0.getGreen(), color0.getBlue(), 128); } else { blend = new Color((color0.getRed() + color1.getRed()) / 2, (color0.getGreen() + color1.getGreen()) / 2, (color0.getBlue() + color1.getBlue()) / 2); } accumulator.addShape(blend, rect); } } }
From source file:com.igormaznitsa.sciareto.ui.UiUtils.java
public static int calculateBrightness(@Nonnull final Color color) { return (int) Math.sqrt(color.getRed() * color.getRed() * .241d + color.getGreen() * color.getGreen() * .691d + color.getBlue() * color.getBlue() * .068d); }
From source file:ColorSchemaGenerator.java
/** * Create the schema color./* w ww. j a va2 s . com*/ * * @param base * @param i (a color between 0 and 3) * @param schemaName * @return */ public static Color createColor(Color base, int i, String schemaName) { i = Math.abs(i %= 3); if (schemaName == null) schemaName = SCHEMA_SOFT; float[] schema = schemas.get(schemaName); float[] components = Color.RGBtoHSB(base.getRed(), base.getGreen(), base.getBlue(), null); components[1] = (schema[i * 2] < 0) ? -schema[i * 2] * components[1] : schema[i * 2]; if (components[1] > 1) components[1] = 1.0f; if (components[1] < 0) components[1] = 0; components[2] = (schema[i * 2 + 1] < 0) ? -schema[i * 2 + 1] * components[2] : schema[i * 2 + 1]; if (components[2] > 1) components[2] = 1.0f; if (components[2] < 0) components[2] = 0; return new Color(Color.HSBtoRGB(components[0], components[1], components[2])); }
From source file:com.teambrmodding.neotech.client.models.ModelItemFluidStorage.java
/** * Change standard color into color MC wants for vertex data * @param input The input//from ww w. j a v a2 s.c om * @return The correct color to add to the vertex data */ public static int fixColorForMC(int input) { // ABGR, MC is reverse for some reason Color outputColor = new Color(input); int a = outputColor.getAlpha(); int r = outputColor.getRed(); int g = outputColor.getGreen(); int b = outputColor.getBlue(); return new Color(b, g, r, a).getRGB(); }
From source file:be.vds.jtbdive.client.view.core.dive.profile.DiveProfileChartFactory.java
public static JFreeChart createDiveProfileChartPanel(DiveProfile diveProfile, Locale locale, LengthUnit lengthUnit) {// ww w . j a v a2 s.co m XYSeries depthSerie = new XYSeries(SERIE_DEPTH); XYSeriesCollection depthCollection = new XYSeriesCollection(); depthCollection.addSeries(depthSerie); JFreeChart chart = ChartFactory.createXYAreaChart(null, getDomainLegend(locale), getRangeLegend(locale, lengthUnit), depthCollection, PlotOrientation.VERTICAL, false, true, false); XYPlot xyp = chart.getXYPlot(); Paint p = new GradientPaint(0f, 0f, UIAgent.getInstance().getColorWaterBottom(), 200f, 200f, UIAgent.getInstance().getColorWaterSurface(), false); xyp.setBackgroundPaint(p); xyp.setDomainGridlinePaint(UIAgent.getInstance().getColorWaterGrid()); xyp.setRangeGridlinePaint(UIAgent.getInstance().getColorWaterGrid()); ((NumberAxis) xyp.getDomainAxis()).setNumberFormatOverride(new MinutesNumberFormat()); XYAreaRenderer renderer0 = new XYAreaRenderer(); renderer0.setOutline(true); renderer0.setBaseOutlinePaint(UIAgent.getInstance().getColorWaterBottom()); Color baseColor = UIAgent.getInstance().getColorBaseBackground(); renderer0.setSeriesPaint(0, new Color(baseColor.getRed(), baseColor.getGreen(), baseColor.getBlue(), 50)); xyp.setRenderer(0, renderer0); int i = 1; XYSeriesCollection decoEntriesCollection = new XYSeriesCollection(); XYSeries decoEntriesSerie = new XYSeries(SERIE_DECO_ENTRY); decoEntriesCollection.addSeries(decoEntriesSerie); XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(); renderer2.setSeriesLinesVisible(0, false); renderer2.setAutoPopulateSeriesShape(false); renderer2.setSeriesPaint(0, UIAgent.getInstance().getColorDecoEntries()); renderer2.setBaseShape(DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE[SHAPE_DECO_ENTRY]); xyp.setDataset(i, decoEntriesCollection); xyp.setRenderer(i, renderer2); i++; XYSeriesCollection ascentTooFastCollection = new XYSeriesCollection(); XYSeries ascentTooFastSerie = new XYSeries(SERIE_WARNING_ASCENT_TOO_FAST); ascentTooFastCollection.addSeries(ascentTooFastSerie); renderer2 = new XYLineAndShapeRenderer(); renderer2.setSeriesLinesVisible(0, false); renderer2.setAutoPopulateSeriesShape(false); renderer2.setSeriesPaint(0, UIAgent.getInstance().getColorWarningAscentTooFast()); renderer2.setBaseShape(DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE[SHAPE_ASCENT_TOO_FAST_WARNING]); xyp.setDataset(i, ascentTooFastCollection); xyp.setRenderer(i, renderer2); i++; XYSeriesCollection decoWarningCollection = new XYSeriesCollection(); XYSeries decoWarningSerie = new XYSeries(SERIE_DECO_STOP); decoWarningCollection.addSeries(decoWarningSerie); renderer2 = new XYLineAndShapeRenderer(); renderer2.setSeriesLinesVisible(0, false); renderer2.setAutoPopulateSeriesShape(false); renderer2.setSeriesPaint(0, UIAgent.getInstance().getColorWarningDecoCeiling()); renderer2.setBaseShape(DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE[SHAPE_DECO_WARNING]); xyp.setDataset(i, decoWarningCollection); xyp.setRenderer(i, renderer2); i++; XYSeriesCollection remainBottomTimeCollection = new XYSeriesCollection(); XYSeries remainBottomTimeSerie = new XYSeries(SERIE_REMAINING_BOTTOM_TIME); remainBottomTimeCollection.addSeries(remainBottomTimeSerie); renderer2 = new XYLineAndShapeRenderer(); renderer2.setSeriesLinesVisible(0, false); renderer2.setAutoPopulateSeriesShape(false); renderer2.setSeriesPaint(0, UIAgent.getInstance().getColorWarningRemainingBottomTime()); renderer2.setBaseShape(DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE[SHAPE_REMAINING_BOTTOM_TIME_WARNING]); xyp.setDataset(i, remainBottomTimeCollection); xyp.setRenderer(i, renderer2); Map<Double, Double> depthEntries = diveProfile.getDepthEntries(); Set<Double> ascentWarning = diveProfile.getAscentWarnings(); Set<Double> decoWarnings = diveProfile.getDecoCeilingWarnings(); Set<Double> remainBottomTime = diveProfile.getRemainingBottomTimeWarnings(); Set<Double> decoEntryTime = diveProfile.getDecoEntries(); if (depthEntries.size() > 0 && depthEntries.get(0d) == null) { depthEntries.put(0d, 0d); } for (Double seconds : depthEntries.keySet()) { double d = UnitsAgent.getInstance().convertLengthFromModel(depthEntries.get(seconds), lengthUnit); depthSerie.add(seconds, Double.valueOf(d)); } if (null != ascentWarning) { for (Double seconds : ascentWarning) { ascentTooFastSerie.add(seconds, depthEntries.get(seconds)); } } if (null != decoWarnings) { for (Double seconds : decoWarnings) { decoWarningSerie.add(seconds, depthEntries.get(seconds)); } } if (null != remainBottomTime) { for (Double seconds : remainBottomTime) { remainBottomTimeSerie.add(seconds, depthEntries.get(seconds)); } } if (null != decoEntryTime) { for (Double seconds : decoEntryTime) { decoEntriesSerie.add(seconds, depthEntries.get(seconds)); } } return chart; }
From source file:com.glaf.core.util.Tools.java
public static String javaColorToCSSColor(Color paramColor) { StringBuffer localStringBuffer = new StringBuffer(30); localStringBuffer.append("rgb("); localStringBuffer.append(paramColor.getRed()); localStringBuffer.append(','); localStringBuffer.append(paramColor.getGreen()); localStringBuffer.append(','); localStringBuffer.append(paramColor.getBlue()); localStringBuffer.append(')'); return localStringBuffer.toString(); }
From source file:ImageProcessing.ImageProcessing.java
public static void processGrayscale(BufferedImage image) { //Converts a color image to a Grayscale image. for (int i = 0; i < image.getHeight(); i++) { for (int j = 0; j < image.getWidth(); j++) { int rgb = image.getRGB(j, i); Color currentPixel = new Color(rgb, true); //Find the average from all the color components for the given pixel. int grayLevel = (currentPixel.getRed() + currentPixel.getGreen() + currentPixel.getBlue()) / 3; int gray = (grayLevel << 16) + (grayLevel << 8) + grayLevel; image.setRGB(j, i, gray);/*from w ww. j av a2s.c o m*/ } } }
From source file:se.ngm.ditaaeps.EpsRenderer.java
public static boolean isColorDark(Color color) { int brightness = Math.max(color.getRed(), color.getGreen()); brightness = Math.max(color.getBlue(), brightness); if (brightness < 200) { if (DEBUG) System.out.println("Color " + color + " is dark"); return true; }/*w ww . j a va 2 s. co m*/ if (DEBUG) System.out.println("Color " + color + " is not dark"); return false; }
From source file:net.cloudkit.relaxation.CaptchaTest.java
public static void clearNoise(BufferedImage image) { final int width = image.getWidth(); final int height = image.getHeight(); /*//ww w .ja va 2s . c o m for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { image.setRGB(x, y, Color.WHITE.getRGB()); } } */ for (int x = image.getMinX(); x < width; x++) { for (int y = image.getMinY(); y < height; y++) { int point = image.getRGB(x, y); // int top = (y > 0) ? image.getRGB(x, y - 1) : -1; // ? int right = (x < width - 1) ? image.getRGB(x + 1, y) : -1; // int bottom = (y < height - 1) ? image.getRGB(x, y + 1) : -1; // int left = (x > 0) ? image.getRGB(x - 1, y) : -1; // ? int topRight = ((x < width - 1) && (y > 0)) ? image.getRGB(x + 1, y - 1) : -1; // int topLeft = ((x > 0) && (y > 0)) ? image.getRGB(x - 1, y - 1) : -1; // ? int bottomRight = ((x < width - 1) && (y < height - 1)) ? image.getRGB(x + 1, y + 1) : -1; // int bottomLeft = ((x > 0) && (y < height - 1)) ? image.getRGB(x - 1, y + 1) : -1; int i = 0; i = (top != -1) ? i + 1 : i; i = (right != -1) ? i + 1 : i; i = (bottom != -1) ? i + 1 : i; i = (left != -1) ? i + 1 : i; i = (topRight != -1) ? i + 1 : i; i = (topLeft != -1) ? i + 1 : i; i = (bottomRight != -1) ? i + 1 : i; i = (bottomLeft != -1) ? i + 1 : i; // System.out.println("i:" + i + ", top:" + top + ", right:" + right + ", bottom:" + bottom + ", left:" + left + ", topRight:" + topRight + ", topLeft:" + topLeft + ", bottomRight:" + bottomRight + ", bottomLeft:" + bottomLeft); if (i < 5) { image.setRGB(x, y, Color.WHITE.getRGB()); } /* int leftNearby = 0; if(left != -1) { int secondLeft = (x > 1) ? image.getRGB(x - 2, y) : -1; int threeLeft = (x > 2) ? image.getRGB(x - 3, y) : -1; leftNearby = ((left == -1) ? 0 : 1) + ((secondLeft == -1) ? 0 : 1) + ((threeLeft == -1) ? 0 : 1); } int rightNearby = 0; if(right != -1) { int secondRight = (x + 1 < width - 1) ? image.getRGB(x + 2, y) : -1; int threeRight = (x + 2 < width - 1) ? image.getRGB(x + 3, y) : -1; rightNearby = ((right == -1) ? 0 : 1) + ((secondRight == -1) ? 0 : 1) + ((threeRight == -1) ? 0 : 1); } int topNearby = 0; if(top != -1) { int secondTop = (y > 1) ? image.getRGB(x, y - 2) : -1; int threeTop = (y > 2) ? image.getRGB(x, y - 3) : -1; topNearby = ((top == -1) ? 0 : 1) + ((secondTop == -1) ? 0 : 1) + ((threeTop == -1) ? 0 : 1); } int bottomNearby = 0; if(bottom != -1) { int secondBottom = (y + 1 < height - 1) ? image.getRGB(x, y + 2) : -1; int threeBottom = (y + 2 < height - 1) ? image.getRGB(x, y + 3) : -1; bottomNearby = ((bottom == -1) ? 0 : 1) + ((secondBottom == -1) ? 0 : 1) + ((threeBottom == -1) ? 0 : 0); } System.out.println(leftNearby + " " + rightNearby + " " + topNearby + " " + bottomNearby); if (leftNearby != 2 && rightNearby != 2 && topNearby != 2 && bottomNearby != 2) { image.setRGB(x, y, Color.WHITE.getRGB()); } */ /* System.out.println(point - top); System.out.println(point - right); System.out.println(point - bottom); System.out.println(point - left); System.out.println(point - topRight); System.out.println(point - topLeft); System.out.println(point - bottomRight); System.out.println(point - bottomLeft); */ // if (point != top && point != right && point != bottom && point != left && point != topRight && point != topLeft && point != bottomRight && point != bottomLeft) { // image.setRGB(x, y, Color.WHITE.getRGB()); // } /* Color color = new Color(image.getRGB(x, y)); if((color.getBlue() < 120) || ((color.getRed() + color.getGreen() + color.getBlue()) < 50)) { // image.setRGB(x, y, Color.WHITE.getRGB()); } else if((color.getRed() + color.getGreen() + color.getBlue()) < 400) { image.setRGB(x, y, Color.BLACK.getRGB()); } */ Color color = new Color(image.getRGB(x, y)); if ((color.getRed() + color.getGreen() + color.getBlue()) < 600) { image.setRGB(x, y, Color.BLACK.getRGB()); } else { image.setRGB(x, y, Color.WHITE.getRGB()); } } } }
From source file:org.opensha.commons.util.XMLUtils.java
/** * Convenience method for writing a java 'Color' object to XML with the given * element name/* w ww. j a v a2 s . com*/ * * @param parent * @param color * @param elName */ public static void colorToXML(Element parent, Color color, String elName) { Element el = parent.addElement(elName); el.addAttribute("r", color.getRed() + ""); el.addAttribute("g", color.getGreen() + ""); el.addAttribute("b", color.getBlue() + ""); el.addAttribute("a", color.getAlpha() + ""); }