ColorMatrixFilter 클래스를 이용하면 이미지의 각 픽셀의 RGBA 색상 및 알파 값에 4 x 5 행렬 변환을 적용하여 saturation 또는 contrast 또는 brightness 를 적용할수 있다. 물론 각각의 ColorMatrixFilter 에 적용되는 matrix 속성값을 다르게 설정하여야 한다.
이 예제에서 활용한 ColorMatrix 는 Mario Klingemann(http://www.quasimondo.com) 가 제작한 소스를 이용하여 트윈클래스를 제작하였다.
기본적인 클래스 구조는 이전의 트윈클래스와 같다. 객체속성을 이용하여 for~in 구문으로 트윈을 적용하였다. 다른 객체에 비해 적용되는 속성의 갯수(matrix 속성)가 20개로써 많기 때문에 이미지를 크게 하거나 트윈길이를 너무 길게할 경우 느려질 수가 있다. 또한 트윈이후 이전 트윈클래스와 같이 콜백함수를 호출할 수 있다.
//================================================================== //@class name : ColorMatrixTween.as //@author : vkimone. KimKiJeung (http://kimkijeung.com) //@last update : 2007. 03. 19 //@version : V1.0 //================================================================== /** @description * 무비클립의 ColorMatrixFilter 트윈 클래스 : 이징함수 설정으로 조절 * @example * <code> * ColorMatrixTween.tween(targetMc,0,ColorMatrixTween.SATURATION,Regular.easeOut,30, {{func: callBackFunction,obj: functionScope, param: [파라미터 배열로 들어감]}} * </code> */ import flash.filters.ColorMatrixFilter; import com.dstrict.UB.util.filters.ColorMatrix; class com.dstrict.UB.util.transitions.tween.ColorMatrixTween{ public static var SATURATION:String="saturation"; public static var CONTRAST:String="contrast"; public static var BRIGHTNESS:String="brightness"; /**--------------------------------------------------------------------- *@description saturation, contrast, brightness 트랜지션 @param mc : MovieClip, 적용무비클립 @param value : Number , 적용 percentage @param mode :String , saturation or contrast or brightness mode @param func : Function, easing function @param durationFrame : Number, 지속프레임 *----------------------------------------------------------------------*/ public static function tween(mc:MovieClip,value:Number,mode:String,func:Function,durationFrame:Number):Void{ var time:Number=1; var beginning:Array=new Array(); var change:Array=new Array(); var mat:ColorMatrix = new ColorMatrix(); switch(mode){ case SATURATION : mat.adjustSaturation(value/100); break; case CONTRAST : mat.adjustContrast(value/100); break; case BRIGHTNESS : mat.adjustBrightness(255*value/100); break; } var cm:ColorMatrixFilter = new ColorMatrixFilter(mat.matrix); var startMatrix:Array= (mc.filters[0].matrix==undefined) ? ColorMatrix.IDENTITY : mc.filters[0].matrix; var targetMatrix:Array=mat.matrix; for(var i in targetMatrix){ beginning.push(startMatrix[i]); change.push(targetMatrix[i]-startMatrix[i]); } var type=(typeof(arguments[5])=="object")? true : false; if(type){ var referObj=arguments[5]; }else{ var p:Number=arguments[5]; var referObj=arguments[6]; } mc.onEnterFrame=function(){ var objIdx:Number=0; for(var i in targetMatrix){ targetMatrix[i]=func(time,beginning[objIdx],change[objIdx],durationFrame,p); objIdx++; } targetColMatrixFilter.matrix=targetMatrix; mc.filters=[targetColMatrixFilter]; time++; if(time>durationFrame){ delete this.onEnterFrame; if(referObj!=undefined){ referObj.func.apply(referObj.obj,referObj.param); } } }; } } import com.dstrict.UB.util.transitions.tween.FilterTween; import mx.transitions.easing.*; import com.dstrict.UB.util.filters.ColorMatrix; //SATURATION (from 0 to 100) image.onRollOver=function(){ ColorMatrixTween.tween(image,0,ColorMatrixTween.SATURATION,Regular.easeOut,10); } image.onRollOut=function(){ ColorMatrixTween.tween(image,100,ColorMatrixTween.SATURATION,Regular.easeOut,10); } //CONTRAST (from 0 to 100) image2.onRollOver=function(){ ColorMatrixTween.tween(image2,100,ColorMatrixTween.CONTRAST,Regular.easeOut,10); } image2.onRollOut=function(){ ColorMatrixTween.tween(image2,0,ColorMatrixTween.CONTRAST,Regular.easeOut,10); } //BRIGHTNESS (from -100 to 100) image3.onRollOver=function(){ ColorMatrixTween.tween(image3,100,ColorMatrixTween.BRIGHTNESS,Regular.easeOut,10); } image3.onRollOut=function(){ ColorMatrixTween.tween(image3,0,ColorMatrixTween.BRIGHTNESS,Regular.easeOut,10); }

아직 자세히 살펴보지는 못했지만 내가 기대하고 있던 내용의 책이였다. AS3.0 으로 바뀌면서 문법자체가 자바랑 상당부분 비슷하게 바뀌었기 때문에 문법적으로 자바 디자인 패턴책과 엄청난 차이가 있는것은 아니다. 하지만 플래시만의 고유의 영역에 있어서 자바나 다른 언어와는 다른 구조적인 이유로 인해 발생하는 패턴 적용의 이슈들을 어느정도 다뤄줬기 때문에 상당히 유용할것 같다.
Recent Comments