如何实现RGB颜色线性渐变
我需要根据变量的属性值设置其不同的颜色,通过RGB控制颜色,颜色是由蓝,绿,黄,红平滑渐变的,哪位大侠能告诉我该如何实现?
2013-08-01 09:28
2013-08-12 22:46
程序代码:for循环中:
var speed = arrList1[i][j];
var col, r, g, b;
if (speed > 2 && speed < 8) {
col = speed - 3;
r = 0;
g = Math.round(col * 51);
b = 255;
}
else if (speed >= 8 && speed < 13) {
col = speed - 8;
r = 0;
g = 255;
b = Math.round(255 - col * 51);
}
else if (speed >= 13 && speed < 18) {
col = speed - 13;
r = Math.round(col * 51);
g = 255;
b = 0;
}
else if (speed >= 18 && speed < 23) {
col = speed - 18;
r = 255;
g = Math.round(255 - col * 51);
b = 0;
}
else {
r = 255;
g = 0;
b = 0;
}r,g,b作为参数传进去分别作为RGB( R,G,B)的变量
2013-08-14 22:13