shamelessly stolen from
 https://github.com/chriseppstein/compass-colors/blob/master/lib/compass-colors/sass_extensions.rb#L86
 Though, I've inverted the coefficients, which seems more logical
513630
def mix!(other, pct = 50.0)
      coeff = pct.to_f / 100.0
      new_rgb = to_rgb.zip(other.to_rgb).map{|c1, c2| (c1 * (1 - coeff)) + (c2 * coeff)}
      h, s, l = self.class.rgb_to_hsl(*new_rgb)
      self.hue, self.saturation, self.lightness = 360*h, s, l
    end
209171
public static void srgbToLab( float r , float g , float b , float lab[] ) {
		ColorXyz.srgbToXyz(r,g,b,lab);

		float X = lab[0];
		float Y = lab[1];
		float Z = lab[2];

		float xr = X/Xr_f;
		float yr = Y/Yr_f;
		float zr = Z/Zr_f;

		float fx, fy, fz;
		if(xr > epsilon_f)	fx = (float)Math.pow(xr, 1.0f/3.0f);
		else				fx = (kappa_f*xr + 16.0f)/116.0f;
		if(yr > epsilon_f)	fy = (float)Math.pow(yr, 1.0/3.0f);
		else				fy = (kappa_f*yr + 16.0f)/116.0f;
		if(zr > epsilon_f)	fz = (float)Math.pow(zr, 1.0/3.0f);
		else				fz = (kappa_f*zr + 16.0f)/116.0f;

		lab[0] = 116.0f*fy-16.0f;
		lab[1] = 500.0f*(fx-fy);
		lab[2] = 200.0f*(fy-fz);
	}
615512
function sassifyFn(rawObject) {
  var sassified = '';

  Object.keys(rawObject).forEach(function iterateVariables(key) {
    var variable = rawObject[key];

    var stringified = JSON.stringify(variable);

    // Trim off double quotes for CSS variables.
    stringified = stringified.substring(1, stringified.length - 1);

    sassified += '$' + key + ': ' + stringified + ';\n';
  });

  return sassified;
}
53026
public static void verticalInverse(BorderIndex1D border , WlBorderCoef<WlCoef_F32> inverseCoef , GrayF32 input , GrayF32 output ) {

		UtilWavelet.checkShape(output,input);

		float []trends = new float[ output.height ];
		float []details = new float[ output.height ];

		boolean isLarger = input.height > output.height;
		int paddedHeight = output.height + output.height%2;

		final int lowerBorder = inverseCoef.getLowerLength()*2;
		final int upperBorder = output.height - inverseCoef.getUpperLength()*2;

		border.setLength(output.height+output.height%2);

		WlCoef_F32 coefficients;

		for( int x = 0; x < output.width; x++) {

			for( int i = 0; i < details.length; i++ ) {
				details[i] = 0;
				trends[i] = 0;
			}

			for( int y = 0; y < output.height; y += 2 ) {
				float a = input.get(x,y/2);
				float d = input.get(x,y/2+input.height/2);

				if( y < lowerBorder ) {
					coefficients = inverseCoef.getBorderCoefficients(y);
				} else if( y >= upperBorder ) {
					coefficients = inverseCoef.getBorderCoefficients(y-paddedHeight);
				} else {
					coefficients = inverseCoef.getInnerCoefficients();
				}

				final int offsetA = coefficients.offsetScaling;
				final int offsetB = coefficients.offsetWavelet;
				final float[] alpha = coefficients.scaling;
				final float[] beta = coefficients.wavelet;

				// add the 'average' signal
				for( int i = 0; i < alpha.length; i++ ) {
					// if an odd image don't update the outer edge
					int yy = border.getIndex(y+offsetA+i);
					if( isLarger && yy >= output.height )
						continue;
					trends[yy] += a*alpha[i];
				}

				// add the detail signal
				for( int i = 0; i < beta.length; i++ ) {
					int yy = border.getIndex(y+offsetB+i);
					if( isLarger && yy >= output.height )
						continue;
					details[yy] += d*beta[i];
				}
			}

			for( int y = 0; y < output.height; y++ ) {
				output.set(x,y, trends[y] + details[y]);
			}
		}
	}
386295
def to_rgb
      chroma = (1 - (2 * @l - 1).abs) * @s
      x = chroma * (1 - ((@h / 60.0) % 2.0 - 1).abs)
      m = @l - chroma / 2.0

      rgb = if @h.zero?
              Color.new(0, 0, 0)
            elsif @h > 0 && @h < 60
              Color.new(chroma, x, 0)
            elsif @h > 60 && @h < 120
              Color.new(x, chroma, 0)
            elsif @h > 120 && @h < 180
              Color.new(0, chroma, x)
            elsif @h > 180 && @h < 240
              Color.new(0, x, chroma)
            elsif @h > 240 && @h < 300
              Color.new(x, 0, chroma)
            else
              Color.new(chroma, 0, x)
            end
      Color.new(((rgb.red + m) * 255.0).round, ((rgb.green + m) * 255.0).round, ((rgb.blue + m) * 255.0).round)
    end
433430
def _rgb_to_rgbw(color):
        
        # Get the maximum between R, G, and B
        max_value = max(color)

        # If the maximum value is 0, immediately return pure black.
        if max_value == 0:
            return [0] * 4

        # Figure out what the color with 100% hue is
        multiplier = 255 / max_value
        hue_red = color.R * multiplier
        hue_green = color.G * multiplier
        hue_blue = color.B * multiplier

        # Calculate the whiteness (not strictly speaking luminance)
        max_hue = max(hue_red, hue_green, hue_blue)
        min_hue = min(hue_red, hue_green, hue_blue)
        luminance = ((max_hue + min_hue) / 2 - 127.5) * 2 / multiplier

        # Calculate the output values
        r = max(0, min(255, int(color.R - luminance)))
        g = max(0, min(255, int(color.G - luminance)))
        b = max(0, min(255, int(color.B - luminance)))
        w = max(0, min(255, int(luminance)))

        return [r, g, b, w]
253583
def xterm_to_rgb(xcolor):
    
    assert 0 <= xcolor <= 255
    if xcolor < 16:
        # basic colors
        return BASIC16[xcolor]
    elif 16 <= xcolor <= 231:
        # color cube
        xcolor -= 16
        return (CUBE_STEPS[xcolor // 36 % 6],
                CUBE_STEPS[xcolor // 6 % 6],
                CUBE_STEPS[xcolor % 6])
    elif 232 <= xcolor <= 255:
        # gray tone
        c = 8 + (xcolor - 232) * 0x0A
        return (c, c, c)
225006
private static function rgb2hsl($r, $g, $b, &$h, &$s, &$l)
    {
        $r /= 255;
        $g /= 255;
        $b /= 255;

        $min = min([$r, $g, $b]);
        $max = max([$r, $g, $b]);

        $l = ($min + $max) / 2;
        $l = round($l, 2);

        if ($min == $max) {
            $s = 0;
            $h = 0;

            return;
        }

        if ($l < 0.5) {
            $s = ($max - $min) / ($max + $min);
        } else {
            $s = ($max - $min) / (2.0 - $max - $min);
        }

        if ($r == $max) {
            $h = ($g - $b) / ($max - $min);
        } elseif ($g == $max) {
            $h = 2.0 + ($b - $r) / ($max - $min);
        } else {
            $h = 4.0 + ($r - $g) / ($max - $min);
        }

        $h *= 60;
        $h = $h < 0 ? $h + 360 : $h;
        $h = (int)round($h);

        $s = round($s, 2);
    }
1011900
function colorgrad() {
    var args = Array.prototype.slice.call(arguments)
      , arraymath = require('./arraymath')
      , spec
      , cstep
      , c1 = args[0]
      , c2 = null
      , rgb1
      , rgb2
      , outType = isArray(c1) ? 'rgb': 'hex'
      , add = arraymath("+")
      , sub = arraymath("-")
      , div = arraymath("/")
      , mul = arraymath("*")

    /*
     *
     * Unpack specification object
     *
     */
    if(isObj(args[1])) {
      spec = args[1]
    }
    else if (isObj(args[2])) {
      spec = args[2]
      c2 = args[1]
    }
    else
      spec = {}
    /*
     * Or with defaults
     */
    var lum = spec.lum || 1
      , n = spec.nshades || 100
      , type = spec.type || "linear"

    /*
     *
     * Design the color step array which will be
     * a length 3 vector.
     *
     */
    rgb1 = isArray(c1) ? c1 : hex2rgb(c1)
    if(c2) // If two hexcolors supplied
      rgb2 = isArray(c2) ? c2 : hex2rgb(c2)
    else // 2nd color is lum% incr/decr of color1
      rgb2 = add( mul(rgb1,[lum]), rgb1)

    // Create step size to step through color gradient
    cstep = div( sub(rgb2, rgb1), [n-1])

    var i
      , nc = []
    nc[0] = rgb1
    for (i = 1; i < n; ++i) {
      nc[i] = add(nc[i-1], cstep)
    }

    function clims(c) {
      if(c > 255)
        return 255
      else if(c < 0)
        return 0
      else return c
    }

    var result = []
    nc.forEach(function (ar) {
      ar = ar.map(Math.round).map(clims)
      if(outType === 'hex')
        ar = rgb2hex(ar)
      result.push( ar )
    })
    return result
  }
804084
def reverse_color(moves)
      moves.each do |move|
        if move["move"] && move["move"]["color"]
          move["move"]["color"] = (move["move"]["color"] + 1) % 2
        end
        move["forks"].each { |_fork| reverse_color(_fork) } if move["forks"]
      end
    end
25291
function (from, to, pos) {
		// Check for has alpha, because rgba colors perform worse due to lack of
		// support in WebKit.
		var hasAlpha,
			ret;

		// Unsupported color, return to-color (#3920)
		if (!to.rgba.length || !from.rgba.length) {
			ret = to.raw || 'none';

		// Interpolate
		} else {
			from = from.rgba;
			to = to.rgba;
			hasAlpha = (to[3] !== 1 || from[3] !== 1);
			ret = (hasAlpha ? 'rgba(' : 'rgb(') + 
				Math.round(to[0] + (from[0] - to[0]) * (1 - pos)) + ',' + 
				Math.round(to[1] + (from[1] - to[1]) * (1 - pos)) + ',' + 
				Math.round(to[2] + (from[2] - to[2]) * (1 - pos)) + 
				(hasAlpha ? (',' + (to[3] + (from[3] - to[3]) * (1 - pos))) : '') + ')';
		}
		return ret;
	}
351830
function (idx) {
		var r = this.getRed(idx),
			g = this.getGreen(idx),
			b = this.getBlue(idx);

		r = Math.floor((0.393 * r) + (0.769 * g) + (0.189 * b));
		g = Math.floor((0.349 * r) + (0.686 * g) + (0.168 * b));
		b = Math.floor((0.272 * r) + (0.534 * g) + (0.131 * b));

		r = r < 0 ? 0 : (r > 255 ? 255 : r);
		g = g < 0 ? 0 : (g > 255 ? 255 : g);
		b = b < 0 ? 0 : (b > 255 ? 255 : b);

		return {red: r, green: g, blue: b};
	}
484814
function(pos, width){
		if( arguments.length === 0 ){
			pos = this.gradient[0].getPosition();
			var last = this.gradient[this.gradient.length-1].getPosition();
			width = Math.floor(last - pos);
		}

		var result = new ColorList();
		if( this.gradient.length === 0 ){
			return result;
		}

		var frac = 0,
			currPoint, nextPoint,
			endPos = pos + width,
			i = 0,
			l = this.gradient.length;

		for( i=0; i<l; i++ ){
			if( this.gradient[i].pos < pos ){
				currPoint = this.gradient[i];
			}
		}

		var isPremature = (currPoint===undefined),
			activeGradient;
		if( !isPremature ){
			activeGradient = filter(this.gradient, function( g ){ return g.pos >= currPoint.pos; });
		} else {
			//start position is before 1st gradient color, so use whole
			activeGradient = this.gradient;
			currPoint = this.gradient[0];
		}

		var currWidth = 0;
		//start over with i, and use it to iterate
		i = 0;
		l = activeGradient.length;
		if( currPoint !== activeGradient[l-1] ){
			nextPoint = activeGradient[i];
			if( isPremature ){
				var d = currPoint.pos - pos;
				currWidth = mathUtils.abs( d ) > 0 ? 1 / d : 1;
			} else {
				if( nextPoint.pos - currPoint.pos > 0 ) {
					currWidth = 1 / (nextPoint.pos - currPoint.pos);
				}
			}
		}
		while( pos < endPos ){
			if( isPremature ){
				frac = 1 - (currPoint.pos - pos) * currWidth;
			} else {
				frac = (pos - currPoint.pos) * currWidth;
			}
			//switch to next color?
			if( frac > 1.0 ){
				currPoint = nextPoint;
				isPremature = false;
				i++;
				if( i < activeGradient.length ){
					nextPoint = activeGradient[i];
					if( currPoint !== activeGradient[l-1] ){
						currWidth = 1 / (nextPoint.pos - currPoint.pos);
					} else {
						currWidth = 0;
					}
					frac = (pos - currPoint.pos) * currWidth;
				}
			}
			if( currPoint  !== activeGradient[l-1] ){
				var ditheredFrac = mathUtils.clip( frac+mathUtils.normalizedRandom() * this.maxDither, 0, 1 );
				ditheredFrac = this.interpolator.interpolate( 0, 1, ditheredFrac );
				result.add( currPoint.color.getBlended(nextPoint.color, ditheredFrac) );
			} else {
				result.add( currPoint.color.copy() );
			}
			pos++;
		}
		return result;

	}
222411
def chromaticity_to_XYZ(white, red, green, blue):
    """"""
    xW, yW = white
    xR, yR = red
    xG, yG = green
    xB, yB = blue
    R = G = B = 1.0

    z = yW * ((xG - xB) * yR - (xR - xB) * yG + (xR - xG) * yB)
    YA = yR / R  * ((xG - xB) * yW - (xW - xB) * yG + (xW - xG) * yB) / z
    XA = YA * xR / yR
    ZA = YA * ((1 - xR) / yR - 1)
    YB = - yG / G * ((xR - xB) * yW - (xW - xB) * yR + (xW - xR) * yB) / z
    XB = YB * xG / yG
    ZB = YB * ((1 - xG) / yG - 1)
    YC = yB / B * ((xR - xG) * yW - (xW - xG) * yR + (xW - xR) * yG) / z
    XC = YC * xB / yB
    ZC = YC * ((1 - xB) / yB - 1)
    XW = XA * R + XB * G + XC * B
    YW = YA * R + YB * G + YC * B
    ZW = ZA * R + ZB * G + ZC * B

    return (XW, YW, ZW), (XA, YA, ZA), (XB, YB, ZB), (XC, YC, ZC)
677869
def Lab_to_XYZ(cobj, *args, **kwargs):
    
    illum = cobj.get_illuminant_xyz()
    xyz_y = (cobj.lab_l + 16.0) / 116.0
    xyz_x = cobj.lab_a / 500.0 + xyz_y
    xyz_z = xyz_y - cobj.lab_b / 200.0

    if math.pow(xyz_y, 3) > color_constants.CIE_E:
        xyz_y = math.pow(xyz_y, 3)
    else:
        xyz_y = (xyz_y - 16.0 / 116.0) / 7.787

    if math.pow(xyz_x, 3) > color_constants.CIE_E:
        xyz_x = math.pow(xyz_x, 3)
    else:
        xyz_x = (xyz_x - 16.0 / 116.0) / 7.787

    if math.pow(xyz_z, 3) > color_constants.CIE_E:
        xyz_z = math.pow(xyz_z, 3)
    else:
        xyz_z = (xyz_z - 16.0 / 116.0) / 7.787

    xyz_x = (illum["X"] * xyz_x)
    xyz_y = (illum["Y"] * xyz_y)
    xyz_z = (illum["Z"] * xyz_z)

    return XYZColor(
        xyz_x, xyz_y, xyz_z, observer=cobj.observer, illuminant=cobj.illuminant)
1276475
private void calchillshade( WritableRaster pitWR, WritableRaster hillshadeWR, WritableRaster gradientWR, double dx ) {

        pAzimuth = Math.toRadians(pAzimuth);
        pElev = Math.toRadians(pElev);

        double[] sunVector = calcSunVector();
        double[] normalSunVector = calcNormalSunVector(sunVector);
        double[] inverseSunVector = calcInverseSunVector(sunVector);
        int rows = pitWR.getHeight();
        int cols = pitWR.getWidth();
        WritableRaster sOmbraWR = calculateFactor(rows, cols, sunVector, inverseSunVector, normalSunVector, pitWR, dx);
        pm.beginTask(msg.message("hillshade.calculating"), rows * cols);
        for( int j = 1; j < rows - 1; j++ ) {
            for( int i = 1; i < cols - 1; i++ ) {

                double[] ng = gradientWR.getPixel(i, j, new double[3]);
                double cosinc = scalarProduct(sunVector, ng);
                if (cosinc < 0) {
                    sOmbraWR.setSample(i, j, 0, 0);
                }
                hillshadeWR.setSample(i, j, 0, (int) (212.5 * (cosinc * sOmbraWR.getSample(i, j, 0) + pMinDiffuse)));
                pm.worked(1);
            }
        }
        pm.done();
    }
1254114
def unicode(self, *, invert_color: bool = False, borders: bool = False) -> str:
        
        builder = []
        for rank_index in range(7, -1, -1):
            if borders:
                builder.append("  ")
                builder.append("-" * 17)
                builder.append("\n")

                builder.append(RANK_NAMES[rank_index])
                builder.append(" ")

            for file_index in range(8):
                square_index = square(file_index, rank_index)

                if borders:
                    builder.append("|")
                elif file_index > 0:
                    builder.append(" ")

                piece = self.piece_at(square_index)

                if piece:
                    builder.append(piece.unicode_symbol(invert_color=invert_color))
                else:
                    builder.append(u"·")

            if borders:
                builder.append("|")

            if borders or rank_index > 0:
                builder.append("\n")

        if borders:
            builder.append("  ")
            builder.append("-" * 17)
            builder.append("\n")
            builder.append("   a b c d e f g h")

        return "".join(builder)