标签:as actionscript as3.0 颜色渐变
//分离:如0xefebec 变成[0xec,0xeb,oxef] function colorValTransfer(inNum:uint):Array{ if(inNum>0xffffff){ throw new Error("Function:colorValTransfer parameter:inNum>>>parameter‘s value must be smaller than 0xffffff"); } var outArr = []; outArr[0] = inNum % 0x100; var middleVal:uint = Math.floor(inNum / 0x100); outArr[1] = middleVal% 0x100; outArr[2] = Math.floor(middleVal/0x100); return outArr; } //找出与0xff的最大差值 如 max(0xff - 0xec,0xff-0xeb,0xff-0xef) function transferBaseNum(tranferArr:Array):uint{ var basicNum : uint = 0; var ergodicFun = function (element:*, index:int, arr:Array): void { var res:int = 0xff - element; if(res < 0 || element < 0){ throw new Error(‘Function:transferBaseNum parameter:tranferArr>>>The elements in an Array must be smaller than 0xff and biger than 0x00‘); } if(res > basicNum){ basicNum = res; } } tranferArr.forEach(ergodicFun); return basicNum; } //生成颜色渐变数组 function getGradientColorArr(colorInNum:uint):Array{ var outArr:Array = colorValTransfer(colorInNum); var basicNum:uint = transferBaseNum(outArr); var resArr:Array = []; resArr[0] = outArr[0] + outArr[1] * 0x100 + outArr[2] * 0x10000; var midleF,midleM,midleE:uint = 0; for(var i:int = 1 ; i <= basicNum ; i++){ outArr[0] += 1; outArr[1] += 1; outArr[2] += 1; if(outArr[0] >0xff){ midleF = 0xff; }else{ midleF = outArr[0]; } if(outArr[1] > 0xff ){ midleM = 0xff; }else{ midleM = outArr[1]; } if(outArr[2] > 0xff){ midleE = 0xff; }else{ midleE = outArr[2]; } resArr[i] = midleF + midleM * 0x100 + midleE * 0x10000; } return resArr; } var log:Function = function(element:*, index:int, arr:Array):void{ trace(element.toString(16)); } getGradientColorArr(0x333333).forEach(log);
本文出自 “我的IT生涯” 博客,请务必保留此出处http://quietnight.blog.51cto.com/7163892/1679103
as3.0 小代码(1)------ 颜色渐变中的颜色渐变数组产生算法
标签:as actionscript as3.0 颜色渐变
原文地址:http://quietnight.blog.51cto.com/7163892/1679103