여러가지 색상을 정비율로 혼합하여 반환.<br>
@param	{Array}		colors		칼라 Array
@param	{Number}	progress	뽑아낼 칼라 지점을 설정 0~1
@param	{String}	type		반환 받을 Color Type, "hex", "rgb", "rgba", "hsl", "hsla" 기본값은 "hex" (~IE8 에서는 rgba를 지원하지 않는다.)
@return	{Color}		예) #ffffff
975517
function ( colors, progress, type ) {
            if (progress > 1) {
                progress = 1;
            } else if (progress < 0) {
                progress = 0;
            }
            var colorNum = colors.length,
                sectionPer, section, sPercent;
            if (colorNum < 2) return colors[0];
            sectionPer = 1 / (colorNum - 1);
            section = Math.floor(progress / sectionPer);
            if (section < 0) return colors[0];
            if (section < colorNum - 1) {
                sPercent = (progress % sectionPer) / sectionPer;
                return this.mix( colors[section], colors[section + 1], sPercent, type );
            }
            return colors[colorNum - 1];
        }
776915
function parseColor(col) {
  let tmp;
  if (typeof col === 'string') {
    col = col.trim();
    if (col.slice(0,1) === '#') {
      if (col.length === 7) {
        return {
          r: parseInt('0x' + col.substr(1,2)),
          g: parseInt('0x' + col.substr(3,2)),
          b: parseInt('0x' + col.substr(5,2)),
          a: 1
        };
      } else if (col.length === 4) {
        return {
          r: Math.pow(parseInt('0x' + col.substr(1,1))+1,2)-1,
          g: Math.pow(parseInt('0x' + col.substr(2,1))+1,2)-1,
          b: Math.pow(parseInt('0x' + col.substr(3,1))+1,2)-1,
          a: 1
        };
      } else if (col.length === 9) {
        return {
          r: parseInt('0x' + col.substr(1,2)),
          g: parseInt('0x' + col.substr(3,2)),
          b: parseInt('0x' + col.substr(5,2)),
          a: parseInt('0x' + col.substr(7,2)) / 255
        };
      } else if (col.length === 5) {
        return {
          r: Math.pow(parseInt('0x' + col.substr(1,1))+1,2)-1,
          g: Math.pow(parseInt('0x' + col.substr(2,1))+1,2)-1,
          b: Math.pow(parseInt('0x' + col.substr(3,1))+1,2)-1,
          a: parseInt('0x' + col.substr(4,1)) / 15
        };
      }
    } else if (col.slice(0,4) === 'rgba') {
      tmp = col.substr(5).split(',');
      return {
        r: parseInt(tmp[0]),
        g: parseInt(tmp[1]),
        b: parseInt(tmp[2]),
        a: parseFloat(tmp[3])
      };
    } else if (col.slice(0,4) === 'hsla') {
      tmp = col.substr(5).split(',').slice(0,4);
      tmp[0] = tmp[0] / 359;
      tmp[1] = tmp[1].slice(0,-1) / 100;
      tmp[2] = tmp[2].slice(0,-2) / 100;
      tmp = hslaToRgba(...tmp);
      return {
        r: tmp[0],
        g: tmp[1],
        b: tmp[2],
        a: parseFloat(tmp[3])
      };
    } else if (col.slice(0,3) === 'rgb') {
      tmp = col.substr(4).split(',');
      return {
        r: parseInt(tmp[0]),
        g: parseInt(tmp[1]),
        b: parseInt(tmp[2]),
        a: 1
      };
    } else if (col.slice(0,3) === 'hsl') {
      tmp = col.substr(4).split(',').slice(0,3);
      tmp[0] = tmp[0] / 359;
      tmp[1] = tmp[1].slice(0,-1) / 100;
      tmp[2] = tmp[2].slice(0,-2) / 100;
      tmp = hslToRgb(...tmp);
      return {
        r: tmp[0],
        g: tmp[1],
        b: tmp[2],
        a: 1
      };
    } else if (col.slice(0,2) === '0x') {
      return {
          r: parseInt('0x' + col.substr(2,2)),
          g: parseInt('0x' + col.substr(4,2)),
          b: parseInt('0x' + col.substr(6,2)),
          a: parseInt('0x' + col.substr(8,2)) / 255
        };
    } else if (col === 'transparent') {
      return {
          r: 0,
          g: 0,
          b: 0,
          a: 0
        };
    } else if (colorNames.hasOwnProperty(col)) {
      return parseColor(colorNames[col]);
    }
  }
}
435225
function (rgbColor) {
            // TODO : Memoize this function by caching its input

            var match = rgbaRx.exec(rgbColor);
            if (match) {
                return this.setColor(+match[1], +match[2], +match[3], +match[5]);
            }

            return this.parseHex(rgbColor);
        }
401311
function toColor(v1, v2, v3, v4, v5) {
    var _r, _g, _b, _a, R, G, B, rgb, options;
    if (v1 === undefined) {
        _r = _g = _b = 0;
        _a = 1;
    } else if (Array.isArray(v1)) {
        options = v2 || {};
        _r = v1[0] !== undefined ? v1[0] : 0;
        _g = v1[1] !== undefined ? v1[1] : 0;
        _b = v1[2] !== undefined ? v1[2] : 0;
        _a = v1[3] !== undefined ? v1[3] : options.base || 1;
    } else if (v1.r !== undefined) {
        options = v2 || {};
        _r = v1.r;
        _g = v1.g;
        _b = v1.b;
        _a = v1.a !== undefined ? v1.a : options.base || 1;
    } else if (typeof v1 === 'string') {
        if (v1.indexOf('#') === 0) {
            return v1;
        }
        if (v1.indexOf('rgb') === 0) {
            return v1;
        }
        if (colors.indexOf(v1) !== -1) {
            return v1;
        }
    } else if (typeof v1 === 'number') {
        if (arguments.length === 1) { // Grayscale value
            _r = _g = _b = v1;
            _a = 1;
        } else if (arguments.length === 2) { // Gray and alpha or options
            _r = _g = _b = v1;
            if (typeof v2 === 'number') {
                _a = v2;
            } else {
                options = v2;
                _a = options.base || 1;
            }
        } else if (arguments.length === 3) { // RGB or gray, alpha and options
            if (typeof v3 === 'number') {
                _r = v1;
                _g = v2;
                _b = v3;
                _a = 1;
            } else {
                _r = _g = _b = v1;
                _a = v2;
                options = v3;
            }
        } else if (arguments.length === 4) { // RGB and alpha or options
            _r = v1;
            _g = v2;
            _b = v3;
            if (typeof v4 === 'number') {
                _a = v4;
            } else {
                options = v4 || {};
                _a = options.base || 1;
            }
        } else { // RGBA + options
            _r = v1;
            _g = v2;
            _b = v3;
            _a = v4;
            options = v5;
        }
    }

    if (!(typeof _r === 'number' &&
        typeof _g === 'number' &&
        typeof _b === 'number' &&
        typeof _a === 'number')) {
        throw new Error('Invalid color arguments');
    }

    options = options || {};

    // The base option allows you to specify values in a different range.
    if (options.base !== undefined) {
        _r /= options.base;
        _g /= options.base;
        _b /= options.base;
        _a /= options.base;
    }
    R = Math.round(_r * 255);
    G = Math.round(_g * 255);
    B = Math.round(_b * 255);
    return 'rgba(' + R + ', ' + G + ', ' + B + ', ' + _a + ')';
}
1041607
function toGradientData(v1, v2, v3, v4, v5) {
    var startColor, endColor, type, rotation, spread, d;
    var data = {};

    if (arguments.length === 1) { // The argument is a dictionary or undefined.
        d = v1 || {};
        startColor = d.startColor;
        endColor = d.endColor;
        type = d.type;
        rotation = d.rotation;
        spread = d.spread;
    } else if (arguments.length >= 2) { // The first two arguments are a start color and an end color.
        startColor = v1;
        endColor = v2;
        type = 'linear';
        rotation = 0;
        spread = 0;
        if (arguments.length === 3) {
            if (typeof v3 === 'string') { // The type can be either linear or radial.
                type = v3;
            } else if (typeof v3 === 'number') { // The type is implicitly linear and the third argument is the rotation angle.
                rotation = v3;
            }
        } else if (arguments.length === 4) {
            if (typeof v3 === 'number') { // The type is implicitly linear and the third/forth arguments are the rotation angle and gradient spread.
                rotation = v3;
                spread = v4;
            } else if (v3 === 'linear') { // The type is explicitly linear and the forth argument is the rotation angle.
                rotation = v4;
            } else if (v3 === 'radial') { // The type is explicitly radial and the forth argument is the gradient spread.
                type = v3;
                spread = v4;
            } else {
                throw new Error('Wrong argument provided: ' + v3);
            }
        } else if (arguments.length === 5) { // Type, rotation (unused in case of radial type gradient), and gradient spread.
            type = v3;
            rotation = v4;
            spread = v5;
        }
    }

    if (!startColor && startColor !== 0) {
        throw new Error('No startColor was given.');
    }
    if (!endColor && endColor !== 0) {
        throw new Error('No endColor was given.');
    }

    try {
        data.startColor = toColor(startColor);
    } catch (e1) {
        throw new Error('startColor is not a valid color: ' + startColor);
    }

    try {
        data.endColor = toColor(endColor);
    } catch (e2) {
        throw new Error('endColor is not a valid color: ' + endColor);
    }

    if (type === undefined) {
        type = 'linear';
    }
    if (type !== 'linear' && type !== 'radial') {
        throw new Error('Unknown gradient type: ' + type);
    }

    data.type = type;

    if (spread === undefined) {
        spread = 0;
    }
    if (typeof spread !== 'number') {
        throw new Error('Spread value is not a number: ' + spread);
    }

    if (type === 'linear') {
        if (rotation === undefined) {
            rotation = 0;
        }
        if (typeof rotation !== 'number') {
            throw new Error('Rotation value is not a number: ' + rotation);
        }
        data.rotation = rotation;
    }

    data.spread = clamp(spread, 0, 0.99);

    return data;
}
627251
public static final Color getColorForValue(double val) {
    // Color positions
    double[] pos = new double[] { 0.0, 0.6, 0.8, 1.0 };
    // Colors at these positions
    Color[] cols = new Color[] { new Color(0.0f, 0.0f, 0.0f, 0.6f), new Color(0.0f, 0.0f, 1.0f, 0.8f), new Color(1.0f, 0.0f, 0.0f, 0.9f), new Color(1.0f, 1.0f, 0.0f, 1.0f) };
    assert (pos.length == cols.length);
    if(val < pos[0]) {
      val = pos[0];
    }
    // Linear interpolation:
    for(int i = 1; i < pos.length; i++) {
      if(val <= pos[i]) {
        Color prev = cols[i - 1];
        Color next = cols[i];
        final double mix = (val - pos[i - 1]) / (pos[i] - pos[i - 1]);
        final int r = (int) ((1 - mix) * prev.getRed() + mix * next.getRed());
        final int g = (int) ((1 - mix) * prev.getGreen() + mix * next.getGreen());
        final int b = (int) ((1 - mix) * prev.getBlue() + mix * next.getBlue());
        final int a = (int) ((1 - mix) * prev.getAlpha() + mix * next.getAlpha());
        Color col = new Color(r, g, b, a);
        return col;
      }
    }
    return cols[cols.length - 1];
  }
1304923
function Color(color) {
    this._reset();
    if (typeof color === 'string') {
        this.parse(color);
    } else {
        var array;
        if (Array.isArray(color)) {
            array = color;
        } else if (typeof color === 'object' && Array.isArray(color.rgba)) {
            array = color.rgba;
        }
        if (array) {
            for (var i = 0; i < this.rgba.length; i++) {
                this.rgba[i] = array[i];
            }
        }
    }
}
64739
function(color, alpha) {
            color = color.toRGB();
            alpha = Math.min(Math.max(alpha, 0), 1);
            var rgb = this.clone();

            rgb.red = (rgb.red * (1 - alpha)) + (color.red * alpha);
            rgb.green = (rgb.green * (1 - alpha)) + (color.green * alpha);
            rgb.blue = (rgb.blue * (1 - alpha)) + (color.blue * alpha);
            rgb.alpha = (rgb.alpha * (1 - alpha)) + (color.alpha * alpha);

            return rgb;
        }
1272390
function color2hex6(color) {
	const named = namedColors[color.toLowerCase()]; if (named) { return '#'+ named; }
	const hex = (/^#([0-9A-Fa-f]{3,8})$/).exec(color); if (hex) {
		const c = hex[1]; if (c.length !== 5 && c.length !== 7) {
			return '#'+ (c.length < 6 ? c.split('').map(x => x+x).join('') : c).slice(0, 6);
		}
	}
	const rgb = (/^rgba?[(]([\d.e%+-]+)\s*(?:\s|,\s*)([\d.e%+-]+)\s*(?:\s|,\s*)([\d.e%+-]+)\s*(?:\s|,\s*)?.*?[)]$/).exec(color); if (rgb) {
		const r = parseNumber(rgb[1], 255), g = parseNumber(rgb[2], 255), b = parseNumber(rgb[3], 255);
		if (isFinite(r) && isFinite(g) && isFinite(b)) { return hexOf(r, g, b); }
	}
	const hsl = (/^hsla?[(]([\d.e+-]+)(|deg|rad|grad|turn)\s*(?:\s|,\s*)([\d.e+-]+[%])\s*(?:\s|,\s*)([\d.e+-]+[%])\s*(?:\s|,\s*)?.*?[)]$/).exec(color); if (hsl) {
		const h = parseNumber(hsl[1]) * hueMultiplier[hsl[2]], s = parseNumber(hsl[3], 100), l = parseNumber(hsl[4], 100);
		if (isFinite(h) && isFinite(s) && isFinite(l)) {
			const { r, g, b, } = hsl2rgb((h % 1 + 1) % 1, s < 0 ? 0 : s > 1 ? 1 : s, l < 0 ? 0 : l > 1 ? 1 : l);
			return hexOf(r, g, b);
		}
	}
	return null; // whatever
	function hexOf(r, g, b) {
		function clamp(n) { return (n < 0 ? 0 : n > 255 ? 255 : n |0).toString(16).padStart(2, '0'); }
		return '#'+ clamp(r) + clamp(g) + clamp(b);
	}
	function parseNumber(n, base) { return n[n.length - 1] === '%' ? n.slice(0, -1) / base : +n; }
	function hsl2rgb(h, s, l) { // basically from here: https://stackoverflow.com/a/9493060
		if (s === 0) { return { r: l * 256, g: l * 256, b: l * 256, }; } // achromatic
		const q = l < 0.5 ? l * (1 + s) : l + s - l * s, p = 2 * l - q;
		return {
			r: hue2rgb(p, q, h + 1/3) * 256,
			g: hue2rgb(p, q, h) * 256,
			b: hue2rgb(p, q, h - 1/3) * 256,
		};
		function hue2rgb(p, q, t) {
			if (t < 0) { t += 1; } if (t > 1) { t -= 1; }
			if (t < 1/6) { return p + (q - p) * 6 * t; }
			if (t < 1/2) { return q; }
			if (t < 2/3) { return p + (q - p) * (2/3 - t) * 6; }
			return p;
		}
	}
}
814387
function (input) {
	// declare variables
	var rgba = [], result;

	/**
	 * Parse the input color to rgba array
	 * @param {String} input
	 */
	function init(input) {

		// rgba
		result = /rgba\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]?(?:\.[0-9]+)?)\s*\)/.exec(input);
		if (result) {
			rgba = [pInt(result[1]), pInt(result[2]), pInt(result[3]), parseFloat(result[4], 10)];
		} else { // hex
			result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(input);
			if (result) {
				rgba = [pInt(result[1], 16), pInt(result[2], 16), pInt(result[3], 16), 1];
			}
		}

	}
	/**
	 * Return the color a specified format
	 * @param {String} format
	 */
	function get(format) {
		var ret;

		// it's NaN if gradient colors on a column chart
		if (rgba && !isNaN(rgba[0])) {
			if (format === 'rgb') {
				ret = 'rgb(' + rgba[0] + ',' + rgba[1] + ',' + rgba[2] + ')';
			} else if (format === 'a') {
				ret = rgba[3];
			} else {
				ret = 'rgba(' + rgba.join(',') + ')';
			}
		} else {
			ret = input;
		}
		return ret;
	}

	/**
	 * Brighten the color
	 * @param {Number} alpha
	 */
	function brighten(alpha) {
		if (isNumber(alpha) && alpha !== 0) {
			var i;
			for (i = 0; i < 3; i++) {
				rgba[i] += pInt(alpha * 255);

				if (rgba[i] < 0) {
					rgba[i] = 0;
				}
				if (rgba[i] > 255) {
					rgba[i] = 255;
				}
			}
		}
		return this;
	}
	/**
	 * Set the color's opacity to a given alpha value
	 * @param {Number} alpha
	 */
	function setOpacity(alpha) {
		rgba[3] = alpha;
		return this;
	}

	// initialize: parse the input
	init(input);

	// public methods
	return {
		get: get,
		brighten: brighten,
		setOpacity: setOpacity
	};
}
310896
function setColor(color) {
         var alpha = this.currentColor.glArray[3];
         this.currentColor.copy(color);
         this.currentColor.glArray[3] *= alpha;
       }
1017371
function ( color ) {
            var type = this.type( color, 'color.toHex() : "' + color + '" ' + MSG_NOT_COLOR );
    
            switch ( type ) {
                case 'hex':
                    return color;
                    break;
                case 'rgb':
                case 'rgba':
                    return this.rgbToHex( color );
                    break;
                case 'hsl':
                case 'hsla':
                    color = this.hslToRgb( color );
                    return this.rgbToHex( color );
                    break;
                case 'keyword':
                    return this.keyword( color, 'color.toHex() : "' + color + '" ' + MSG_NOT_COLOR );
                    break;
            }
        }
820198
public static function get_colors($type = 'hex')
    {
        $cached = self::$colorsCached;
        if (isset($cached[$type])) return $cached[$type];

        $colors = Config::inst()->get('Identity', 'colors');
        if ($type == 'rgb') {
            $rgbColors = [];
            foreach ($colors as $name => $c) {
                $rgbColors[$name] = self::hex2rgb($c);
            }
            $colors = $rgbColors;
        }
        self::$colorsCached[$type] = $colors;
        return $colors;
    }
402781
function(color) {
        this._reset();
        if (!color)
            return;
        var r, g, b;
        color = (color.charAt(0) == '#') ? color.substring(1, color.length)
                : color;
        if (color.length == 3) {
            r = parseInt(color.substring(0, 1) + color.substring(0, 1), 16);
            g = parseInt(color.substring(1, 2) + color.substring(1, 2), 16);
            b = parseInt(color.substring(2, 3) + color.substring(2, 3), 16);
        } else {
            r = parseInt(color.substring(0, 2), 16);
            g = parseInt(color.substring(2, 4), 16);
            b = parseInt(color.substring(4, 6), 16);
        }
        this.rgba[0] = r;
        this.rgba[1] = g;
        this.rgba[2] = b;
    }
464660
public static RgbaColor from(String color) {
        if (color.startsWith("#")) {
            return fromHex(color);
        }
        else if (color.startsWith("rgba")) {
            return fromRgba(color);
        }
        else if (color.startsWith("rgb")) {
            return fromRgb(color);
        }
        else if (color.startsWith("hsla")) {
            return fromHsla(color);
        }
        else if (color.startsWith("hsl")) {
            return fromHsl(color);
        }
        else {
            return getDefaultColor();
        }
    }
1332751
function (data, colorFunc, state) {
        var gradientPixels = this._gradientPixels;
        var pixelsSingleState = gradientPixels[state] || (gradientPixels[state] = new Uint8ClampedArray(256 * 4));
        var color = [0, 0, 0, 0];
        var off = 0;
        for (var i = 0; i < 256; i++) {
            colorFunc[state](i / 255, true, color);
            pixelsSingleState[off++] = color[0];
            pixelsSingleState[off++] = color[1];
            pixelsSingleState[off++] = color[2];
            pixelsSingleState[off++] = color[3];
        }
        return pixelsSingleState;
    }
1011319
public static TermColor getColorByFunction(TermFunction func) {
    	
        List<Term<?>> args = func.getSeparatedValues(CSSFactory.getTermFactory().createOperator(','), false);
        if (args != null)
        {
        	if ((COLOR_RGB_NAME.equals(func.getFunctionName()) && args.size() == COLOR_PARAMS_COUNT)
        	   || COLOR_RGBA_NAME.equals(func.getFunctionName()) && args.size() == COLOR_PARAMS_COUNT + 1) {
        		
                boolean percVals = false;
                boolean intVals = false;
        		int[] rgb = new int[COLOR_PARAMS_COUNT];
        		for(int i = 0; i < COLOR_PARAMS_COUNT; i++) {
        		    Term<?> term = args.get(i);
        			// term is number and numeric
        			if(term instanceof TermInteger ) {
        				rgb[i] = ((TermInteger)term).getIntValue();
        				intVals = true;
        			}
        			// term is percent
        			else if(term instanceof TermPercent) {
        				final int value = ((TermPercent) term).getValue().intValue();
        				rgb[i] = (value * MAX_VALUE) / PERCENT_CONVERSION;
        				percVals = true;
        			}
        			// not valid term
        			else {
        				return null;
        			}
        		}
        		
        		if (percVals && intVals) //do not allow both percentages and int values combined
        		    return null;
        		
        		// limits
        		for(int i = 0; i < rgb.length; i++) {
        			if(rgb[i] < MIN_VALUE) rgb[i] = MIN_VALUE;
        			if(rgb[i] > MAX_VALUE) rgb[i] = MAX_VALUE;
        		}
        		
        		//alpha
        		int a = MAX_VALUE;
        		if (args.size() > COLOR_PARAMS_COUNT)
        		{
        		    Term<?> term = args.get(COLOR_PARAMS_COUNT);
        		    if (term instanceof TermNumber || term instanceof TermInteger) {
        		        float alpha = getFloatValue(term);
        		        a = Math.round(alpha * MAX_VALUE);
        		        if (a < MIN_VALUE) a = MIN_VALUE;
        		        if (a > MAX_VALUE) a = MAX_VALUE;
        		    }
        		    else
        		        return null; //unacceptable alpha value
        		}
        		
        		return new TermColorImpl(rgb[0], rgb[1], rgb[2], a);
        	}
        	else if ((COLOR_HSL_NAME.equals(func.getFunctionName()) && args.size() == COLOR_PARAMS_COUNT)
                    || COLOR_HSLA_NAME.equals(func.getFunctionName()) && args.size() == COLOR_PARAMS_COUNT + 1) {
    
        	    float h, s, l;
        	    Term<?> hterm = args.get(0);
                if (hterm instanceof TermNumber || hterm instanceof TermInteger) {
                    h = getFloatValue(hterm);
        	        while (h >= MAX_HUE) h -= MAX_HUE;
        	        while (h < 0) h += MAX_HUE;
        	        h = h / MAX_HUE; //normalize to 0..1
        	    }
        	    else
        	        return null;
    
                Term<?> sterm = args.get(1);
                if (sterm instanceof TermPercent) {
                    int is = ((TermPercent) sterm).getValue().intValue();
                    if (is > 100) is = 100;
                    else if (is < 0) is = 0;
                    s = is / 100.0f;
                }
                else
                    return null;
        	    
                Term<?> lterm = args.get(2);
                if (lterm instanceof TermPercent) {
                    int il = ((TermPercent) lterm).getValue().intValue();
                    if (il > 100) il = 100;
                    else if (il < 0) il = 0;
                    l = il / 100.0f;
                }
                else
                    return null;
                
                int[] rgb = hslToRgb(h, s, l);
                
                // alpha
                int a = MAX_VALUE;
                if (args.size() > COLOR_PARAMS_COUNT)
                {
                    Term<?> term = args.get(3);
                    if (term instanceof TermNumber || term instanceof TermInteger) {
                        float alpha = getFloatValue(term);
                        a = Math.round(alpha * MAX_VALUE);
                        if (a < MIN_VALUE) a = MIN_VALUE;
                        if (a > MAX_VALUE) a = MAX_VALUE;
                    }
                    else
                        return null; // unacceptable alpha value
                }
    
                return new TermColorImpl(rgb[0], rgb[1], rgb[2], a);
            }
        	// invalid function
        	else
        	    return null;
        }
        else
            return null; //couldn't parse arguments
    }