输出连续颜色:
/** * * *-----------------------* * | *** 输出连续颜色 *** | * *-----------------------* * * 编辑修改收录:fengzi(疯子、wu341、wgq341) * * 不会写代码,我是代码搬运工。 * * 联系方式:QQ(493712833)。 * * 随 笔: https://www.cnblogs.com/fengziwu/ * * 版权协议:请自觉遵守LGPL协议,欢迎修改、复制、转载、传播给更多需要的人。 * 免责声明:任何因使用此软件导致的纠纷与软件/程序开发者无关。 * 日 期: 2019.05.08 */ /** * 24位、32位颜色 * reload() 连续执行此方法,不断更新颜色值 * @author fengzi * @date : 28/11/2018 */ package fengzi.colors { import flash.display.Sprite; import flash.events.Event; import flash.utils.Timer; import flash.events.TimerEvent; public class GetColor extends Sprite { private var _colorRandom:uint; private var _color:uint = 0xf09000; private var colorArray:Array; private var index:uint = 0; private var mz:int = 1; private var _index:uint = 0; private var i:Number; private var j:Number; //构造函数 public function GetColor():void { colorArray = color_arr(); } //连续执行此方法,不断更新颜色值 public function reload():void { i = Math.random(); if (i > 0.99) { mz *= -1; } j = Math.round(mz * i * 5); index += j; if (index < 0) { index = colorArray.length - 1; } else { if (index >= colorArray.length) { index = 0; } } _colorRandom = colorArray[index]; if (++_index > colorArray.length - 1) { _index = 0; } _color = colorArray[_index]; } private function color_arr():Array { var color1:Array = []; var color2:Array = []; var color3:Array = []; var color4:Array = []; var color5:Array = []; var color6:Array = []; var color7:Array = []; for (var n:int = 0; n <255; n += 3) { color1.push(0xFF0000 + n * 255); color2.push((255 - n) * 0x10000 + 0xFF00); color3.push(0xFF00 + n); color4.push((255 - n) * 255 +255); color5.push(255 + n * 0x10000); color6.push(255 - n+ 0xFF0000); } color7 = [].concat(color1).concat(color2).concat(color3).concat(color4).concat(color5).concat(color6); return color7; } /** * @color32Random 连续的随机颜色 * @return 返回32位随机颜色值 */ public function get color32Random():uint { var red:uint = _colorRandom >> 16; var green:uint = _colorRandom >> 8 & 0xFF; var blue:uint = _colorRandom & 0xFF; return getColorFromRGBA(red,green,blue,255); } /** * @orderColor32 连续的顺序颜色 * @return 返回32位顺序颜色值 */ public function get orderColor32():uint { var red:uint = _color >> 16; var green:uint = _color >> 8 & 0xFF; var blue:uint = _color & 0xFF; return getColorFromRGBA(red,green,blue,255); } /** * @color24 连续的顺序颜色 * @return 返回24位顺序颜色值 */ public function get color24():uint { return _color; } /** * @getColorFromRGBA 颜色通道 * @param r 红色值 * @param g 绿色值 * @param b 蓝色值 * @param a Alpha 值 * @return 32位颜色值0xFFFFFFFF */ public function getColorFromRGBA(r:uint=0,g:uint=0,b:uint=0,a:Number=1.0):uint { return ((a * 0xff ) & 0xff) << 24| r << 16| g << 8 | b; } /** * @getColorFromRGB 颜色通道 * @param r 红色值 * @param g 绿色值 * @param b 蓝色值 * @return 24位颜色值0xFFFFFF */ public function getColorFromRGB(r:uint=0,g:uint=0,b:uint=0):uint { return r << 16 | g << 8 | b; } /** * @randomColor24 * @return 返回24位随机颜色值 */ public function get randomColor24():uint { var r:Number = Math.random() * 255; var g:Number = Math.random() * 255; var b:Number = Math.random() * 255; return r << 16 | g << 8 | b; } /** * @randomColor32 * @return 返回32位随机颜色值 */ public function get randomColor32():uint { var a:Number = Math.random() * 255; var r:Number = Math.random() * 255; var g:Number = Math.random() * 255; var b:Number = Math.random() * 255; return a << 24 | r << 16 | g << 8 | b; } } }