Code:
private ["_normalized","_min","_max","_failsafe","_clamp","_s"];
_normalized = _this select 0;
_min = _this select 1;
_max = _this select 2;
_clamp = if (count _this > 3) then {_this select 3} else {true}; //Optional parameter, default true. If false, answer may be outside 0-1 range.
_failsafe = if (_min == _max) then {0.0001} else {_min - _max}; //Avoids division by zero errors in the event of equal inputs.
_normalized= 1 - ((_normalized - _min) * (1 / _failsafe) +1); //Scales the input parameter to 0-1.
if (_clamp) then {_normalized = _normalized max 0 min 1}; //And clamps outside values if not actively set to false.
_normalized
fnSunElevation (without parameter checking I use for testing, untested in this copy&paste version):
Code:
private ["_ret","_amount","_bgtcontrast","_color","_bgt","_ctr","_a1","_r1","_g1","_b1","_r2","_g2","_b2","_sun"];
_amount = call sunElevation;
if (_amount < 30) then {
_amount = [_amount, -14, -1] call fnNormalize;
_amount = _amount min 1;
_amount = _amount max 0;
_amount = 1 - _amount; //Max effect when sun is -10° below horizon (or lower), no effect when sun is -1° below horizon (or higher).
_bgtcontrast = 1.0 - 0.32 * _amount;
_color = -0.05 * _amount;
_ret = [ _bgtcontrast, _bgtcontrast, 0, [0, 0, _color, _color],[0, 0, 0, 1],[0, 0, 0, 0]];
} else {
_amount = [_amount, 30, 52] call fnNormalize;
_amount = _amount min 1;
_amount = _amount max 0;
_val = (0.5*overcast*overcast) + (0.5*fog*fog);
_bgt = [1.5,0.7,_val] call fnSelectByLast;
_ctr = [-0.015,0.015,_val] call fnSelectByLast;
_a1 = [0.85,1.3,_val] call fnSelectByLast;
_r1 = 1; _g1 = 0; _b1 = -1;
_r2 = 0.899, _g2 = 0.0287, _b2 = 0.04;
_bgt = [1.0,_bgt,_amount] call fnSelectByLast;
_ctr = [0.0,_ctr,_amount] call fnSelectByLast;
_r1 = [0.0,_r1,_amount] call fnSelectByLast;
_g1 = [0.0,_g1,_amount] call fnSelectByLast;
_b1 = [0.0,_b1,_amount] call fnSelectByLast;
_a1 = [1.0,_a1,_amount] call fnSelectByLast;
_r2 = [0.0,_r2,_amount] call fnSelectByLast;
_g2 = [0.0,_g2,_amount] call fnSelectByLast;
_b2 = [0.0,_b2,_amount] call fnSelectByLast;
_ret = [1, _bgt, _ctr, [0,0,0,0], [_r1, _g1, _b1, _a1], [_r2, _g2, _b2, 0.0]];
};
_ret