Skip to content

Commit aec06f1

Browse files
committed
Added ColorSpectrum function
1 parent b97536f commit aec06f1

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

src/display/color/ColorSpectrum.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2020 Photon Storm Ltd.
4+
* @license {@link https://opensource.org/licenses/MIT|MIT License}
5+
*/
6+
7+
var GetColor = require('./GetColor');
8+
9+
/**
10+
* Return an array of Colors in a Color Spectrum.
11+
*
12+
* @function Phaser.Display.Color.ColorSpectrum
13+
* @since 3.50.0
14+
*
15+
* @return {Phaser.Types.Display.ColorObject[]} An array containing 1024 elements, where each contains a Color Object.
16+
*/
17+
var ColorSpectrum = function ()
18+
{
19+
var colors = [];
20+
21+
var range = 255;
22+
23+
var i;
24+
var r = 255;
25+
var g = 0;
26+
var b = 0;
27+
28+
// Red to Yellow
29+
for (i = 0; i <= range; i++)
30+
{
31+
colors.push({ r: r, g: i, b: b, color: GetColor(r, i, b) });
32+
}
33+
34+
g = 255;
35+
36+
// Yellow to Green
37+
for (i = range; i >= 0; i--)
38+
{
39+
colors.push({ r: i, g: g, b: b, color: GetColor(i, g, b) });
40+
}
41+
42+
r = 0;
43+
44+
// Green to Blue
45+
for (i = 0; i <= range; i++, g--)
46+
{
47+
colors.push({ r: r, g: g, b: i, color: GetColor(r, g, i) });
48+
}
49+
50+
g = 0;
51+
b = 255;
52+
53+
// Blue to Red
54+
for (i = 0; i <= range; i++, b--, r++)
55+
{
56+
colors.push({ r: r, g: g, b: b, color: GetColor(r, g, b) });
57+
}
58+
59+
return colors;
60+
};
61+
62+
module.exports = ColorSpectrum;

src/display/color/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
var Color = require('./Color');
88

9+
Color.ColorSpectrum = require('./ColorSpectrum');
910
Color.ColorToRGBA = require('./ColorToRGBA');
1011
Color.ComponentToHex = require('./ComponentToHex');
1112
Color.GetColor = require('./GetColor');

0 commit comments

Comments
 (0)