Java RGB Color Create deformationToRGB(final double val, final double min, final double max)

Here you can find the source of deformationToRGB(final double val, final double min, final double max)

Description

deformation To RGB

License

Open Source License

Declaration

private static int deformationToRGB(final double val, final double min, final double max) 

Method Source Code


//package com.java2s;

import java.awt.Color;

public class Main {
    private static final double COLOR_CENTER = 75 / 360.0;
    private static final double COLOR_GAP = 5 / 360.0;
    private static final double COLOR_RANGE_POS = 160 / 360.0;
    private static final double COLOR_RANGE_NEG = 75 / 360.0;
    private static final int COLOR_NaN = Color.MAGENTA.getRGB();
    private static boolean debugMode;

    private static int deformationToRGB(final double val, final double min, final double max) {
        final int result;
        if (Double.isNaN(val)) {
            if (debugMode) {
                result = COLOR_NaN;/*from  w  w  w.ja  v a 2s  .  c  om*/
            } else {
                result = Color.HSBtoRGB(0, 1, 0);
            }
        } else {
            float h, s = 1, b = 1;
            double fract;
            final double midlle = (max + min) / 2.0;
            final double half = max - midlle;
            if (val >= min && val <= max) {
                if (val < midlle) {
                    fract = -(val - midlle) / half;
                    h = (float) (fract * COLOR_RANGE_POS + COLOR_CENTER + COLOR_GAP);
                } else {
                    fract = (val - midlle) / half;
                    h = (float) (COLOR_CENTER - COLOR_GAP - (fract * COLOR_RANGE_NEG));
                }
            } else {
                h = 1;
                s = 0;
                b = 0.5f;
            }

            result = Color.HSBtoRGB(h, s, b);
        }
        return result;
    }
}

Related

  1. cmykToRgb(float... cmyk)
  2. fromHtmlRGB(String rgb)
  3. fromRGB(String tag)
  4. getRGB(Color color)
  5. getRGB(java.awt.Color color)