渐变色值 发表于 2019-01-27 rgb to hex1234function rgbToHex(r, g, b) { var hex = ((r<<16) | (g<<8) | b).toString(16); return "#" + new Array(Math.abs(hex.length-7)).join("0") + hex;} hex to rgb1234567function hexToRgb(hex) { var rgb = []; for(var i=1; i<7; i+=2){ rgb.push(parseInt("0x" + hex.slice(i,i+2))); } return rgb;} 123456789101112131415let ratio = Math.random();let i = 100;let colorList = [];function getGradientColor(ratio) { let r = Math.cos(ratio) * 127 + 128; let g = Math.cos(ratio + 2 * Math.PI / 3) * 127 + 128; let b = Math.cos(ratio + 4 * Math.PI / 3) * 127 + 128; return '#' + (r << 16 | g << 8 | b).toString(16);}while (i--) { colorList.push(getGradientColor(ratio)); ratio += Math.PI * 2 / 50;}