/* * 想构造一系列平滑过渡的颜色,用HSV颜色空间容易,用RGB较难。 * * 将色彩由HSV空间转换到RGB空间 * * h 颜色 用角度表示,范围:0到360度 * s 色度 0.0到1.0 0为白色,越高颜色越“纯” * v 亮度 0.0到1.0 0为黑色,越高越亮 */ Color HSVtoRGB(float h /* 0~360 degrees */, float s /* 0 ~ 1.0 */, float v /* 0 ~ 1.0 */ ) { float f, p, q, t; if( s == 0 ) { // achromatic (grey) return makeColor(v,v,v); } h /= 60; // sector 0 to 5 int i = (int) Math.floor( h ); f = h - i; // factorial part of h p = v * ( 1 - s ); q = v * ( 1 - s * f ); t = v * ( 1 - s * ( 1 - f ) ); switch( i ) { case 0: return makeColor(v,t,p); case 1: return makeColor(q,v,p); case 2: return makeColor(p,v,t); case 3: return makeColor(p,q,v); case 4: return makeColor(t,p,v); default: // case 5: return makeColor(v,p,q); } }
HSV色彩转RGB(JAVA版)
最新推荐文章于 2022-05-07 16:29:18 发布