一,生成数组形式
var colors = [];
// 生成随机颜色
for (var i = 0; i < 20; i++) {
colors.push(
[
'rgba( ' +
(Math.random() * 255 >> 0) + ',' +
(Math.random() * 255 >> 0) + ',' +
(Math.random() * 255 >> 0) + ',' + 1 +
' )',
'rgba( ' +
(Math.random() * 255 >> 0) + ',' +
(Math.random() * 255 >> 0) + ',' +
(Math.random() * 255 >> 0) + ',' + .7 +
' )'
]
);
}
console.log(colors);
二 生成数组对象形式
var colors = [];
// 生成随机颜色
for (var i = 0; i < 20; i++) {
colors.push(
{
colorStart: '(' + (Math.random() * 255 >> 0) + ',' +
(Math.random() * 255 >> 0) + ',' +
(Math.random() * 255 >> 0) + ',' + 1 +
' )',
colorEnd: '(' + (Math.random() * 255 >> 0) + ',' +
(Math.random() * 255 >> 0) + ',' +
(Math.random() * 255 >> 0) + ',' + .7 +
' )'
}
);
}
console.log(colors);