/
gradient.js
65 lines (42 loc) · 1.71 KB
/
gradient.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create });
function preload() {
// game.load.image('hotdog', 'assets/sprites/hotdog.png');
}
function create() {
game.stage.backgroundColor = "#0c9fc7";
/**
* Interpolates the two given colours based on the supplied step and currentStep properties.
*
* @method Phaser.Color.interpolateColor
* @static
* @param {number} color1 - The first color value.
* @param {number} color2 - The second color value.
* @param {number} steps - The number of steps to run the interpolation over.
* @param {number} currentStep - The currentStep value. If the interpolation will take 100 steps, a currentStep value of 50 would be half-way between the two.
* @param {number} alpha - The alpha of the returned color.
* @returns {number} The interpolated color value.
*/
// interpolateColor: function (color1, color2, steps, currentStep, alpha) {
var out = [];
var bmd = game.add.bitmapData(800, 600);
bmd.addToWorld();
var y = 0;
for (var i = 0; i < 30; i++)
{
var c = Phaser.Color.interpolateColor(0x66d973, 0x40b54d, 30, i);
// console.log(Phaser.Color.getWebRGB(c));
bmd.rect(0, y, 800, y+2, Phaser.Color.getWebRGB(c));
out.push(Phaser.Color.getWebRGB(c));
y += 2;
}
for (var i = 0; i < 60; i++)
{
var c = Phaser.Color.interpolateColor(0x40b54d, 0x1d962b, 60, i);
// console.log(Phaser.Color.getWebRGB(c));
bmd.rect(0, y, 800, y+2, Phaser.Color.getWebRGB(c));
out.push(Phaser.Color.getWebRGB(c));
y += 2;
}
// console.log(out);
console.log(JSON.stringify(out));
}