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

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

源代码1 项目: lgmodeler   文件: ShapeView.java
public void updateIcon(){
	Graphics g = icon.getGraphics();
	if(shape.getColor() == 0){
		g.drawImage(Resources.CLEAR_SHAPE_ICONS[shape.getType().ordinal()+1],0,0,null);
	} else {
		Image src = Resources.SHAPE_ICONS[shape.getType().ordinal()+1];
		g.drawImage(src, 0, 0, null);
		int[] data = ((DataBufferInt)icon.getRaster().getDataBuffer()).getData();
		float[] hsb = new float[3];
		int col = shapeList.getColor(shape.getColor());
		Color.RGBtoHSB((col>>16)&0xFF,(col>>8)&0xFF,col&0xFF,hsb);
		float hue = hsb[0];
		float sat = hsb[1];
		float bright = hsb[2];
		for(int i = 0; i < data.length; i++){
			int rgb = data[i];
			int a = rgb&0xFF000000;
			Color.RGBtoHSB((rgb>>16)&0xFF, (rgb>>8)&0xFF, rgb&0xFF, hsb);
			hsb[0] = hue;
			hsb[1] = sat;
			hsb[2] *= 0.5f + 0.5f*bright;
			data[i] = a | (Color.HSBtoRGB(hsb[0], hsb[1], hsb[2])&0xFFFFFF);
		}
	}
}
 
源代码2 项目: megamek   文件: MovementModifierEnvelopeSprite.java
/**
 * @param boardView1
 * @param mp
 */
public MovementModifierEnvelopeSprite(BoardView1 boardView1, MovePath mp) {
    super(boardView1, mp.getFinalCoords());

    facing = Facing.valueOfInt(mp.getFinalFacing());
    
    int modi = Compute.getTargetMovementModifier(mp.getHexesMoved(),
            mp.isJumping(),
            mp.getEntity() instanceof VTOL,
            boardView1.game).getValue();
    //Add evasion bonus for 'Mech with dual cockpit
    if (mp.getEntity().getCrew().getCrewType().equals(CrewType.DUAL)
            && mp.getEntity().getCrew().hasDedicatedPilot()
            && !mp.isJumping() && mp.getHexesMoved() > 0) {
        modi++;
    }
    float hue = 0.7f - 0.15f * modi;
    color = new Color(Color.HSBtoRGB(hue, 1, 1));
    modifier = String.format("%+d", modi);
}
 
源代码3 项目: SproutLife   文件: AngleColorModel.java
private Color getColor(Organism o, float h, float s, float br) {
    Organism[] ancestors = new Organism[4];
    Organism a = o;
    for (int ai=0;ai<ancestors.length;ai++) {
        ancestors[ai]=a;
        a = a.getParent();
        if (a==null) {
            return getRandomColor(o);
        }
    }
    double dp1 = getDotProduct(ancestors[0], ancestors[1], ancestors[2]);
    double dp2 = getDotProduct(ancestors[1], ancestors[2], ancestors[3]);

    float r1 = getRotation(dp1);
    float r2 = getRotation(dp2);

    Color c1 = new Color(Color.HSBtoRGB(h+r1, s, br));
    Color c2 = new Color(Color.HSBtoRGB(h+r2, s, br));

    int r = (c1.getRed()*3+c2.getRed()*2)/5;
    int g = (c1.getGreen()*3+c2.getGreen()*2)/5;
    int b = (c1.getBlue()*3+c2.getBlue()*2)/5;

    return new Color(r,g,b);
}
 
源代码4 项目: diirt   文件: LabelColorSchemes.java
/**
 *Returns a new LabelColorScheme, based on the given hex labels.
 * @param labels a list of strings (color values in hexadecimal)
 * @return a LabelColorScheme with the method getColor, that will return a Color corresponding to the hex label.
 */
public static LabelColorScheme orderedHueColor(List<String> labels) {
    final List<String> orderedUniqueLabels = new ArrayList<String>(new TreeSet<String>(labels));
    return new LabelColorScheme() {

        float step = (1.0f / 3) / ((float) Math.ceil(orderedUniqueLabels.size() / 3.0));

        @Override
        public int getColor(String label) {
            int index = orderedUniqueLabels.indexOf(label);
            if (index == -1) {
                return 0;
            }
            return Color.HSBtoRGB(index * step, 1.0f, 1.0f);
        }
    };
}
 
源代码5 项目: mzmine2   文件: XYBlockPixelSizePaintScales.java
public static Paint[] getFullRainBowScaleUpperBound() {
  int ncolor = 360;
  Color[] readRainbow = new Color[ncolor];
  Color[] rainbow = new Color[ncolor];

  float x = (float) (1. / (ncolor + 160));
  for (int i = 0; i < readRainbow.length; i++) {
    readRainbow[i] = new Color(Color.HSBtoRGB((i) * x, 1.0F, 1.0F));
  }
  for (int i = 0; i < readRainbow.length - 5; i++) {
    rainbow[i] = readRainbow[readRainbow.length - i - 1];
  }
  for (int i = rainbow.length - 5; i < rainbow.length; i++) {
    rainbow[i] = new Color(244, 66, 223);
  }
  return rainbow;
}
 
源代码6 项目: pumpernickel   文件: TextBlock.java
public TextBlock(float hue, String text) {
	properties.addListener(new PropertyChangeListener() {
		@Override
		public void propertyChange(PropertyChangeEvent evt) {
			dirty = true;
		}
	});
	setAntiAliased(true);
	setTextPaint(Color.black);
	setUsingFractionalMetrics(true);
	setFont(new Font("default", Font.BOLD, 14));
	setText(text);
	setInsets(new Insets(2, 2, 2, 2));
	setShadowActive(true);
	setTextShadowActive(true);
	Color c1 = new Color(Color.HSBtoRGB(hue, .8f, 1));
	Color c2 = new Color(Color.HSBtoRGB(hue, .8f, .7f));
	setBackground(new GradientPaint(0, 0, c1, 0, 20, c2));
	setBorderPaint(new Color(0, 0, 0, 90));
	setStroke(new BasicStroke(1));
	setCurveWidth(18);
	setTextInsets(new Insets(2, 8, 2, 8));
	setBackgroundShadowColor(new Color(0, 0, 0, 50));
}
 
源代码7 项目: fractals   文件: MandelbrotColor.java
public static void main(String[] args) throws Exception {
    int width = 1920, height = 1080, max = 1000;
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    int black = 0;
    int[] colors = new int[max];
    for (int i = 0; i<max; i++) {
        colors[i] = Color.HSBtoRGB(i/256f, 1, i/(i+8f));
    }

    for (int row = 0; row < height; row++) {
        for (int col = 0; col < width; col++) {
            double c_re = (col - width/2)*4.0/width;
            double c_im = (row - height/2)*4.0/width;
            double x = 0, y = 0;
            double r2;
            int iteration = 0;
            while (x*x+y*y < 4 && iteration < max) {
                double x_new = x*x-y*y+c_re;
                y = 2*x*y+c_im;
                x = x_new;
                iteration++;
            } 
            if (iteration < max) image.setRGB(col, row, colors[iteration]);
            else image.setRGB(col, row, black);
        }
    }

    ImageIO.write(image, "png", new File("mandelbrot.png"));
}
 
源代码8 项目: opsu-dance   文件: DistanceRainbow.java
@Override
public int getMovementColor(float movementProgress)
{
	float hue = this.hueBeforeMove + this.hueIncrease * movementProgress;
	hue = hue - (float) Math.floor(hue);
	return Color.HSBtoRGB(hue, saturation, 1f);
}
 
源代码9 项目: IngressAnimations   文件: OldGoldenSpiral.java
public static Color[] generatePastels(int n) {
	Color[] cc = new Color[n];
	for (int i=0; i<cc.length; i++) {
		cc[i] = new Color(Color.HSBtoRGB(((float)i)/n, 0.76f,1f));
	}
	return cc;
}
 
源代码10 项目: pumpernickel   文件: DarkenedIcon.java
/**
 * 
 * @param c
 *            the optional component used to invoke icon.paintIcon().
 *            Unfortunately for some icons (like
 *            UIManager.getIcon("IthisnternalFrame.maximizeIcon")) on
 *            Windows: we'll get a NPE if this is null.
 * 
 * @return
 */
private BufferedImage createImage(Component c) {
	Icon i = getIcon();
	BufferedImage bi = new BufferedImage(i.getIconWidth(),
			i.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
	Graphics2D g = bi.createGraphics();
	i.paintIcon(c, g, 0, 0);
	g.dispose();

	int[] row = new int[bi.getWidth()];
	float[] hsbvals = new float[3];
	for (int y = 0; y < bi.getHeight(); y++) {
		bi.getRaster().getDataElements(0, y, bi.getWidth(), 1, row);
		for (int x = 0; x < bi.getWidth(); x++) {
			int red = (row[x] & 0x00ff0000) >> 16;
			int green = (row[x] & 0x00ff00) >> 8;
			int blue = (row[x] & 0x00ff) >> 0;
			Color.RGBtoHSB(red, green, blue, hsbvals);
			hsbvals[2] = hsbvals[2] * (1 - f);
			int k = Color.HSBtoRGB(hsbvals[0], hsbvals[1], hsbvals[2]);
			k = (k & 0xffffff) + (row[x] & 0xff000000);
			row[x] = k;
		}
		bi.getRaster().setDataElements(0, y, bi.getWidth(), 1, row);
	}
	return bi;
}
 
源代码11 项目: mars-sim   文件: HsbColor.java
private HsbColor(Builder builder) {
    // private Constructor can only be called from Builder
    mHue = builder.getHue();
    mSaturation = builder.getSaturation();
    mBrightness = builder.getBrightness();
    final Color TMP_COLOR = new Color(Color.HSBtoRGB(mHue, mSaturation, mBrightness));
    mColor = new Color(TMP_COLOR.getRed(), TMP_COLOR.getGreen(), TMP_COLOR.getBlue(), builder.getAlpha());
}
 
源代码12 项目: Pixelitor   文件: HueComposite.java
@Override
public void composeRGB(int[] src, int[] dst, float alpha) {
    int w = src.length;

    for (int i = 0; i < w; i += 4) {
        int sr = src[i];
        int dir = dst[i];
        int sg = src[i + 1];
        int dig = dst[i + 1];
        int sb = src[i + 2];
        int dib = dst[i + 2];
        int sa = src[i + 3];
        int dia = dst[i + 3];
        int dor, dog, dob;

        Color.RGBtoHSB(sr, sg, sb, sHSB);
        Color.RGBtoHSB(dir, dig, dib, dHSB);

        dHSB[0] = sHSB[0];

        int doRGB = Color.HSBtoRGB(dHSB[0], dHSB[1], dHSB[2]);
        dor = (doRGB & 0xff0000) >> 16;
        dog = (doRGB & 0xff00) >> 8;
        dob = (doRGB & 0xff);

        float a = alpha * sa / 255.0f;
        float ac = 1 - a;

        dst[i] = (int) (a * dor + ac * dir);
        dst[i + 1] = (int) (a * dog + ac * dig);
        dst[i + 2] = (int) (a * dob + ac * dib);
        dst[i + 3] = (int) (sa * alpha + dia * ac);
    }
}
 
源代码13 项目: seaglass   文件: AbstractRegionPainter.java
/**
 * Derive and returns a color, which is based on an existing color.
 *
 * @param  src     The source color from which to derive the new color.
 * @param  hOffset The hue offset used for derivation.
 * @param  sOffset The saturation offset used for derivation.
 * @param  bOffset The brightness offset used for derivation.
 * @param  aOffset The alpha offset used for derivation. Between 0...255
 *
 * @return The derived color.
 */
protected Color deriveColor(Color src, float hOffset, float sOffset, float bOffset, int aOffset) {
    float[] tmp = Color.RGBtoHSB(src.getRed(), src.getGreen(), src.getBlue(), null);

    // apply offsets
    tmp[0] = clamp(tmp[0] + hOffset);
    tmp[1] = clamp(tmp[1] + sOffset);
    tmp[2] = clamp(tmp[2] + bOffset);
    int alpha = clamp(src.getAlpha() + aOffset);

    return new Color((Color.HSBtoRGB(tmp[0], tmp[1], tmp[2]) & 0xFFFFFF) | (alpha << 24), true);
}
 
源代码14 项目: pumpernickel   文件: ColorPickerSliderUI.java
@Override
public synchronized void paintTrack(Graphics g) {
	int mode = colorPicker.getMode();
	if (mode == JColorPicker.HUE || mode == JColorPicker.BRI
			|| mode == JColorPicker.SAT) {
		float[] hsb = colorPicker.getHSB();
		if (mode == JColorPicker.HUE) {
			for (int y = 0; y < trackRect.height; y++) {
				float hue = ((float) y) / ((float) trackRect.height);
				intArray[y] = Color.HSBtoRGB(hue, 1, 1);
			}
		} else if (mode == JColorPicker.SAT) {
			for (int y = 0; y < trackRect.height; y++) {
				float sat = 1 - ((float) y) / ((float) trackRect.height);
				intArray[y] = Color.HSBtoRGB(hsb[0], sat, hsb[2]);
			}
		} else {
			for (int y = 0; y < trackRect.height; y++) {
				float bri = 1 - ((float) y) / ((float) trackRect.height);
				intArray[y] = Color.HSBtoRGB(hsb[0], hsb[1], bri);
			}
		}
	} else {
		int[] rgb = colorPicker.getRGB();
		if (mode == JColorPicker.RED) {
			for (int y = 0; y < trackRect.height; y++) {
				int red = 255 - (int) (y * 255 / trackRect.height + .49);
				intArray[y] = (red << 16) + (rgb[1] << 8) + (rgb[2]);
			}
		} else if (mode == JColorPicker.GREEN) {
			for (int y = 0; y < trackRect.height; y++) {
				int green = 255 - (int) (y * 255 / trackRect.height + .49);
				intArray[y] = (rgb[0] << 16) + (green << 8) + (rgb[2]);
			}
		} else if (mode == JColorPicker.BLUE) {
			for (int y = 0; y < trackRect.height; y++) {
				int blue = 255 - (int) (y * 255 / trackRect.height + .49);
				intArray[y] = (rgb[0] << 16) + (rgb[1] << 8) + (blue);
			}
		}
	}
	Graphics2D g2 = (Graphics2D) g;
	Rectangle r = new Rectangle(6, trackRect.y, 14, trackRect.height);
	if (slider.hasFocus()) {
		PlafPaintUtils.paintFocus(g2, r, 3);
	}

	bi.getRaster().setDataElements(0, 0, 1, trackRect.height, intArray);
	TexturePaint p = new TexturePaint(bi, new Rectangle(0, trackRect.y, 1,
			bi.getHeight()));
	g2.setPaint(p);
	g2.fillRect(r.x, r.y, r.width, r.height);

	PlafPaintUtils.drawBevel(g2, r);
}
 
源代码15 项目: OpenModsLib   文件: GuiComponentColorPicker.java
public int getColor() {
	float h = pointX * 0.01f;
	float b = 1.0f - (pointY * 0.02f);
	float s = 1.0f - (tone / 255f);
	return Color.HSBtoRGB(h, s, b) & 0xFFFFFF;
}
 
源代码16 项目: mars-sim   文件: RangeSliderUI.java
public RangeSliderUI(final RangeSlider RANGE_SLIDER) {
    super(RANGE_SLIDER);
    thumbShape = RANGE_SLIDER.getThumbShape() != null ? RANGE_SLIDER.getThumbShape() : RangeSlider.ThumbShape.ROUND;
    thumbDesign = RANGE_SLIDER.getThumbDesign() != null ? RANGE_SLIDER.getThumbDesign() : RangeSlider.ThumbDesign.DARK;
    final Color RANGE_COLOR = RANGE_SLIDER.getRangeColor() != null ? RANGE_SLIDER.getRangeColor() : new Color(51, 204, 255);
    final int RED = RANGE_COLOR.getRed();
    final int GREEN = RANGE_COLOR.getGreen();
    final int BLUE = RANGE_COLOR.getBlue();
    if ((RED == GREEN) && (GREEN == BLUE)) {
        rangeColors = new Color[]{
            new Color(Color.HSBtoRGB(0.0f, 0.0f, 0.95f)),
            new Color(Color.HSBtoRGB(0.0f, 0.0f, 0.88f)),
            new Color(Color.HSBtoRGB(0.0f, 0.0f, 0.67f)),
            new Color(Color.HSBtoRGB(0.0f, 0.0f, 0.49f))
        };
    } else {
        final float RANGE_COLOR_HUE = Color.RGBtoHSB(RED, GREEN, BLUE, null)[0];
        rangeColors = new Color[]{
            new Color(Color.HSBtoRGB(RANGE_COLOR_HUE, 0.85f, 0.95f)),
            new Color(Color.HSBtoRGB(RANGE_COLOR_HUE, 0.85f, 0.88f)),
            new Color(Color.HSBtoRGB(RANGE_COLOR_HUE, 0.85f, 0.67f)),
            new Color(Color.HSBtoRGB(RANGE_COLOR_HUE, 0.85f, 0.49f))
        };
    }
    darkTrack = RANGE_SLIDER.isDarkTrack();
    slider = RANGE_SLIDER;
    initThumbs();
    lowerThumbHover = false;
    upperThumbHover = false;
    TRACK_FRAME = new RoundRectangle2D.Double();
    TRACK = new RoundRectangle2D.Double();
    RANGE = new RoundRectangle2D.Double();
    switch(thumbShape) {
        case ROUND:
            indicatorsVisible = true;
            break;
        case SQUARE:
            indicatorsVisible = true;
            break;
        default:
            indicatorsVisible = false;
    }
}
 
源代码17 项目: Pixelitor   文件: Gradient.java
private void rebuildGradient() {
        xKnots[0] = -1;
        xKnots[numKnots - 1] = 256;
        yKnots[0] = yKnots[1];
        yKnots[numKnots - 1] = yKnots[numKnots - 2];

//		int knot = 0;
        for (int i = 1; i < numKnots - 1; i++) {
            float spanLength = xKnots[i + 1] - xKnots[i];
            int end = xKnots[i + 1];
            if (i == numKnots - 2) {
                end++;
            }
            for (int j = xKnots[i]; j < end; j++) {
                int rgb1 = yKnots[i];
                int rgb2 = yKnots[i + 1];
                float[] hsb1 = Color.RGBtoHSB((rgb1 >> 16) & 0xff, (rgb1 >> 8) & 0xff, rgb1 & 0xff, null);
                float[] hsb2 = Color.RGBtoHSB((rgb2 >> 16) & 0xff, (rgb2 >> 8) & 0xff, rgb2 & 0xff, null);
                float t = (j - xKnots[i]) / spanLength;
                int type = getKnotType(i);
                int blend = getKnotBlend(i);

                if (j >= 0 && j <= 255) {
                    switch (blend) {
                        case CONSTANT:
                            t = 0;
                            break;
                        case LINEAR:
                            break;
                        case SPLINE:
//						map[i] = ImageMath.colorSpline(j, numKnots, xKnots, yKnots);
                            t = ImageMath.smoothStep(0.15f, 0.85f, t);
                            break;
                        case CIRCLE_UP:
                            t = t - 1;
                            t = (float) Math.sqrt(1 - t * t);
                            break;
                        case CIRCLE_DOWN:
                            t = 1 - (float) Math.sqrt(1 - t * t);
                            break;
                    }
//					if (blend != SPLINE) {
                    switch (type) {
                        case RGB:
                            map[j] = ImageMath.mixColors(t, rgb1, rgb2);
                            break;
                        case HUE_CW:
                        case HUE_CCW:
                            if (type == HUE_CW) {
                                if (hsb2[0] <= hsb1[0]) {
                                    hsb2[0] += 1.0f;
                                }
                            } else {
                                if (hsb1[0] <= hsb2[1]) {
                                    hsb1[0] += 1.0f;
                                }
                            }
                            float h = ImageMath.lerp(t, hsb1[0], hsb2[0]) % ImageMath.TWO_PI;
                            float s = ImageMath.lerp(t, hsb1[1], hsb2[1]);
                            float b = ImageMath.lerp(t, hsb1[2], hsb2[2]);
                            map[j] = 0xff000000 | Color.HSBtoRGB(h, s, b);//FIXME-alpha
                            break;
                    }
//					}
                }
            }
        }
    }
 
源代码18 项目: nanoleaf-desktop   文件: PanelCanvas.java
public void checkAuroraState() throws StatusCodeException
{
	if (devices != null && devices[0] != null)
	{
		stopLoadingSpinner();
		
		String colorMode = devices[0].state().getColorMode();
		if (colorMode.equals("hs") || colorMode.equals("ct"))
		{
			if (customEffectDisplay != null)
			{
				customEffectDisplay.stop();
			}
			
			int hue = devices[0].state().getHue();
			int sat = devices[0].state().getSaturation();
			int bri = devices[0].state().getBrightness();
			setHSB(hue, sat, bri);
		}
		else if (colorMode.equals("effects") || colorMode.equals("effect"))
		{
			String currentEffectName = devices[0].effects().getCurrentEffectName();
			Effect currentEffect = devices[0].effects().getCurrentEffect();
			if (currentEffect != null && currentEffect.getAnimType() != null)
			{
				if (currentEffectName.equals("*Static*") ||
						currentEffect.getAnimType().equals(Effect.Type.STATIC))
				{
					if (customEffectDisplay != null)
					{
						customEffectDisplay.stop();
					}
					setStaticEffect(currentEffect);
				}
				else if (currentEffect.getAnimType().equals(Effect.Type.CUSTOM))
				{
					// **************** Currently disabled ****************
					//customEffectDisplay.changeEffect(currentEffect);
				}
				else if (!currentEffect.getAnimType().equals(Effect.Type.STATIC))
				{
					if (customEffectDisplay != null)
					{
						customEffectDisplay.stop();
					}
					io.github.rowak.nanoleafapi.Color[] palette =
							currentEffect.getPalette();
					int[] avgRgb = new int[3];
					if (palette != null)
					{
						for (io.github.rowak.nanoleafapi.Color c : palette)
						{
							Color rgb = new Color(Color.HSBtoRGB(c.getHue()/360f,
									c.getSaturation()/100f, c.getBrightness()/100f));
							avgRgb[0] += rgb.getRed();
							avgRgb[1] += rgb.getGreen();
							avgRgb[2] += rgb.getBlue();
						}
						Color avgColor = new Color(avgRgb[0]/palette.length,
								avgRgb[1]/palette.length, avgRgb[2]/palette.length);
						setColor(avgColor);
					}
				}
			}
		}
	}
}
 
源代码19 项目: opsu-dance   文件: TimeRainbow.java
@Override
public int getMovementColor(float movementProgress)
{
	return Color.HSBtoRGB(this.hue, saturation, 1.0f);
}
 
源代码20 项目: gcs   文件: Colors.java
/**
 * @param color  The color to base the new color on.
 * @param amount The amount to adjust the hue by, in the range -1 to 1.
 * @return The adjusted color.
 */
public static final Color adjustHue(Color color, float amount) {
    float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null);
    return new Color(Color.HSBtoRGB(Math.max(Math.min(hsb[0] + amount, 1.0f), 0.0f), hsb[1], hsb[2]));
}