Java Code Examples for java.awt.Color#getColorComponents()
The following examples show how to use
java.awt.Color#getColorComponents() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ColorUtils.java From ghidra with Apache License 2.0 | 6 votes |
/** * Takes the first color, blending into it the second color, using the given ratio. A * lower ratio (say .1f) signals to use very little of the first color; a larger ratio * signals to use more of the first color. * * @param c1 the first color * @param c2 the second color * @param ratio the amount of the first color to include in the final output * @return the new color */ public static Color blend(Color c1, Color c2, float ratio) { float rgb1[] = new float[3]; float rgb2[] = new float[3]; c1.getColorComponents(rgb1); c2.getColorComponents(rgb2); float inverse = (float) 1.0 - ratio; //@formatter:off Color color = new Color( rgb1[0] * ratio + rgb2[0] * inverse, rgb1[1] * ratio + rgb2[1] * inverse, rgb1[2] * ratio + rgb2[2] * inverse); //@formatter:on return color; }
Example 2
Source File: MotionDisplayer.java From opensim-gui with Apache License 2.0 | 6 votes |
/** * @param defaultForceColor the defaultForceColor to set */ public void setDefaultForceColor(Color defaultForceColor) { float[] colorFloat = new float[3]; defaultForceColor.getColorComponents(colorFloat); for (int i=0;i<3;i++) this.defaultForceColor[i] = (double) colorFloat[i]; Vec3 colorAsVec3 = new Vec3(); for (int i =0; i <3; i++) colorAsVec3.set(i, this.defaultForceColor[i]); this.defaultExperimentalMarkerColor = colorAsVec3; Set<OpenSimObject> expermintalDataObjects = mapComponentToUUID.keySet(); for (OpenSimObject expObj : expermintalDataObjects){ // Find first ExperimentalMarker and change its Material, this will affect all of them if (expObj instanceof MotionObjectPointForce){ UUID expObjectUUID = mapComponentToUUID.get(expObj).get(0); ViewDB.getInstance().applyColorToObjectByUUID(model, expObjectUUID, colorAsVec3); } } }
Example 3
Source File: ColorPick.java From Spark with Apache License 2.0 | 6 votes |
/** * Creates a Colorpicker with initialvalues provided by c * @param opacity, true if Opacity Slider should be visible * @param c, the initial Color */ public ColorPick(boolean opacity, Color c) { this(opacity); for(int i=0; i < 3; i++) { float w = c.getColorComponents(new float[3])[i]; int x = Math.round(w*255f/1f); _sliderarray[i].setValue(x); } _sliderarray[3].setValue(c.getAlpha()); this.revalidate(); }
Example 4
Source File: ColorUtil.java From Spark with Apache License 2.0 | 5 votes |
/** * Blend two colors. * * @param color1 First color to blend. * @param color2 Second color to blend. * @param ratio Blend ratio. 0.5 will give even blend, 1.0 will return * color1, 0.0 will return color2 and so on. * @return Blended color. */ public static Color blend(Color color1, Color color2, double ratio) { float r = (float)ratio; float ir = (float)1.0 - r; float rgb1[] = new float[3]; float rgb2[] = new float[3]; color1.getColorComponents(rgb1); color2.getColorComponents(rgb2); return new Color(rgb1[0] * r + rgb2[0] * ir, rgb1[1] * r + rgb2[1] * ir, rgb1[2] * r + rgb2[2] * ir); }
Example 5
Source File: ColorUtil.java From Spark with Apache License 2.0 | 5 votes |
/** * Return the "distance" between two colors. * * @param color1 First color. * @param color2 Second color. * @return Distance between colors. */ public static double colorDistance(Color color1, Color color2) { float rgb1[] = new float[3]; float rgb2[] = new float[3]; color1.getColorComponents(rgb1); color2.getColorComponents(rgb2); return ColorUtil.colorDistance(rgb1[0], rgb1[1], rgb1[2], rgb2[0], rgb2[1], rgb2[2]); }
Example 6
Source File: ColorPick.java From Spark with Apache License 2.0 | 5 votes |
/** * Sets the Color of this Colorpicker * @param c */ public void setColor(Color c) { for (int i = 0; i < 3; i++) { float w = c.getColorComponents(new float[3])[i]; int x = Math.round(w * 255f / 1f); _sliderarray[i].setValue(x); } _sliderarray[3].setValue(c.getAlpha()); this.revalidate(); }
Example 7
Source File: JavaFxColor.java From dingtalk-plugin with MIT License | 4 votes |
public static float[] getRgb(Color color) { return color.getColorComponents(null); }
Example 8
Source File: AbstractHighlightDrawer.java From ReactionDecoder with GNU Lesser General Public License v3.0 | 4 votes |
private Color makeTranslucentColor(Color color) { float[] c = color.getColorComponents(null); return new Color(c[0], c[1], c[2], params.highlightAlpha); }
Example 9
Source File: AppearanceHelper.java From opensim-gui with Apache License 2.0 | 4 votes |
void setAppearanceColorProperty(Color newColor) { float[] colorComp = new float[3]; newColor.getColorComponents(colorComp); final AbstractProperty ap = appearance.updPropertyByName("color"); final Model model = this.model; final Vec3 oldValue = new Vec3(appearance.get_color()); final PropertyEditorAdaptor pea = new PropertyEditorAdaptor(model, appearance, ap, compNode); pea.setAffectsState(false); ap.setValueIsDefault(false); final Vec3 newColorVec3 = new Vec3(colorComp[0], colorComp[1], colorComp[2]); pea.setValueVec3(newColorVec3, false); // Delay update display till end ViewDB.getInstance().updateComponentDisplay(model, compNode.comp, ap); //System.out.println("p, c"+ap.toString()+compNode.comp.dump()); AbstractUndoableEdit auEdit = new AbstractUndoableEdit() { @Override public void undo() throws CannotUndoException { super.undo(); pea.setValueVec3(oldValue, false); ViewDB.getInstance().updateComponentDisplay(model, compNode.comp, ap); } @Override public String getUndoPresentationName() { return "Undo color change"; } @Override public void redo() throws CannotRedoException { super.redo(); pea.setValueVec3(newColorVec3, false); ViewDB.getInstance().updateComponentDisplay(model, compNode.comp, ap); } @Override public String getRedoPresentationName() { return "Redo color change"; } }; ExplorerTopComponent.addUndoableEdit(auEdit); }
Example 10
Source File: LandmarkColorBlendInterpolation.java From burlap with Apache License 2.0 | 4 votes |
@Override public Color color(double v) { //end point? if(v <= landmarkValues.get(0)){ return landmarkColors.get(0); } if(v >= landmarkValues.get(landmarkValues.size()-1)){ return landmarkColors.get(landmarkColors.size()-1); } //which is the interpolation end point? int ePoint = 1; for(int i = 1; i < landmarkValues.size(); i++){ ePoint = i; if(landmarkValues.get(i) > v){ break ; } } double sv = landmarkValues.get(ePoint-1); double ev = landmarkValues.get(ePoint); double vRange = ev - sv; double t = (v - sv) / vRange; t = Math.pow(t, this.polyDegree); Color sC = landmarkColors.get(ePoint-1); Color eC = landmarkColors.get(ePoint); float [] sColorComp = sC.getColorComponents(null); float [] eColorComp = eC.getColorComponents(null); float red = this.interpolate(sColorComp[0], eColorComp[0], (float)t); float green = this.interpolate(sColorComp[1], eColorComp[1], (float)t); float blue = this.interpolate(sColorComp[2], eColorComp[2], (float)t); Color finalColor = new Color(red, green, blue); return finalColor; }