|
| 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; |
0 commit comments