1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > [js] 颜色渐变算法

[js] 颜色渐变算法

时间:2019-07-25 12:38:00

相关推荐

[js] 颜色渐变算法

给定一组数据,给定渐变颜色两端的颜色值,需要根据这组数据中的每个值大小为其分配一个颜色

/pozhu15/p/11951320.html

// 颜色,根据数值均分gerColorOfWeight1(minNum, maxNum, colorStart, colorend, number) {console.log(55, minNum, maxNum, colorStart, colorend, number);const colorR =((colorend.red - colorStart.red) * (number - minNum)) / (maxNum - minNum) + colorStart.red;console.log(22, colorR);const colorG =((colorend.green - colorStart.green) * (number - minNum)) / (maxNum - minNum) +colorStart.green;console.log(223, colorG);const colorB =((colorend.blue - colorStart.blue) * (number - minNum)) / (maxNum - minNum) +colorStart.blue;console.log(2233, colorB);const color = `rgb(${parseInt(colorR).toString()},${parseInt(colorG).toString()},${parseInt(colorB).toString()})`;// #color=getColorstr((int(colorR),int(colorG),int(colorB)))#转换为16进制颜色return color;},

const colorStart = {red: 218, green: 195, blue: 255 };const colorend = {red: 172, green: 90, blue: 255 };const weightlist = [2, 30, 56, 12, 4, 62]const number = 12const mycolor = this.gerColorOfWeight1(Math.min.apply(null, weightlist), Math.max.apply(null, weightlist), colorStart, colorend, number)console.log(mycolor); //'rgb(210,177,255)'

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。