color_toolkit.as
来自「这是《Flash MX编程与创意实现》的源代码」· AS 代码 · 共 621 行 · 第 1/2 页
AS
621 行
/*
Color Toolkit v1.2
Oct. 29, 2002
(c) 2002 Robert Penner
MovieClip getter/setter properties:
_brightness
_brightOffset
_negativeColor
_rgb
_red
_green
_blue
_redPercent
_greenPercent
_bluePercent
_redOffset
_greenOffset
_blueOffset
Color methods:
setRGB2()
getRGB2()
reset()
setBrightness()
getBrightness()
setBrightOffset()
getBrightOffset()
setTint()
getTint()
setTint2()
getTint2()
setTintOffset()
getTintOffset()
setRed()
getRed()
setGreen()
getGreen()
setBlue()
getBlue()
setRedPercent()
getRedPercent()
setGreenPercent()
getGreenPercent()
setBluePercent()
getBluePercent()
setRedOffset()
getRedOffset()
setGreenOffset()
getGreenOffset()
setBlueOffset()
getBlueOffset()
invert()
setNegative()
getNegative()
MovieClip methods:
setRGB()
getRGB()
setRGB2()
getRGB2()
resetColor()
setColorTransform()
getColorTransform()
setBrightness()
getBrightness()
setBrightOffset()
getBrightOffset()
setTint()
getTint()
setTint2()
getTint2()
setTintOffset()
getTintOffset()
setRed()
getRed()
setGreen()
getGreen()
setBlue()
getBlue()
setRedPercent()
getRedPercent()
setGreenPercent()
getGreenPercent()
setBluePercent()
getBluePercent()
setRedOffset()
getRedOffset()
setGreenOffset()
getGreenOffset()
setBlueOffset()
getBlueOffset()
invertColor()
setNegativeColor()
getNegativeColor()
Discussed in Chapter 9 of
Robert Penner's Programming Macromedia Flash MX
http://www.robertpenner.com/profmx
http://www.amazon.com/exec/obidos/ASIN/0072223561/robertpennerc-20
*/
// --------------------------------------------------------
// ====== solid color - Color methods ======
Color.prototype.setRGBStr = function (hexStr) {
// grab the last six characters of the string
hexStr = hexStr.substr (-6, 6);
this.setRGB (parseInt (hexStr, 16));
};
Color.prototype.getRGBStr = function () {
var hexStr = this.getRGB().toString(16);
// fill in zeroes as needed
var toFill = 6 - hexStr.length;
while (toFill--) hexStr = "0" + hexStr;
return hexStr.toUpperCase();
};
// set red, green, and blue with normal numbers
// r, g, b between 0 and 255
Color.prototype.setRGB2 = function (r, g, b) {
this.setRGB (r << 16 | g << 8 | b);
}; // Branden Hall - www.figleaf.com
// returns an object with r, g, and b properties
Color.prototype.getRGB2 = function () {
var t = this.getTransform();
return {r:t.rb, g:t.gb, b:t.bb};
};
// reset the color object to normal
Color.prototype.reset = function () {
this.setTransform ({ra:100, ga:100, ba:100, rb:0, gb:0, bb:0});
};
// --------------------------------------------------------
// ====== solid color - MovieClip methods ======
MovieClip.prototype.setRGB = function (col) {
(new Color(this)).setRGB (col);
};
MovieClip.prototype.getRGB = function () {
return (new Color(this)).getRGB();
};
MovieClip.prototype.setRGBStr = function (hexStr) {
(new Color(this)).setRGBStr (hexStr);
};
MovieClip.prototype.getRGBStr = function () {
return (new Color(this)).getRGBStr();
};
// set red, green, and blue with normal numbers
// r, g, b between 0 and 255
MovieClip.prototype.setRGB2 = function (r, g, b) {
(new Color(this)).setRGB2 (r, g, b);
};
// returns an object with r, g, and b properties
MovieClip.prototype.getRGB2 = function () {
return (new Color(this)).getRGB2();
};
// invert current color values
MovieClip.prototype.resetColor = function () {
(new Color(this)).reset();
};
// --------------------------------------------------------
// ====== color transform - MovieClip methods ======
MovieClip.prototype.setColorTransform = function (trans) {
(new Color(this)).setTransform (trans);
};
MovieClip.prototype.getColorTransform = function () {
return (new Color(this)).getTransform();
};
// --------------------------------------------------------
// ====== brightness - Color methods ======
// brighten just like Property Inspector
// bright between -100 and 100
Color.prototype.setBrightness = function (bright) {
var trans = this.getTransform();
with (trans) {
ra = ga = ba = 100 - Math.abs (bright); // color percent
rb = gb = bb = (bright > 0) ? bright * (256/100) : 0; // color offset
}
this.setTransform (trans);
};
Color.prototype.getBrightness = function () {
var trans = this.getTransform();
with (trans) return rb ? 100 - ra : ra - 100;
};
// ====== brightness - MovieClip methods ======
// brighten just like Property Inspector
// bright between -100 and 100
MovieClip.prototype.setBrightness = function (bright) {
(new Color(this)).setBrightness (bright);
};
MovieClip.prototype.getBrightness = function () {
return (new Color(this)).getBrightness();
};
// --------------------------------------------------------
// ====== brightOffset - Color methods ======
// offset between -255 and 255
Color.prototype.setBrightOffset = function (offset) {
var trans = this.getTransform()
with (trans) rb = gb = bb = offset;
this.setTransform (trans);
};
Color.prototype.getBrightOffset = function () {
return this.getTransform().rb;
};
// ====== brightOffset - MovieClip methods ======
// offset between -255 and 255
MovieClip.prototype.setBrightOffset = function (offset) {
(new Color(this)).setBrightOffset (offset);
};
MovieClip.prototype.getBrightOffset = function () {
return (new Color(this)).getBrightOffset();
};
// --------------------------------------------------------
// ====== tint - Color methods ======
// tint with a color just like Property Inspector
// r, g, b between 0 and 255; percent between 0 and 100
Color.prototype.setTint = function (r, g, b, percent) {
var ratio = percent / 100;
var trans = {rb:r*ratio, gb:g*ratio, bb:b*ratio};
trans.ra = trans.ga = trans.ba = 100 - percent;
this.setTransform (trans);
};
// returns a tint object containing r, g, b, and percent properties
Color.prototype.getTint = function () {
var trans = this.getTransform();
var tint = {percent: 100 - trans.ra};
var ratio = 100 / tint.percent;
tint.r = trans.rb * ratio;
tint.g = trans.gb * ratio;
tint.b = trans.bb * ratio;
return tint;
};
// tint with a color - alternate approach
// rgb a color number between 0 and 0xFFFFFF; percent between 0 and 100
Color.prototype.setTint2 = function (rgb, percent) {
var r = (rgb >> 16) ;
var g = (rgb >> 8) & 0xFF;
var b = rgb & 0xFF;
var ratio = percent / 100;
var trans = {rb:r*ratio, gb:g*ratio, bb:b*ratio};
trans.ra = trans.ga = trans.ba = 100 - percent;
this.setTransform (trans);
};
// returns a tint object containing rgb (a 0xFFFFFF number) and percent properties
Color.prototype.getTint2 = function () {
var trans = this.getTransform();
var tint = {percent: 100 - trans.ra};
var ratio = 100 / tint.percent;
tint.rgb = (trans.rb*ratio)<<16 | (trans.gb*ratio)<<8 | trans.bb*ratio;
return tint;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?