From 5da0e42be4a0afa7c238f9756788558d73a1bb58 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Tue, 10 Sep 2013 14:00:46 +0100 Subject: [PATCH] Added in the Color Utils and removed the less important functions into ColorHarmony plugin. Updated Stage so backgroundColor can be a string or integer now. --- Plugins/ColorHarmony.js | 231 ++++++++++++++ Plugins/Plugins.csproj | 92 ------ Plugins/Template.js | 68 ---- Plugins/Template.ts | 74 ----- Plugins/app.js.map | 1 - ...gnTimeResolveAssemblyReferencesInput.cache | Bin 6226 -> 0 bytes ...le_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs | 0 ...le_5937a670-0e60-4077-877b-f7221da3dda1.cs | 0 ...le_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs | 0 examples/js.php | 3 + examples/stagecolor.php | 31 ++ src/core/Stage.js | 10 +- src/utils/Color.js | 291 ++++++++++++++++++ {Plugins => todo}/CameraFX/Border.js | 0 {Plugins => todo}/CameraFX/Border.ts | 0 {Plugins => todo}/CameraFX/Fade.js | 0 {Plugins => todo}/CameraFX/Fade.ts | 0 {Plugins => todo}/CameraFX/Flash.js | 0 {Plugins => todo}/CameraFX/Flash.ts | 0 {Plugins => todo}/CameraFX/Mirror.js | 0 {Plugins => todo}/CameraFX/Mirror.ts | 0 {Plugins => todo}/CameraFX/Scanlines.js | 0 {Plugins => todo}/CameraFX/Scanlines.ts | 0 {Plugins => todo}/CameraFX/Shadow.js | 0 {Plugins => todo}/CameraFX/Shadow.ts | 0 {Plugins => todo}/CameraFX/Shake.js | 0 {Plugins => todo}/CameraFX/Shake.ts | 0 {Plugins => todo}/verlet/AngleConstraint.js | 0 .../verlet/AngleConstraint.js.map | 0 {Plugins => todo}/verlet/AngleConstraint.ts | 0 {Plugins => todo}/verlet/Composite.js | 0 {Plugins => todo}/verlet/Composite.ts | 0 .../verlet/DistanceConstraint.js | 0 .../verlet/DistanceConstraint.ts | 0 {Plugins => todo}/verlet/Particle.js | 0 {Plugins => todo}/verlet/Particle.js.map | 0 {Plugins => todo}/verlet/Particle.ts | 0 {Plugins => todo}/verlet/PinConstraint.js | 0 {Plugins => todo}/verlet/PinConstraint.ts | 0 {Plugins => todo}/verlet/VerletManager.js | 0 {Plugins => todo}/verlet/VerletManager.ts | 0 41 files changed, 565 insertions(+), 236 deletions(-) create mode 100644 Plugins/ColorHarmony.js delete mode 100644 Plugins/Plugins.csproj delete mode 100644 Plugins/Template.js delete mode 100644 Plugins/Template.ts delete mode 100644 Plugins/app.js.map delete mode 100644 Plugins/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache delete mode 100644 Plugins/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs delete mode 100644 Plugins/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs delete mode 100644 Plugins/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs create mode 100644 examples/stagecolor.php create mode 100644 src/utils/Color.js rename {Plugins => todo}/CameraFX/Border.js (100%) rename {Plugins => todo}/CameraFX/Border.ts (100%) rename {Plugins => todo}/CameraFX/Fade.js (100%) rename {Plugins => todo}/CameraFX/Fade.ts (100%) rename {Plugins => todo}/CameraFX/Flash.js (100%) rename {Plugins => todo}/CameraFX/Flash.ts (100%) rename {Plugins => todo}/CameraFX/Mirror.js (100%) rename {Plugins => todo}/CameraFX/Mirror.ts (100%) rename {Plugins => todo}/CameraFX/Scanlines.js (100%) rename {Plugins => todo}/CameraFX/Scanlines.ts (100%) rename {Plugins => todo}/CameraFX/Shadow.js (100%) rename {Plugins => todo}/CameraFX/Shadow.ts (100%) rename {Plugins => todo}/CameraFX/Shake.js (100%) rename {Plugins => todo}/CameraFX/Shake.ts (100%) rename {Plugins => todo}/verlet/AngleConstraint.js (100%) rename {Plugins => todo}/verlet/AngleConstraint.js.map (100%) rename {Plugins => todo}/verlet/AngleConstraint.ts (100%) rename {Plugins => todo}/verlet/Composite.js (100%) rename {Plugins => todo}/verlet/Composite.ts (100%) rename {Plugins => todo}/verlet/DistanceConstraint.js (100%) rename {Plugins => todo}/verlet/DistanceConstraint.ts (100%) rename {Plugins => todo}/verlet/Particle.js (100%) rename {Plugins => todo}/verlet/Particle.js.map (100%) rename {Plugins => todo}/verlet/Particle.ts (100%) rename {Plugins => todo}/verlet/PinConstraint.js (100%) rename {Plugins => todo}/verlet/PinConstraint.ts (100%) rename {Plugins => todo}/verlet/VerletManager.js (100%) rename {Plugins => todo}/verlet/VerletManager.ts (100%) diff --git a/Plugins/ColorHarmony.js b/Plugins/ColorHarmony.js new file mode 100644 index 00000000..4b973b65 --- /dev/null +++ b/Plugins/ColorHarmony.js @@ -0,0 +1,231 @@ +/** +* A collection of methods useful for manipulating and comparing colors. +* +* @class ColorHarmony +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License +* @module Phaser +*/ + +Phaser.Plugins.ColorHarmony.prototype = { + + /** + * Returns a Complementary Color Harmony for the given color. + *

A complementary hue is one directly opposite the color given on the color wheel

+ *

Value returned in 0xAARRGGBB format with Alpha set to 255.

+ * + * @method getComplementHarmony + * @param {Number} color The color to base the harmony on. + * @return {Number} 0xAARRGGBB format color value. + */ + getComplementHarmony: function (color) { + + var hsv = Phaser.Color.RGBtoHSV(color); + var opposite = Phaser.Color.game.math.wrapValue(hsv.hue, 180, 359); + return Phaser.Color.HSVtoRGB(opposite, 1.0, 1.0); + + }, + + /** + * Returns an Analogous Color Harmony for the given color. + *

An Analogous harmony are hues adjacent to each other on the color wheel

+ *

Values returned in 0xAARRGGBB format with Alpha set to 255.

+ * + * @method getAnalogousHarmony + * @param {Number} color The color to base the harmony on. + * @param {Number} threshold Control how adjacent the colors will be (default +- 30 degrees) + * @return {Object} Object containing 3 properties: color1 (the original color), color2 (the warmer analogous color) and color3 (the colder analogous color) + */ + getAnalogousHarmony: function (color, threshold) { + if (typeof threshold === "undefined") { threshold = 30; } + var hsv = Phaser.Color.RGBtoHSV(color); + if(threshold > 359 || threshold < 0) { + throw Error("Color Warning: Invalid threshold given to getAnalogousHarmony()"); + } + var warmer = Phaser.Color.game.math.wrapValue(hsv.hue, 359 - threshold, 359); + var colder = Phaser.Color.game.math.wrapValue(hsv.hue, threshold, 359); + return { + color1: color, + color2: Phaser.Color.HSVtoRGB(warmer, 1.0, 1.0), + color3: Phaser.Color.HSVtoRGB(colder, 1.0, 1.0), + hue1: hsv.hue, + hue2: warmer, + hue3: colder + }; + }, + + /** + * Returns an Split Complement Color Harmony for the given color. + *

A Split Complement harmony are the two hues on either side of the color's Complement

+ *

Values returned in 0xAARRGGBB format with Alpha set to 255.

+ * + * @method getSplitComplementHarmony + * @param {Number} color The color to base the harmony on + * @param {Number} threshold Control how adjacent the colors will be to the Complement (default +- 30 degrees) + * @return {Object} An object containing 3 properties: color1 (the original color), color2 (the warmer analogous color) and color3 (the colder analogous color) + */ + getSplitComplementHarmony: function (color, threshold) { + if (typeof threshold === "undefined") { threshold = 30; } + var hsv = Phaser.Color.RGBtoHSV(color); + if(threshold >= 359 || threshold <= 0) { + throw Error("Phaser.Color Warning: Invalid threshold given to getSplitComplementHarmony()"); + } + var opposite = Phaser.Color.game.math.wrapValue(hsv.hue, 180, 359); + var warmer = Phaser.Color.game.math.wrapValue(hsv.hue, opposite - threshold, 359); + var colder = Phaser.Color.game.math.wrapValue(hsv.hue, opposite + threshold, 359); + return { + color1: color, + color2: Phaser.Color.HSVtoRGB(warmer, hsv.saturation, hsv.value), + color3: Phaser.Color.HSVtoRGB(colder, hsv.saturation, hsv.value), + hue1: hsv.hue, + hue2: warmer, + hue3: colder + }; + }, + + /** + * Returns a Triadic Color Harmony for the given color. + *

A Triadic harmony are 3 hues equidistant from each other on the color wheel

+ *

Values returned in 0xAARRGGBB format with Alpha set to 255.

+ * + * @method getTriadicHarmony + * @param {Number} color The color to base the harmony on. + * @return {Object} An Object containing 3 properties: color1 (the original color), color2 and color3 (the equidistant colors) + */ + getTriadicHarmony: function (color) { + var hsv = Phaser.Color.RGBtoHSV(color); + var triadic1 = Phaser.Color.game.math.wrapValue(hsv.hue, 120, 359); + var triadic2 = Phaser.Color.game.math.wrapValue(triadic1, 120, 359); + return { + color1: color, + color2: Phaser.Color.HSVtoRGB(triadic1, 1.0, 1.0), + color3: Phaser.Color.HSVtoRGB(triadic2, 1.0, 1.0) + }; + }, + + /** + * Get HSV color wheel values in an array which will be 360 elements in size. + * + * @method getHSVColorWheel + * @param {Number} alpha Alpha value for each color of the color wheel, between 0 (transparent) and 255 (opaque) + * @return {Array} An array containing 360 elements corresponding to the HSV color wheel. + */ + getHSVColorWheel: function (alpha) { + + alpha = alpha || 255; + + var colors = []; + + for (var c = 0; c <= 359; c++) + { + colors[c] = Phaser.Color.getWebRGB(Phaser.Color.HSVtoRGB(c, 1.0, 1.0, alpha)); + } + + return colors; + }, + + /** + * Convert a HSV (hue, saturation, lightness) color space value to an RGB color + * + * @method HSVtoRGB + * @param {Number} h Hue degree, between 0 and 359 + * @param {Number} s Saturation, between 0.0 (grey) and 1.0 + * @param {Number} v Value, between 0.0 (black) and 1.0 + * @param {Number} alpha Alpha value to set per color (between 0 and 255) + * @return {Number} 32-bit ARGB color value (0xAARRGGBB) + */ + HSVtoRGB: function (h, s, v, alpha) { + if (typeof alpha === "undefined") { alpha = 255; } + var result; + if(s == 0.0) { + result = Phaser.Color.getColor32(alpha, v * 255, v * 255, v * 255); + } else { + h = h / 60.0; + var f = h - Math.floor(h); + var p = v * (1.0 - s); + var q = v * (1.0 - s * f); + var t = v * (1.0 - s * (1.0 - f)); + switch(Math.floor(h)) { + case 0: + result = Phaser.Color.getColor32(alpha, v * 255, t * 255, p * 255); + break; + case 1: + result = Phaser.Color.getColor32(alpha, q * 255, v * 255, p * 255); + break; + case 2: + result = Phaser.Color.getColor32(alpha, p * 255, v * 255, t * 255); + break; + case 3: + result = Phaser.Color.getColor32(alpha, p * 255, q * 255, v * 255); + break; + case 4: + result = Phaser.Color.getColor32(alpha, t * 255, p * 255, v * 255); + break; + case 5: + result = Phaser.Color.getColor32(alpha, v * 255, p * 255, q * 255); + break; + default: + throw new Error("Phaser.Color.HSVtoRGB : Unknown color"); + } + } + return result; + }, + + /** + * Convert an RGB color value to an object containing the HSV color space values: Hue, Saturation and Lightness + * + * @method RGBtoHSV + * @param {Number} color In format 0xRRGGBB + * @return {Object} An Object with the properties hue (from 0 to 360), saturation (from 0 to 1.0) and lightness (from 0 to 1.0, also available under .value) + */ + RGBtoHSV: function (color) { + var rgb = Phaser.Color.getRGB(color); + var red = rgb.red / 255; + var green = rgb.green / 255; + var blue = rgb.blue / 255; + var min = Math.min(red, green, blue); + var max = Math.max(red, green, blue); + var delta = max - min; + var lightness = (max + min) / 2; + var hue; + var saturation; + // Grey color, no chroma + if(delta == 0) { + hue = 0; + saturation = 0; + } else { + if(lightness < 0.5) { + saturation = delta / (max + min); + } else { + saturation = delta / (2 - max - min); + } + var delta_r = (((max - red) / 6) + (delta / 2)) / delta; + var delta_g = (((max - green) / 6) + (delta / 2)) / delta; + var delta_b = (((max - blue) / 6) + (delta / 2)) / delta; + if(red == max) { + hue = delta_b - delta_g; + } else if(green == max) { + hue = (1 / 3) + delta_r - delta_b; + } else if(blue == max) { + hue = (2 / 3) + delta_g - delta_r; + } + if(hue < 0) { + hue += 1; + } + if(hue > 1) { + hue -= 1; + } + } + // Keep the value with 0 to 359 + hue *= 360; + hue = Math.round(hue); + return { + hue: hue, + saturation: saturation, + lightness: lightness, + value: lightness + }; + } + +} diff --git a/Plugins/Plugins.csproj b/Plugins/Plugins.csproj deleted file mode 100644 index c7910145..00000000 --- a/Plugins/Plugins.csproj +++ /dev/null @@ -1,92 +0,0 @@ - - - - Debug - {1106D1E1-DCE3-4CAF-8096-6C85F765D519} - {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} - Library - bin - v4.5 - full - true - true - - - - - - - 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - Plugins - - - - - - - - True - True - 0 - / - http://localhost:61985/ - False - False - - - False - - - - - - ES5 - true - false - - - ES5 - false - false - - - - - - - - - - Border.ts - - - - Fade.ts - - - - Flash.ts - - - Mirror.ts - - - Scanlines.ts - - - - Shadow.ts - - - - Shake.ts - - - Template.ts - - - - \ No newline at end of file diff --git a/Plugins/Template.js b/Plugins/Template.js deleted file mode 100644 index 8c54f41d..00000000 --- a/Plugins/Template.js +++ /dev/null @@ -1,68 +0,0 @@ -var __extends = this.__extends || function (d, b) { - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var Phaser; -(function (Phaser) { - /// - /// - /** - * Phaser - Example Plugin - */ - (function (Plugins) { - var Example = (function (_super) { - __extends(Example, _super); - function Example(game, parent) { - _super.call(this, game, parent); - this.active = true; - this.visible = true; - this.hasPreUpdate = false; - this.hasUpdate = false; - this.hasPostUpdate = false; - this.hasPreRender = false; - this.hasRender = false; - this.hasPostRender = false; - } - Example.prototype.preUpdate = /** - * Pre-update is called at the start of the update cycle, before any other updates have taken place. - * It is only called if active is set to true. - */ - function () { - }; - Example.prototype.update = /** - * Pre-update is called at the start of the update cycle, after all the core system updates have taken place, but before the world update. - * It is only called if active is set to true. - */ - function () { - }; - Example.prototype.postUpdate = /** - * Post-update is called at the end of the objects update cycle, after other update logic has taken place. - * It is only called if active is set to true. - */ - function () { - }; - Example.prototype.preRender = /** - * Pre-render is called right before the Game Renderer starts and before any custom preRender callbacks have been run. - * It is only called if visible is set to true. - */ - function () { - }; - Example.prototype.render = /** - * Pre-render is called right before the Game Renderer starts and before any custom preRender callbacks have been run. - * It is only called if visible is set to true. - */ - function () { - }; - Example.prototype.postRender = /** - * Post-render is called after every camera and game object has been rendered, also after any custom postRender callbacks have been run. - * It is only called if visible is set to true. - */ - function () { - }; - return Example; - })(Phaser.Plugin); - Plugins.Example = Example; - })(Phaser.Plugins || (Phaser.Plugins = {})); - var Plugins = Phaser.Plugins; -})(Phaser || (Phaser = {})); diff --git a/Plugins/Template.ts b/Plugins/Template.ts deleted file mode 100644 index 25aec63a..00000000 --- a/Plugins/Template.ts +++ /dev/null @@ -1,74 +0,0 @@ -/// -/// - -/** -* Phaser - Example Plugin -*/ - -module Phaser.Plugins { - - export class Example extends Phaser.Plugin { - - constructor(game: Phaser.Game, parent) { - - super(game, parent); - - this.active = true; - this.visible = true; - - this.hasPreUpdate = false; - this.hasUpdate = false; - this.hasPostUpdate = false; - - this.hasPreRender = false; - this.hasRender = false; - this.hasPostRender = false; - - } - - /** - * Pre-update is called at the start of the update cycle, before any other updates have taken place. - * It is only called if active is set to true. - */ - public preUpdate() { - } - - /** - * Pre-update is called at the start of the update cycle, after all the core system updates have taken place, but before the world update. - * It is only called if active is set to true. - */ - public update() { - } - - /** - * Post-update is called at the end of the objects update cycle, after other update logic has taken place. - * It is only called if active is set to true. - */ - public postUpdate() { - } - - /** - * Pre-render is called right before the Game Renderer starts and before any custom preRender callbacks have been run. - * It is only called if visible is set to true. - */ - public preRender() { - } - - /** - * Pre-render is called right before the Game Renderer starts and before any custom preRender callbacks have been run. - * It is only called if visible is set to true. - */ - public render() { - } - - /** - * Post-render is called after every camera and game object has been rendered, also after any custom postRender callbacks have been run. - * It is only called if visible is set to true. - */ - public postRender() { - } - - - } - -} diff --git a/Plugins/app.js.map b/Plugins/app.js.map deleted file mode 100644 index a0afef87..00000000 --- a/Plugins/app.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"app.js","sources":["app.ts"],"names":["Greeter","Greeter.constructor","Greeter.start","","Greeter.stop","onload"],"mappings":"AAAA;IAKIA,SALEA,OAAOA,CAKGA,OAAoBA;QAC5BC,IAAIA,CAACA,OAAOA,GAAGA,OAAOA;QACtBA,IAAIA,CAACA,OAAOA,CAACA,SAASA,IAAIA,eAAeA;QACzCA,IAAIA,CAACA,IAAIA,GAAGA,QAAQA,CAACA,aAAaA,CAACA,MAAMA,CAACA;QAC1CA,IAAIA,CAACA,OAAOA,CAACA,WAAWA,CAACA,IAAIA,CAACA,IAAIA,CAACA;QACnCA,IAAIA,CAACA,IAAIA,CAACA,SAASA,GAAGA,IAAIA,IAAIA,EAAEA,CAACA,WAAWA,EAAEA;IAClDA,CAACA;IAEDD,0BAAAA;QAAAE,iBAECA;QADGA,IAAIA,CAACA,UAAUA,GAAGA,WAAWA,CAACA;YAAMC,OAAAA,KAAIA,CAACA,IAAIA,CAACA,SAASA,GAAGA,IAAIA,IAAIA,EAAEA,CAACA,WAAWA,EAAEA,CAAAA;QAA9CA,CAA8CA,EAAED,GAAGA,CAACA;IAC5FA,CAACA;IAEDF,yBAAAA;QACII,YAAYA,CAACA,IAAIA,CAACA,UAAUA,CAACA;IACjCA,CAACA;IAELJ;AAACA,CAAAA,IAAA;AAED,MAAM,CAAC,MAAM,GAAG;IACZK,IAAIA,EAAEA,GAAGA,QAAQA,CAACA,cAAcA,CAACA,SAASA,CAACA,CAACA;IAC5CA,IAAIA,OAAOA,GAAGA,IAAIA,OAAOA,CAACA,EAAEA,CAACA,CAACA;IAC9BA,OAAOA,CAACA,KAAKA,EAAEA;AACnBA,CAACA"} \ No newline at end of file diff --git a/Plugins/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/Plugins/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache deleted file mode 100644 index 594d24c2ae1a9f2edacb2a57298a8a5a6b29fe2b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6226 zcmeHLZBrXJ5VpZ67($C_N)l)ir%l_uI5&2I@G`@PVB?l)VHn#(JHs(VzLRYQ-N_^A zFfPMy=`ZN?C$_tOIS3HfAM6=ESRSv>EA5L`E8U}wL?e;NztHd(+x;;h?k;zf)Usl% z1Fi!qiY9Qmw6fCkq`#BfP9+bR(p>tRnT(ajPb!%Wgb5Ve^jTmO6{+NYP!`vg8A0#!SHJuvzq2tTGm z$Od!YYt6i}Xl|bw=A&1721aM4U*Xj}7i`|4zRO)|Sa&3H^3je%*UeTU~qT zLw>u8CpY+4rIG^Xsm(Pvb6hdUNX40+t-FS*BBRQw?Nd|Jv(;;i>AI2?h!Dr2Zly|#Xo>gC5Bb#)kVI2vqN@3^{Xbd;jQ$f9sJ4MX`I`#pizPjBZo!_I;a=t z5rW(JIFPA$3?CpA4N$B7Y9} zvDS#M@X6C$kO%NI1-!JilwQiL$G?XE2@D*5$vhIP!F|sq2*hKSD+GDedSYiRfw9H- zk;g#Z_LyrH0H31yKkO~30AX7nHCX_WH~om@smoAc5d>0w2?(ldDDh3dUhQ(FWXr23 zAd>FKND=NDg8Q&CVCZSThKe=n$_9!&>vuLFa?+ZA5+r`;;aZ7#fUQky>~k1 + @@ -98,3 +99,5 @@ + + diff --git a/examples/stagecolor.php b/examples/stagecolor.php new file mode 100644 index 00000000..2e744126 --- /dev/null +++ b/examples/stagecolor.php @@ -0,0 +1,31 @@ + + + + phaser.js - a new beginning + + + + + + + + \ No newline at end of file diff --git a/src/core/Stage.js b/src/core/Stage.js index d4a28a11..fed5db15 100644 --- a/src/core/Stage.js +++ b/src/core/Stage.js @@ -92,8 +92,16 @@ Object.defineProperty(Phaser.Stage.prototype, "backgroundColor", { }, set: function (color) { - this._stage.setBackgroundColor(color); + this._backgroundColor = color; + + if (typeof color === 'string') + { + color = Phaser.Color.hexToRGB(color); + } + + this._stage.setBackgroundColor(color); + }, enumerable: true, diff --git a/src/utils/Color.js b/src/utils/Color.js new file mode 100644 index 00000000..47cb5d2b --- /dev/null +++ b/src/utils/Color.js @@ -0,0 +1,291 @@ +/** +* A collection of methods useful for manipulating and comparing colors. +* +* @class Color +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License +* @module Phaser +*/ + +Phaser.Color = { + + /** + * Given an alpha and 3 color values this will return an integer representation of it + * + * @method getColor32 + * @param {Number} alpha The Alpha value (between 0 and 255) + * @param {Number} red The Red channel value (between 0 and 255) + * @param {Number} green The Green channel value (between 0 and 255) + * @param {Number} blue The Blue channel value (between 0 and 255) + * @return {Number} A native color value integer (format: 0xAARRGGBB) + */ + getColor32: function (alpha, red, green, blue) { + return alpha << 24 | red << 16 | green << 8 | blue; + }, + + /** + * Given 3 color values this will return an integer representation of it. + * + * @method getColor + * @param {Number} red The Red channel value (between 0 and 255) + * @param {Number} green The Green channel value (between 0 and 255) + * @param {Number} blue The Blue channel value (between 0 and 255) + * @return {Number} A native color value integer (format: 0xRRGGBB) + */ + getColor: function (red, green, blue) { + return red << 16 | green << 8 | blue; + }, + + /** + * Converts the given hex string into an object containing the RGB values. + * + * @method hexToRGB + * @param {String} The string hex color to convert. + * @return {Object} An object with 3 properties: r,g and b. + */ + hexToRGB: function (h) { + + var hex16 = (h.charAt(0) == "#") ? h.substring(1, 7) : h; + var red = parseInt(hex16.substring(0, 2), 16); + var green = parseInt(hex16.substring(2, 4), 16); + var blue = parseInt(hex16.substring(4, 6), 16); + + return red << 16 | green << 8 | blue; + + }, + + /** + * Returns a string containing handy information about the given color including string hex value, + * RGB format information and HSL information. Each section starts on a newline, 3 lines in total. + * + * @method getColorInfo + * @param {Number} color A color value in the format 0xAARRGGBB + * @return {String} string containing the 3 lines of information + */ + getColorInfo: function (color) { + var argb = Phaser.Color.getRGB(color); + var hsl = Phaser.Color.RGBtoHSV(color); + // Hex format + var result = Phaser.Color.RGBtoHexstring(color) + "\n"; + // RGB format + result = result.concat("Alpha: " + argb.alpha + " Red: " + argb.red + " Green: " + argb.green + " Blue: " + argb.blue) + "\n"; + // HSL info + result = result.concat("Hue: " + hsl.hue + " Saturation: " + hsl.saturation + " Lightnes: " + hsl.lightness); + return result; + }, + + /** + * Return a string representation of the color in the format 0xAARRGGBB + * + * @method RGBtoHexstring + * @param {Number} color The color to get the string representation for + * @return {String A string of length 10 characters in the format 0xAARRGGBB + */ + RGBtoHexstring: function (color) { + var argb = Phaser.Color.getRGB(color); + return "0x" + Phaser.Color.colorToHexstring(argb.alpha) + Phaser.Color.colorToHexstring(argb.red) + Phaser.Color.colorToHexstring(argb.green) + Phaser.Color.colorToHexstring(argb.blue); + }, + + /** + * Return a string representation of the color in the format #RRGGBB + * + * @method RGBtoWebstring + * @param {Number} color The color to get the string representation for + * @return {String} A string of length 10 characters in the format 0xAARRGGBB + */ + RGBtoWebstring: function (color) { + var argb = Phaser.Color.getRGB(color); + return "#" + Phaser.Color.colorToHexstring(argb.red) + Phaser.Color.colorToHexstring(argb.green) + Phaser.Color.colorToHexstring(argb.blue); + }, + + /** + * Return a string containing a hex representation of the given color + * + * @method colorToHexstring + * @param {Number} color The color channel to get the hex value for, must be a value between 0 and 255) + * @return {String} A string of length 2 characters, i.e. 255 = FF, 0 = 00 + */ + colorToHexstring: function (color) { + var digits = "0123456789ABCDEF"; + var lsd = color % 16; + var msd = (color - lsd) / 16; + var hexified = digits.charAt(msd) + digits.charAt(lsd); + return hexified; + }, + + /** + * Interpolates the two given colours based on the supplied step and currentStep properties. + * @method interpolateColor + * @param {Number} color1 + * @param {Number} color2 + * @param {Number} steps + * @param {Number} currentStep + * @param {Number} alpha + * @return {Number} The interpolated color value. + */ + interpolateColor: function (color1, color2, steps, currentStep, alpha) { + if (typeof alpha === "undefined") { alpha = 255; } + var src1 = Phaser.Color.getRGB(color1); + var src2 = Phaser.Color.getRGB(color2); + var r = (((src2.red - src1.red) * currentStep) / steps) + src1.red; + var g = (((src2.green - src1.green) * currentStep) / steps) + src1.green; + var b = (((src2.blue - src1.blue) * currentStep) / steps) + src1.blue; + return Phaser.Color.getColor32(alpha, r, g, b); + }, + + /** + * Interpolates the two given colours based on the supplied step and currentStep properties. + * @method interpolateColorWithRGB + * @param {Number} color + * @param {Number} r + * @param {Number} g + * @param {Number} b + * @param {Number} steps + * @param {Number} currentStep + * @return {Number} The interpolated color value. + */ + interpolateColorWithRGB: function (color, r, g, b, steps, currentStep) { + var src = Phaser.Color.getRGB(color); + var or = (((r - src.red) * currentStep) / steps) + src.red; + var og = (((g - src.green) * currentStep) / steps) + src.green; + var ob = (((b - src.blue) * currentStep) / steps) + src.blue; + return Phaser.Color.getColor(or, og, ob); + }, + + /** + * Interpolates the two given colours based on the supplied step and currentStep properties. + * @method interpolateRGB + * @param {Number} r1 + * @param {Number} g1 + * @param {Number} b1 + * @param {Number} r2 + * @param {Number} g2 + * @param {Number} b2 + * @param {Number} steps + * @param {Number} currentStep + * @return {Number} The interpolated color value. + */ + interpolateRGB: function (r1, g1, b1, r2, g2, b2, steps, currentStep) { + var r = (((r2 - r1) * currentStep) / steps) + r1; + var g = (((g2 - g1) * currentStep) / steps) + g1; + var b = (((b2 - b1) * currentStep) / steps) + b1; + return Phaser.Color.getColor(r, g, b); + }, + + /** + * Returns a random color value between black and white + *

Set the min value to start each channel from the given offset.

+ *

Set the max value to restrict the maximum color used per channel

+ * + * @method getRandomColor + * @param {Number} min The lowest value to use for the color + * @param {Number} max The highest value to use for the color + * @param {Number} alpha The alpha value of the returning color (default 255 = fully opaque) + * @return {Number} 32-bit color value with alpha + */ + getRandomColor: function (min, max, alpha) { + if (typeof min === "undefined") { min = 0; } + if (typeof max === "undefined") { max = 255; } + if (typeof alpha === "undefined") { alpha = 255; } + // Sanity checks + if(max > 255) { + return Phaser.Color.getColor(255, 255, 255); + } + if(min > max) { + return Phaser.Color.getColor(255, 255, 255); + } + var red = min + Math.round(Math.random() * (max - min)); + var green = min + Math.round(Math.random() * (max - min)); + var blue = min + Math.round(Math.random() * (max - min)); + return Phaser.Color.getColor32(alpha, red, green, blue); + }, + + /** + * Return the component parts of a color as an Object with the properties alpha, red, green, blue + * + *

Alpha will only be set if it exist in the given color (0xAARRGGBB)

+ * + * @method getRGB + * @param {Number} color in RGB (0xRRGGBB) or ARGB format (0xAARRGGBB) + * @return {Object} An Object with properties: alpha, red, green, blue + */ + getRGB: function (color) { + return { + alpha: color >>> 24, + red: color >> 16 & 0xFF, + green: color >> 8 & 0xFF, + blue: color & 0xFF + }; + }, + + /** + * Returns a CSS friendly string value from the given color. + * @method getWebRGB + * @param {Number} color + * @return {String} A string in the format: 'rgba(r,g,b,a)' + */ + getWebRGB: function (color) { + var alpha = (color >>> 24) / 255; + var red = color >> 16 & 0xFF; + var green = color >> 8 & 0xFF; + var blue = color & 0xFF; + return 'rgba(' + red.toString() + ',' + green.toString() + ',' + blue.toString() + ',' + alpha.toString() + ')'; + }, + + /** + * Given a native color value (in the format 0xAARRGGBB) this will return the Alpha component, as a value between 0 and 255 + * + * @method getAlpha + * @param {Number} color In the format 0xAARRGGBB + * @return {Number} The Alpha component of the color, will be between 0 and 1 (0 being no Alpha (opaque), 1 full Alpha (transparent)) + */ + getAlpha: function (color) { + return color >>> 24; + }, + + /** + * Given a native color value (in the format 0xAARRGGBB) this will return the Alpha component as a value between 0 and 1 + * + * @method getAlphaFloat + * @param {Number} color In the format 0xAARRGGBB + * @return {Number} The Alpha component of the color, will be between 0 and 1 (0 being no Alpha (opaque), 1 full Alpha (transparent)) + */ + getAlphaFloat: function (color) { + return (color >>> 24) / 255; + }, + + /** + * Given a native color value (in the format 0xAARRGGBB) this will return the Red component, as a value between 0 and 255 + * + * @method getRed + * @param {Number} color In the format 0xAARRGGBB + * @return {Number} The Red component of the color, will be between 0 and 255 (0 being no color, 255 full Red) + */ + getRed: function (color) { + return color >> 16 & 0xFF; + }, + + /** + * Given a native color value (in the format 0xAARRGGBB) this will return the Green component, as a value between 0 and 255 + * + * @method getGreen + * @param {Number} color In the format 0xAARRGGBB + * @return {Number} The Green component of the color, will be between 0 and 255 (0 being no color, 255 full Green) + */ + getGreen: function (color) { + return color >> 8 & 0xFF; + }, + + /** + * Given a native color value (in the format 0xAARRGGBB) this will return the Blue component, as a value between 0 and 255 + * + * @method getBlue + * @param {Number} color In the format 0xAARRGGBB + * @return {Number} The Blue component of the color, will be between 0 and 255 (0 being no color, 255 full Blue) + */ + getBlue: function (color) { + return color & 0xFF; + } + +}; diff --git a/Plugins/CameraFX/Border.js b/todo/CameraFX/Border.js similarity index 100% rename from Plugins/CameraFX/Border.js rename to todo/CameraFX/Border.js diff --git a/Plugins/CameraFX/Border.ts b/todo/CameraFX/Border.ts similarity index 100% rename from Plugins/CameraFX/Border.ts rename to todo/CameraFX/Border.ts diff --git a/Plugins/CameraFX/Fade.js b/todo/CameraFX/Fade.js similarity index 100% rename from Plugins/CameraFX/Fade.js rename to todo/CameraFX/Fade.js diff --git a/Plugins/CameraFX/Fade.ts b/todo/CameraFX/Fade.ts similarity index 100% rename from Plugins/CameraFX/Fade.ts rename to todo/CameraFX/Fade.ts diff --git a/Plugins/CameraFX/Flash.js b/todo/CameraFX/Flash.js similarity index 100% rename from Plugins/CameraFX/Flash.js rename to todo/CameraFX/Flash.js diff --git a/Plugins/CameraFX/Flash.ts b/todo/CameraFX/Flash.ts similarity index 100% rename from Plugins/CameraFX/Flash.ts rename to todo/CameraFX/Flash.ts diff --git a/Plugins/CameraFX/Mirror.js b/todo/CameraFX/Mirror.js similarity index 100% rename from Plugins/CameraFX/Mirror.js rename to todo/CameraFX/Mirror.js diff --git a/Plugins/CameraFX/Mirror.ts b/todo/CameraFX/Mirror.ts similarity index 100% rename from Plugins/CameraFX/Mirror.ts rename to todo/CameraFX/Mirror.ts diff --git a/Plugins/CameraFX/Scanlines.js b/todo/CameraFX/Scanlines.js similarity index 100% rename from Plugins/CameraFX/Scanlines.js rename to todo/CameraFX/Scanlines.js diff --git a/Plugins/CameraFX/Scanlines.ts b/todo/CameraFX/Scanlines.ts similarity index 100% rename from Plugins/CameraFX/Scanlines.ts rename to todo/CameraFX/Scanlines.ts diff --git a/Plugins/CameraFX/Shadow.js b/todo/CameraFX/Shadow.js similarity index 100% rename from Plugins/CameraFX/Shadow.js rename to todo/CameraFX/Shadow.js diff --git a/Plugins/CameraFX/Shadow.ts b/todo/CameraFX/Shadow.ts similarity index 100% rename from Plugins/CameraFX/Shadow.ts rename to todo/CameraFX/Shadow.ts diff --git a/Plugins/CameraFX/Shake.js b/todo/CameraFX/Shake.js similarity index 100% rename from Plugins/CameraFX/Shake.js rename to todo/CameraFX/Shake.js diff --git a/Plugins/CameraFX/Shake.ts b/todo/CameraFX/Shake.ts similarity index 100% rename from Plugins/CameraFX/Shake.ts rename to todo/CameraFX/Shake.ts diff --git a/Plugins/verlet/AngleConstraint.js b/todo/verlet/AngleConstraint.js similarity index 100% rename from Plugins/verlet/AngleConstraint.js rename to todo/verlet/AngleConstraint.js diff --git a/Plugins/verlet/AngleConstraint.js.map b/todo/verlet/AngleConstraint.js.map similarity index 100% rename from Plugins/verlet/AngleConstraint.js.map rename to todo/verlet/AngleConstraint.js.map diff --git a/Plugins/verlet/AngleConstraint.ts b/todo/verlet/AngleConstraint.ts similarity index 100% rename from Plugins/verlet/AngleConstraint.ts rename to todo/verlet/AngleConstraint.ts diff --git a/Plugins/verlet/Composite.js b/todo/verlet/Composite.js similarity index 100% rename from Plugins/verlet/Composite.js rename to todo/verlet/Composite.js diff --git a/Plugins/verlet/Composite.ts b/todo/verlet/Composite.ts similarity index 100% rename from Plugins/verlet/Composite.ts rename to todo/verlet/Composite.ts diff --git a/Plugins/verlet/DistanceConstraint.js b/todo/verlet/DistanceConstraint.js similarity index 100% rename from Plugins/verlet/DistanceConstraint.js rename to todo/verlet/DistanceConstraint.js diff --git a/Plugins/verlet/DistanceConstraint.ts b/todo/verlet/DistanceConstraint.ts similarity index 100% rename from Plugins/verlet/DistanceConstraint.ts rename to todo/verlet/DistanceConstraint.ts diff --git a/Plugins/verlet/Particle.js b/todo/verlet/Particle.js similarity index 100% rename from Plugins/verlet/Particle.js rename to todo/verlet/Particle.js diff --git a/Plugins/verlet/Particle.js.map b/todo/verlet/Particle.js.map similarity index 100% rename from Plugins/verlet/Particle.js.map rename to todo/verlet/Particle.js.map diff --git a/Plugins/verlet/Particle.ts b/todo/verlet/Particle.ts similarity index 100% rename from Plugins/verlet/Particle.ts rename to todo/verlet/Particle.ts diff --git a/Plugins/verlet/PinConstraint.js b/todo/verlet/PinConstraint.js similarity index 100% rename from Plugins/verlet/PinConstraint.js rename to todo/verlet/PinConstraint.js diff --git a/Plugins/verlet/PinConstraint.ts b/todo/verlet/PinConstraint.ts similarity index 100% rename from Plugins/verlet/PinConstraint.ts rename to todo/verlet/PinConstraint.ts diff --git a/Plugins/verlet/VerletManager.js b/todo/verlet/VerletManager.js similarity index 100% rename from Plugins/verlet/VerletManager.js rename to todo/verlet/VerletManager.js diff --git a/Plugins/verlet/VerletManager.ts b/todo/verlet/VerletManager.ts similarity index 100% rename from Plugins/verlet/VerletManager.ts rename to todo/verlet/VerletManager.ts