Skip to content

Commit 27d62aa

Browse files
committed
Color.HSVColorWheel will return an array with 360 color objects for each segment of an HSV color wheel.
1 parent 65022cc commit 27d62aa

3 files changed

Lines changed: 34 additions & 125 deletions

File tree

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,11 @@ Version 2.0.4 - "Mos Shirare" - in development
9393
* InputManager.resetLocked - If the Input Manager has been reset locked then all calls made to InputManager.reset, such as from a State change, are ignored.
9494
* Group.resetCursor will reset the Group cursor back to the start of the group, or to the given index value.
9595
* World.wrap will take a game object and if its x/y coordinates fall outside of the world bounds it will be repositioned on the opposite side, for a wrap-around effect.
96-
* Group.classType allows you to change the type of object that Group.create or createMultiple makes to your own custom class.
96+
* Group.classType allows you to change the type of object that Group.create or createMultiple makes from Phaser.Sprite to your own custom class.
9797
* Game.scratch is a single handy BitmapData instance that can be used as a visual scratch-pad, for off-screen bitmap manipulation (and is used as such by BitmapData itself).
9898
* Device.support32bit is a new boolean that sets if the context supports 32bit pixel manipulation using array buffer views or not.
9999
* BitmapData.processPixelRGB lets you perform a custom callback on every pixel in the BitmapData.
100+
100101
* P2.World now has its own pause and resume methods, so you can pause the physics simulation independent of your game (thanks @georgiee)
101102
* Phaser.ArrayList is a new iterative object, similar in principal to a linked list but operating on a single array without modifying the object structure.
102103
* Add scaleMode params to FilterTexture and RenderTexture (pixi.js update by @giraluna)
@@ -116,6 +117,17 @@ Version 2.0.4 - "Mos Shirare" - in development
116117
* Point.interpolate - Interpolates the two given Points, based on the `f` value (between 0 and 1) and returns a new Point.
117118
* Your State can now have a pauseUpdate method, which is called constantly when the game is paused.
118119
* The Input system is now updated even while the game is paused.
120+
* Color.packPixel packs an rgb component into a single integer.
121+
* Color.unpackPixel unpacks an integer into a color object.
122+
* Color.fromRGBA converts an integer in 0xRRGGBBAA format to a color object.
123+
* Color.toRGBA converts rgba components into a 32-bit integer.
124+
* Color.RGBtoHSL converts an rgb color into hsl (hue, saturation, lightness)
125+
* Color.HSLtoRGB converts hsl values into an rgb color object.
126+
* Color.RGBtoHSV converts an rgb color into hsv (hue, saturation, value)
127+
* Color.HSVtoRGB converts an hsv value into an rgb color object.
128+
* Color.createColor - creates the new light-weight color object used by most Color conversion methods.
129+
* Color.RGBtoString converts an rgba color into a # or 0x color string.
130+
* Color.HSVColorWheel will return an array with 360 color objects for each segment of an HSV color wheel.
119131

120132

121133
### Bug Fixes

plugins/ColorHarmony.js

Lines changed: 0 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -103,130 +103,6 @@ Phaser.Plugins.ColorHarmony.prototype = {
103103
color2: Phaser.Color.HSVtoRGB(triadic1, 1.0, 1.0),
104104
color3: Phaser.Color.HSVtoRGB(triadic2, 1.0, 1.0)
105105
};
106-
},
107-
108-
/**
109-
* Get HSV color wheel values in an array which will be 360 elements in size.
110-
*
111-
* @method getHSVColorWheel
112-
* @param {Number} alpha Alpha value for each color of the color wheel, between 0 (transparent) and 255 (opaque)
113-
* @return {Array} An array containing 360 elements corresponding to the HSV color wheel.
114-
*/
115-
getHSVColorWheel: function (alpha) {
116-
117-
alpha = alpha || 255;
118-
119-
var colors = [];
120-
121-
for (var c = 0; c <= 359; c++)
122-
{
123-
colors[c] = Phaser.Color.getWebRGB(Phaser.Color.HSVtoRGB(c, 1.0, 1.0, alpha));
124-
}
125-
126-
return colors;
127-
},
128-
129-
/**
130-
* Convert a HSV (hue, saturation, lightness) color space value to an RGB color
131-
*
132-
* @method HSVtoRGB
133-
* @param {Number} h Hue degree, between 0 and 359
134-
* @param {Number} s Saturation, between 0.0 (grey) and 1.0
135-
* @param {Number} v Value, between 0.0 (black) and 1.0
136-
* @param {Number} alpha Alpha value to set per color (between 0 and 255)
137-
* @return {Number} 32-bit ARGB color value (0xAARRGGBB)
138-
*/
139-
HSVtoRGB: function (h, s, v, alpha) {
140-
if (typeof alpha === "undefined") { alpha = 255; }
141-
var result;
142-
if(s === 0.0) {
143-
result = Phaser.Color.getColor32(alpha, v * 255, v * 255, v * 255);
144-
} else {
145-
h = h / 60.0;
146-
var f = h - Math.floor(h);
147-
var p = v * (1.0 - s);
148-
var q = v * (1.0 - s * f);
149-
var t = v * (1.0 - s * (1.0 - f));
150-
switch(Math.floor(h)) {
151-
case 0:
152-
result = Phaser.Color.getColor32(alpha, v * 255, t * 255, p * 255);
153-
break;
154-
case 1:
155-
result = Phaser.Color.getColor32(alpha, q * 255, v * 255, p * 255);
156-
break;
157-
case 2:
158-
result = Phaser.Color.getColor32(alpha, p * 255, v * 255, t * 255);
159-
break;
160-
case 3:
161-
result = Phaser.Color.getColor32(alpha, p * 255, q * 255, v * 255);
162-
break;
163-
case 4:
164-
result = Phaser.Color.getColor32(alpha, t * 255, p * 255, v * 255);
165-
break;
166-
case 5:
167-
result = Phaser.Color.getColor32(alpha, v * 255, p * 255, q * 255);
168-
break;
169-
default:
170-
throw new Error("Phaser.Color.HSVtoRGB : Unknown color");
171-
}
172-
}
173-
return result;
174-
},
175-
176-
/**
177-
* Convert an RGB color value to an object containing the HSV color space values: Hue, Saturation and Lightness
178-
*
179-
* @method RGBtoHSV
180-
* @param {Number} color In format 0xRRGGBB
181-
* @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)
182-
*/
183-
RGBtoHSV: function (color) {
184-
var rgb = Phaser.Color.getRGB(color);
185-
var red = rgb.red / 255;
186-
var green = rgb.green / 255;
187-
var blue = rgb.blue / 255;
188-
var min = Math.min(red, green, blue);
189-
var max = Math.max(red, green, blue);
190-
var delta = max - min;
191-
var lightness = (max + min) / 2;
192-
var hue;
193-
var saturation;
194-
// Grey color, no chroma
195-
if(delta === 0) {
196-
hue = 0;
197-
saturation = 0;
198-
} else {
199-
if(lightness < 0.5) {
200-
saturation = delta / (max + min);
201-
} else {
202-
saturation = delta / (2 - max - min);
203-
}
204-
var delta_r = (((max - red) / 6) + (delta / 2)) / delta;
205-
var delta_g = (((max - green) / 6) + (delta / 2)) / delta;
206-
var delta_b = (((max - blue) / 6) + (delta / 2)) / delta;
207-
if(red == max) {
208-
hue = delta_b - delta_g;
209-
} else if(green == max) {
210-
hue = (1 / 3) + delta_r - delta_b;
211-
} else if(blue == max) {
212-
hue = (2 / 3) + delta_g - delta_r;
213-
}
214-
if(hue < 0) {
215-
hue += 1;
216-
}
217-
if(hue > 1) {
218-
hue -= 1;
219-
}
220-
}
221-
// Keep the value with 0 to 359
222-
hue *= 360;
223-
hue = Math.round(hue);
224-
return {
225-
hue: hue,
226-
saturation: saturation,
227-
lightness: lightness,
228-
value: lightness
229-
};
230106
}
231107

232108
};

src/utils/Color.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,29 @@ Phaser.Color = {
574574

575575
},
576576

577+
/**
578+
* Get HSV color wheel values in an array which will be 360 elements in size.
579+
*
580+
* @method Phaser.Color.HSVColorWheel
581+
* @static
582+
* @return {array} An array containing 360 elements corresponding to the HSV color wheel.
583+
*/
584+
HSVColorWheel: function () {
585+
586+
var colors = [];
587+
588+
for (var c = 0; c <= 359; c++)
589+
{
590+
colors[c] = Phaser.Color.HSVtoRGB(c, 1.0, 1.0);
591+
}
592+
593+
return colors;
594+
595+
},
596+
577597
/**
578598
* Interpolates the two given colours based on the supplied step and currentStep properties.
599+
*
579600
* @method Phaser.Color.interpolateColor
580601
* @static
581602
* @param {number} color1 - The first color value.

0 commit comments

Comments
 (0)