RGB to HSV The R,G,B values are divided by 255 to change the range from 0..255 to 0..1: R' = R/255 G' = G/255 B' = B/255 Cmax = max(R', G', B') Cmin = min(R', G', B') Δ = Cmax - Cmin Hue calculation: Saturation calculation: Value calculation: V = Cma
The RGB color model is an additive system in which each color is defined by the amount of red, green, and blue light emitted. In the RGB scheme, colors are represented numerically with a set of three numbers, each of which ranges from 0 to 255. White
以原型的方式,给string字符串类型添加方法,用于实现颜色值格式的转换:不习惯使用原型方法的,只要借鉴实现方法就好! 代码如下: var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/; /*RGB颜色转换为16进制*/ String.prototype.colorHex = function(){ var that = this; if(/^(rgb|RGB)/.test(that)){ var aColor = that.replace(/(?:\(|