css color to webgl color

webgl中所使用的颜色值域为0~1,超出1的部分则自动截取为1
css中的颜色值域为0~255
因为同为RGB颜色,所以转换方法为 颜色值/255 一般取两位小数即可,需要更精准则取更多小数

js做简单的数值转换

1
2
3
4
5
6
7
8
9
const t = (d, h = 3) => {
return d.map( d => Math.floor(d / 255 * Math.pow(10, h)) / Math.pow(10, h) );
}

// test

t([0,25,97]);

// output: [0, 0.098, 0.38]
#

Comments

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×