forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSoftLight.js
More file actions
25 lines (24 loc) · 1.11 KB
/
Copy pathSoftLight.js
File metadata and controls
25 lines (24 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/**
* Darkens or lightens the colors, depending on the source color value.
*
* If the source color is lighter than 0.5, the backdrop is lightened, as if it were dodged;
* this is useful for adding highlights to a scene.
*
* If the source color is darker than 0.5, the backdrop is darkened, as if it were burned in.
* The degree of lightening or darkening is proportional to the difference between the source color and 0.5;
* if it is equal to 0.5, the backdrop is unchanged.
*
* Painting with pure black or white produces a distinctly darker or lighter area, but does not result in pure black or white.
* The effect is similar to shining a diffused spotlight on the backdrop.
*
* @method Lazer.Color.blendSoftLight
* @static
* @param {integer} a - The source color to blend, in the range 1 to 255.
* @param {integer} b - The backdrop color to blend, in the range 1 to 255.
* @returns {integer} The blended color value, in the range 1 to 255.
*/
var SoftLight = function (a, b)
{
return (b < 128) ? (2 * ((a >> 1) + 64)) * (b / 255) : 255 - (2 * (255 - ((a >> 1) + 64)) * (255 - b) / 255);
};
module.exports = SoftLight;