“FlashPlatform Algorithm RGB2HSL”的版本间的差异
来自Blueidea
(以内容“Category:FlashPlatform Algorithm”创建新页面) |
|||
第1行: | 第1行: | ||
[[Category:FlashPlatform Algorithm]] | [[Category:FlashPlatform Algorithm]] | ||
+ | |||
+ | ==RGBColor== | ||
+ | <syntaxhighlight lang="actionscript"> | ||
+ | package starpulse.geom { | ||
+ | /** | ||
+ | * RGB色彩。 | ||
+ | */ | ||
+ | public class RGBColor { | ||
+ | //========================================================================== | ||
+ | // Constructor | ||
+ | //========================================================================== | ||
+ | /** | ||
+ | * RGB色彩。 | ||
+ | * @param r Number - red value [0-255] | ||
+ | * @param g Number - green value [0-255] | ||
+ | * @param b Number - blue value [0-255] | ||
+ | */ | ||
+ | public function RGBColor(r:uint = 255, g:uint = 255, b:uint = 255, a:uint = 255) { | ||
+ | $a = a; | ||
+ | $r = r; | ||
+ | $g = g; | ||
+ | $b = b; | ||
+ | } | ||
+ | //========================================================================== | ||
+ | // Properties | ||
+ | //========================================================================== | ||
+ | private var $a:uint; | ||
+ | private var $r:uint; | ||
+ | private var $g:uint; | ||
+ | private var $b:uint; | ||
+ | //========================================================================== | ||
+ | // Public accessors | ||
+ | //========================================================================== | ||
+ | /** | ||
+ | * @private | ||
+ | */ | ||
+ | public function set alpha(value:uint):void { | ||
+ | $a = value; | ||
+ | } | ||
+ | /** | ||
+ | * 透明通道。 | ||
+ | */ | ||
+ | public function get alpha():uint { | ||
+ | return $a; | ||
+ | } | ||
+ | /** | ||
+ | * @private | ||
+ | */ | ||
+ | public function set red(value:uint):void { | ||
+ | $r = value; | ||
+ | } | ||
+ | /** | ||
+ | * 紅色通道。 | ||
+ | */ | ||
+ | public function get red():uint { | ||
+ | return $r; | ||
+ | } | ||
+ | /** | ||
+ | * @private | ||
+ | */ | ||
+ | public function set green(value:uint):void { | ||
+ | $g = value; | ||
+ | } | ||
+ | /** | ||
+ | * 綠色通道。 | ||
+ | */ | ||
+ | public function get green():uint { | ||
+ | return $g; | ||
+ | } | ||
+ | /** | ||
+ | * @private | ||
+ | */ | ||
+ | public function set blue(value:uint):void { | ||
+ | $b = value; | ||
+ | } | ||
+ | /** | ||
+ | * 蓝色通道。 | ||
+ | */ | ||
+ | public function get blue():uint { | ||
+ | return $b; | ||
+ | } | ||
+ | /** | ||
+ | * @private | ||
+ | */ | ||
+ | public function set value(v:uint):void { | ||
+ | $a = 255; | ||
+ | $r = (v >>> 16 << 16) >>> 16; | ||
+ | $g = ((v >>> 8 << 8) - ($r << 16)) >>> 8; | ||
+ | $b = ((v >>> 0 << 0) - ($r << 16) - ($g << 8)) >>> 0; | ||
+ | } | ||
+ | /** | ||
+ | * 無透明通道顏色值。 | ||
+ | */ | ||
+ | public function get value():uint { | ||
+ | const R1:uint = $r >= 16 ? $r / 16 : 0; | ||
+ | const R2:uint = $r >= 16 ? $r % 16 : $r; | ||
+ | const G1:uint = $g >= 16 ? $g / 16 : 0; | ||
+ | const G2:uint = $g >= 16 ? $g % 16 : $g; | ||
+ | const B1:uint = $b >= 16 ? $b / 16 : 0; | ||
+ | const B2:uint = $b >= 16 ? $b % 16 : $b; | ||
+ | return (R1 << 20) + (R2 << 16) + | ||
+ | (G1 << 12) + (G2 << 8) + (B1 << 4) + (B2 << 0); | ||
+ | } | ||
+ | /** | ||
+ | * @private | ||
+ | */ | ||
+ | public function set value32(v:uint):void { | ||
+ | $a = v >>> 24; | ||
+ | $r = ((v >>> 16 << 16) - ($a << 24)) >>> 16; | ||
+ | $g = ((v >>> 8 << 8) - ($a << 24) - ($r << 16)) >>> 8; | ||
+ | $b = ((v >>> 0 << 0) - ($a << 24) - ($r << 16) - ($g << 8)) >>> 0; | ||
+ | } | ||
+ | /** | ||
+ | * 32位4通道顏色值。 | ||
+ | */ | ||
+ | public function get value32():uint { | ||
+ | const A1:uint = $a >= 16 ? $a / 16 : 0; | ||
+ | const A2:uint = $a >= 16 ? $a % 16 : $a; | ||
+ | const R1:uint = $r >= 16 ? $r / 16 : 0; | ||
+ | const R2:uint = $r >= 16 ? $r % 16 : $r; | ||
+ | const G1:uint = $g >= 16 ? $g / 16 : 0; | ||
+ | const G2:uint = $g >= 16 ? $g % 16 : $g; | ||
+ | const B1:uint = $b >= 16 ? $b / 16 : 0; | ||
+ | const B2:uint = $b >= 16 ? $b % 16 : $b; | ||
+ | return (A1 << 28) + (A2 << 24) + (R1 << 20) + (R2 << 16) + | ||
+ | (G1 << 12) + (G2 << 8) + (B1 << 4) + (B2 << 0); | ||
+ | } | ||
+ | //========================================================================== | ||
+ | // Public methods | ||
+ | //========================================================================== | ||
+ | /** | ||
+ | * 設定顏色值為字符串所表示的無透明通道顏色值。<br/> | ||
+ | * 例如: | ||
+ | * <table> | ||
+ | * <tr><th>参数</th></tr> | ||
+ | * <tr><td>from("0xFFCC00");</td></tr> | ||
+ | * <tr><td>from("23564");</td></tr> | ||
+ | * </table> | ||
+ | * @param value 表示數值的字符串。 | ||
+ | */ | ||
+ | public function from(value:String):void { | ||
+ | const V:int = int(new Number(value)); | ||
+ | $a = 255; | ||
+ | $r = (V >>> 16 << 16) >>> 16; | ||
+ | $g = ((V >>> 8 << 8) - ($r << 16)) >>> 8; | ||
+ | $b = ((V >>> 0 << 0) - ($r << 16) - ($g << 8)) >>> 0; | ||
+ | } | ||
+ | /** | ||
+ | * 設定顏色值為字符串所表示的32位4通道顏色值。<br/> | ||
+ | * 例如: | ||
+ | * <table> | ||
+ | * <tr><th>参数</th></tr> | ||
+ | * <tr><td>from32("0xFFFFCC00");</td></tr> | ||
+ | * <tr><td>from32("3323564");</td></tr> | ||
+ | * </table> | ||
+ | * @param value 表示數值的字符串。 | ||
+ | */ | ||
+ | public function from32(value:String):void { | ||
+ | const V:int = int(new Number(value)); | ||
+ | $a = V >>> 24; | ||
+ | $r = ((V >>> 16 << 16) - ($a << 24)) >>> 16; | ||
+ | $g = ((V >>> 8 << 8) - ($a << 24) - ($r << 16)) >>> 8; | ||
+ | $b = ((V >>> 0 << 0) - ($a << 24) - ($r << 16) - ($g << 8)) >>> 0; | ||
+ | } | ||
+ | /** | ||
+ | * 無透明通道顏色值的16進制表示。 | ||
+ | */ | ||
+ | public function toString():String { | ||
+ | return "[0x" + value.toString(16).toUpperCase() + "]"; | ||
+ | } | ||
+ | /** | ||
+ | * 32位4通道顏色值的16進制表示。 | ||
+ | */ | ||
+ | public function toString32():String { | ||
+ | return "[0x" + value32.toString(16).toUpperCase() + "]"; | ||
+ | } | ||
+ | } // <- end class -> | ||
+ | } | ||
+ | </syntaxhighlight> |
2011-04-14T03:27:23的版本
RGBColor
package starpulse.geom { /** * RGB色彩。 */ public class RGBColor { //========================================================================== // Constructor //========================================================================== /** * RGB色彩。 * @param r Number - red value [0-255] * @param g Number - green value [0-255] * @param b Number - blue value [0-255] */ public function RGBColor(r:uint = 255, g:uint = 255, b:uint = 255, a:uint = 255) { $a = a; $r = r; $g = g; $b = b; } //========================================================================== // Properties //========================================================================== private var $a:uint; private var $r:uint; private var $g:uint; private var $b:uint; //========================================================================== // Public accessors //========================================================================== /** * @private */ public function set alpha(value:uint):void { $a = value; } /** * 透明通道。 */ public function get alpha():uint { return $a; } /** * @private */ public function set red(value:uint):void { $r = value; } /** * 紅色通道。 */ public function get red():uint { return $r; } /** * @private */ public function set green(value:uint):void { $g = value; } /** * 綠色通道。 */ public function get green():uint { return $g; } /** * @private */ public function set blue(value:uint):void { $b = value; } /** * 蓝色通道。 */ public function get blue():uint { return $b; } /** * @private */ public function set value(v:uint):void { $a = 255; $r = (v >>> 16 << 16) >>> 16; $g = ((v >>> 8 << 8) - ($r << 16)) >>> 8; $b = ((v >>> 0 << 0) - ($r << 16) - ($g << 8)) >>> 0; } /** * 無透明通道顏色值。 */ public function get value():uint { const R1:uint = $r >= 16 ? $r / 16 : 0; const R2:uint = $r >= 16 ? $r % 16 : $r; const G1:uint = $g >= 16 ? $g / 16 : 0; const G2:uint = $g >= 16 ? $g % 16 : $g; const B1:uint = $b >= 16 ? $b / 16 : 0; const B2:uint = $b >= 16 ? $b % 16 : $b; return (R1 << 20) + (R2 << 16) + (G1 << 12) + (G2 << 8) + (B1 << 4) + (B2 << 0); } /** * @private */ public function set value32(v:uint):void { $a = v >>> 24; $r = ((v >>> 16 << 16) - ($a << 24)) >>> 16; $g = ((v >>> 8 << 8) - ($a << 24) - ($r << 16)) >>> 8; $b = ((v >>> 0 << 0) - ($a << 24) - ($r << 16) - ($g << 8)) >>> 0; } /** * 32位4通道顏色值。 */ public function get value32():uint { const A1:uint = $a >= 16 ? $a / 16 : 0; const A2:uint = $a >= 16 ? $a % 16 : $a; const R1:uint = $r >= 16 ? $r / 16 : 0; const R2:uint = $r >= 16 ? $r % 16 : $r; const G1:uint = $g >= 16 ? $g / 16 : 0; const G2:uint = $g >= 16 ? $g % 16 : $g; const B1:uint = $b >= 16 ? $b / 16 : 0; const B2:uint = $b >= 16 ? $b % 16 : $b; return (A1 << 28) + (A2 << 24) + (R1 << 20) + (R2 << 16) + (G1 << 12) + (G2 << 8) + (B1 << 4) + (B2 << 0); } //========================================================================== // Public methods //========================================================================== /** * 設定顏色值為字符串所表示的無透明通道顏色值。<br/> * 例如: * <table> * <tr><th>参数</th></tr> * <tr><td>from("0xFFCC00");</td></tr> * <tr><td>from("23564");</td></tr> * </table> * @param value 表示數值的字符串。 */ public function from(value:String):void { const V:int = int(new Number(value)); $a = 255; $r = (V >>> 16 << 16) >>> 16; $g = ((V >>> 8 << 8) - ($r << 16)) >>> 8; $b = ((V >>> 0 << 0) - ($r << 16) - ($g << 8)) >>> 0; } /** * 設定顏色值為字符串所表示的32位4通道顏色值。<br/> * 例如: * <table> * <tr><th>参数</th></tr> * <tr><td>from32("0xFFFFCC00");</td></tr> * <tr><td>from32("3323564");</td></tr> * </table> * @param value 表示數值的字符串。 */ public function from32(value:String):void { const V:int = int(new Number(value)); $a = V >>> 24; $r = ((V >>> 16 << 16) - ($a << 24)) >>> 16; $g = ((V >>> 8 << 8) - ($a << 24) - ($r << 16)) >>> 8; $b = ((V >>> 0 << 0) - ($a << 24) - ($r << 16) - ($g << 8)) >>> 0; } /** * 無透明通道顏色值的16進制表示。 */ public function toString():String { return "[0x" + value.toString(16).toUpperCase() + "]"; } /** * 32位4通道顏色值的16進制表示。 */ public function toString32():String { return "[0x" + value32.toString(16).toUpperCase() + "]"; } } // <- end class -> }