Unity 8
Gradient.js
1 /*
2  * Copyright (C) 2013 Canonical, Ltd.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 3.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 function threeColorByIndex(index, total, colors) {
18  var red, green, blue;
19  var p = 0.0;
20 
21  if(total > 0) {
22  p = index / total;
23  }
24 
25  if (p < 0.5) {
26  red = (colors.main.r * p * 2.0) + colors.start.r * (0.5 - p) * 2.0;
27  green = (colors.main.g * p * 2.0) + colors.start.g * (0.5 - p) * 2.0;
28  blue = (colors.main.b * p * 2.0) + colors.start.b * (0.5 - p) * 2.0;
29  } else {
30  red = colors.end.r * (p - 0.5) * 2.0 + colors.main.r * (1.0 - p) * 2.0;
31  green = colors.end.g * (p - 0.5) * 2.0 + colors.main.g * (1.0 - p) * 2.0;
32  blue = colors.end.b * (p - 0.5) * 2.0 + colors.main.b * (1.0 - p) * 2.0;
33  }
34 
35  return Qt.rgba(red, green, blue, 1);
36 }