java.awt.Color#getColorComponents ( )源码实例Demo

下面列出了java.awt.Color#getColorComponents ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ghidra   文件: ColorUtils.java
/**
 * 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;
}
 
源代码2 项目: opensim-gui   文件: MotionDisplayer.java
/**
 * @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);  
        }
    }

    
}
 
源代码3 项目: Spark   文件: ColorPick.java
/**
    * 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();

   }
 
源代码4 项目: Spark   文件: ColorUtil.java
/**
 * 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);
}
 
源代码5 项目: Spark   文件: ColorUtil.java
/**
 * 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]);
}
 
源代码6 项目: Spark   文件: ColorPick.java
/**
    * 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();
   }
 
源代码7 项目: dingtalk-plugin   文件: JavaFxColor.java
public static float[] getRgb(Color color) {
  return color.getColorComponents(null);
}
 
源代码8 项目: ReactionDecoder   文件: AbstractHighlightDrawer.java
private Color makeTranslucentColor(Color color) {
    float[] c = color.getColorComponents(null);
    return new Color(c[0], c[1], c[2], params.highlightAlpha);
}
 
源代码9 项目: opensim-gui   文件: AppearanceHelper.java
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);
}
 
源代码10 项目: burlap   文件: LandmarkColorBlendInterpolation.java
@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;
}