Skip to content

Commit 58ece72

Browse files
committed
Added in all of the final Color functions.
Added in all of the blend mode functions.
1 parent 90bd8a7 commit 58ece72

34 files changed

Lines changed: 621 additions & 10 deletions

v3/src/graphics/blendmodes/Add.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Adds the source and backdrop colors together and returns the value, up to a maximum of 255.
3+
*
4+
* @method Lazer.Color.blendAdd
5+
* @static
6+
* @param {integer} a - The source color to blend, in the range 1 to 255.
7+
* @param {integer} b - The backdrop color to blend, in the range 1 to 255.
8+
* @returns {integer} The blended color value, in the range 1 to 255.
9+
*/
10+
var Add = function (a, b)
11+
{
12+
return Math.min(255, a + b);
13+
};
14+
15+
module.exports = Add;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Takes the average of the source and backdrop colors.
3+
*
4+
* @method Lazer.Color.blendAverage
5+
* @static
6+
* @param {integer} a - The source color to blend, in the range 1 to 255.
7+
* @param {integer} b - The backdrop color to blend, in the range 1 to 255.
8+
* @returns {integer} The blended color value, in the range 1 to 255.
9+
*/
10+
var Average = function (a, b)
11+
{
12+
return (a + b) / 2;
13+
};
14+
15+
module.exports = Average;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Darkens the backdrop color to reflect the source color.
3+
* Painting with white produces no change.
4+
*
5+
* @method Lazer.Color.blendColorBurn
6+
* @static
7+
* @param {integer} a - The source color to blend, in the range 1 to 255.
8+
* @param {integer} b - The backdrop color to blend, in the range 1 to 255.
9+
* @returns {integer} The blended color value, in the range 1 to 255.
10+
*/
11+
var ColorBurn = function (a, b)
12+
{
13+
return (b === 0) ? b : Math.max(0, (255 - ((255 - a) << 8) / b));
14+
};
15+
16+
module.exports = ColorBurn;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Brightens the backdrop color to reflect the source color.
3+
* Painting with black produces no change.
4+
*
5+
* @method Lazer.Color.blendColorDodge
6+
* @static
7+
* @param {integer} a - The source color to blend, in the range 1 to 255.
8+
* @param {integer} b - The backdrop color to blend, in the range 1 to 255.
9+
* @returns {integer} The blended color value, in the range 1 to 255.
10+
*/
11+
var ColorDodge = function (a, b)
12+
{
13+
return (b === 255) ? b : Math.min(255, ((a << 8) / (255 - b)));
14+
};
15+
16+
module.exports = ColorDodge;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Selects the darker of the backdrop and source colors.
3+
*
4+
* @method Lazer.Color.blendDarken
5+
* @static
6+
* @param {integer} a - The source color to blend, in the range 1 to 255.
7+
* @param {integer} b - The backdrop color to blend, in the range 1 to 255.
8+
* @returns {integer} The blended color value, in the range 1 to 255.
9+
*/
10+
var Darken = function (a, b)
11+
{
12+
return (b > a) ? a : b;
13+
};
14+
15+
module.exports = Darken;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Subtracts the darker of the two constituent colors from the lighter.
3+
*
4+
* Painting with white inverts the backdrop color; painting with black produces no change.
5+
*
6+
* @method Lazer.Color.blendDifference
7+
* @static
8+
* @param {integer} a - The source color to blend, in the range 1 to 255.
9+
* @param {integer} b - The backdrop color to blend, in the range 1 to 255.
10+
* @returns {integer} The blended color value, in the range 1 to 255.
11+
*/
12+
var Difference = function (a, b)
13+
{
14+
return Math.abs(a - b);
15+
};
16+
17+
module.exports = Difference;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Produces an effect similar to that of the Difference mode, but lower in contrast.
3+
* Painting with white inverts the backdrop color; painting with black produces no change.
4+
*
5+
* @method Lazer.Color.blendExclusion
6+
* @static
7+
* @param {integer} a - The source color to blend, in the range 1 to 255.
8+
* @param {integer} b - The backdrop color to blend, in the range 1 to 255.
9+
* @returns {integer} The blended color value, in the range 1 to 255.
10+
*/
11+
var Exclusion = function (a, b)
12+
{
13+
return a + b - 2 * a * b / 255;
14+
};
15+
16+
module.exports = Exclusion;

v3/src/graphics/blendmodes/Glow.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var Reflect = require('./Reflect');
2+
3+
/**
4+
* Glow blend mode. This mode is a variation of reflect mode with the source and backdrop colors swapped.
5+
*
6+
* @method Lazer.Color.blendGlow
7+
* @static
8+
* @param {integer} a - The source color to blend, in the range 1 to 255.
9+
* @param {integer} b - The backdrop color to blend, in the range 1 to 255.
10+
* @returns {integer} The blended color value, in the range 1 to 255.
11+
*/
12+
var Glow = function (a, b)
13+
{
14+
return Reflect(b, a);
15+
};
16+
17+
module.exports = Glow;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
var Overlay = require('./Overlay');
2+
3+
/**
4+
* Multiplies or screens the colors, depending on the source color value.
5+
*
6+
* If the source color is lighter than 0.5, the backdrop is lightened, as if it were screened;
7+
* this is useful for adding highlights to a scene.
8+
*
9+
* If the source color is darker than 0.5, the backdrop is darkened, as if it were multiplied;
10+
* this is useful for adding shadows to a scene.
11+
*
12+
* The degree of lightening or darkening is proportional to the difference between the source color and 0.5;
13+
* if it is equal to 0.5, the backdrop is unchanged.
14+
*
15+
* Painting with pure black or white produces pure black or white. The effect is similar to shining a harsh spotlight on the backdrop.
16+
*
17+
* @method Lazer.Color.blendHardLight
18+
* @static
19+
* @param {integer} a - The source color to blend, in the range 1 to 255.
20+
* @param {integer} b - The backdrop color to blend, in the range 1 to 255.
21+
* @returns {integer} The blended color value, in the range 1 to 255.
22+
*/
23+
var HardLight = function (a, b)
24+
{
25+
return Overlay(b, a);
26+
};
27+
28+
module.exports = HardLight;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var VividLight = require('./VividLight');
2+
3+
/**
4+
* Runs blendVividLight on the source and backdrop colors.
5+
* If the resulting color is 128 or more, it receives a value of 255; if less than 128, a value of 0.
6+
* Therefore, all blended pixels have red, green, and blue channel values of either 0 or 255.
7+
* This changes all pixels to primary additive colors (red, green, or blue), white, or black.
8+
*
9+
* @method Lazer.Color.blendHardMix
10+
* @static
11+
* @param {integer} a - The source color to blend, in the range 1 to 255.
12+
* @param {integer} b - The backdrop color to blend, in the range 1 to 255.
13+
* @returns {integer} The blended color value, in the range 1 to 255.
14+
*/
15+
var HardMix = function (a, b)
16+
{
17+
return (VividLight(a, b) < 128) ? 0 : 255;
18+
};
19+
20+
module.exports = HardMix;

0 commit comments

Comments
 (0)