Skip to content

Instantly share code, notes, and snippets.

@jameslkingsley
Created September 13, 2016 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jameslkingsley/d55f5ac22016680efb851e02255cac5a to your computer and use it in GitHub Desktop.
Save jameslkingsley/d55f5ac22016680efb851e02255cac5a to your computer and use it in GitHub Desktop.
private _colorMatrix = {
params [
["_rgba", [], [[]]],
["_matrix", [], [[]]]
];
if (_rgba isEqualTo [] || _matrix isEqualTo []) exitWith {};
_rgba params ["_r", "_g", "_b", "_a"];
private _fu = {([([255, _this] select (_this < 255)), 0] select (_this < 0))};
private _newR = ((_r * (_matrix select 0)) + (_g * (_matrix select 1)) + (_b * (_matrix select 2)) + (_a * (_matrix select 3)) + (_matrix select 4));
private _newG = ((_r * (_matrix select 5)) + (_g * (_matrix select 6)) + (_b * (_matrix select 7)) + (_a * (_matrix select 8)) + (_matrix select 9));
private _newB = ((_r * (_matrix select 10)) + (_g * (_matrix select 11)) + (_b * (_matrix select 12)) + (_a * (_matrix select 13)) + (_matrix select 14));
private _newA = ((_r * (_matrix select 15)) + (_g * (_matrix select 16)) + (_b * (_matrix select 17)) + (_a * (_matrix select 18)) + (_matrix select 19));
([
_newR call _fu,
_newG call _fu,
_newB call _fu,
_newA call _fu
])
};
private _blindType = {
params [["_type", "Normal", [""]]];
private _types = [
['Normal', [1,0,0,0,0, 0,1,0,0,0, 0,0,1,0,0, 0,0,0,1,0, 0,0,0,0,1]],
['Protanopia', [0.567,0.433,0,0,0, 0.558,0.442,0,0,0, 0,0.242,0.758,0,0, 0,0,0,1,0, 0,0,0,0,1]],
['Protanomaly', [0.817,0.183,0,0,0, 0.333,0.667,0,0,0, 0,0.125,0.875,0,0, 0,0,0,1,0, 0,0,0,0,1]],
['Deuteranopia', [0.625,0.375,0,0,0, 0.7,0.3,0,0,0, 0,0.3,0.7,0,0, 0,0,0,1,0, 0,0,0,0,1]],
['Deuteranomaly', [0.8,0.2,0,0,0, 0.258,0.742,0,0,0, 0,0.142,0.858,0,0, 0,0,0,1,0, 0,0,0,0,1]],
['Tritanopia', [0.95,0.05,0,0,0, 0,0.433,0.567,0,0, 0,0.475,0.525,0,0, 0,0,0,1,0, 0,0,0,0,1]],
['Tritanomaly', [0.967,0.033,0,0,0, 0,0.733,0.267,0,0, 0,0.183,0.817,0,0, 0,0,0,1,0, 0,0,0,0,1]],
['Achromatopsia', [0.299,0.587,0.114,0,0, 0.299,0.587,0.114,0,0, 0.299,0.587,0.114,0,0, 0,0,0,1,0, 0,0,0,0,1]],
['Achromatomaly', [0.618,0.320,0.062,0,0, 0.163,0.775,0.062,0,0, 0.163,0.320,0.516,0,0,0,0,0,1,0,0,0,0,0]]
];
(((_types select {(_x select 0) == _type}) param [0, []]) param [1, []])
};
private _color = [[1, 0.5, 0, 1], ["Tritanopia"] call _blindType] call _colorMatrix;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment