/** * Mixes a collection of colors into this color * Calculates a new K and S coefficient using a weighted average of all K and S coefficients * In this implementation we assume each color has an equal concentration so each concentration * weight will be equal to 1/(1 + colors.size) * @param colors The Colors to mix into this Color */ public void Mix(IReadOnlyCollection <Color> colors) { var length = colors.Count; // just a little error checking if (length == 0) { return; } // calculate a concentration weight for a equal concentration of all colors in mix var concentration = 1.0 / (1.0 + length); // calculate first iteration var aR = _aR * concentration; var aG = _aG * concentration; var aB = _aB * concentration; // sum the weighted average for (var i = 0; i < length; i++) { var color = new KmColor(colors.ElementAt(i)); aR += color._aR * concentration; aG += color._aG * concentration; aB += color._aB * concentration; } // update with results _aR = aR; _aG = aG; _aB = aB; }
/** * Mixes another color into this color * Calculates a new K and S coefficient using by averaging the K and S values * In this implementation we assume each color has an equal concentration * @param color The Color to mix into this Color */ public void Mix(Color color) { // calculate new KS (Absorbance) for mix with one color of equal concentration var kmColor = new KmColor(color); _aR = (_aR + kmColor._aR) / 2.0; _aG = (_aG + kmColor._aG) / 2.0; _aB = (_aB + kmColor._aB) / 2.0; }