/** Hue ColorMatrixFilter version 2.0.1 Created by Matthew Lloyd http://www.DevSlash.com/ Matt.Lloyd101@gmail.com This is release under a Creative Commons license. More information can be found here: http://creativecommons.org/licenses/by-nc-sa/2.0/uk/ ---------------------------------------------------------------- @codehint Gives you a way to change the Hue and Saturation on DisplayObjects. @example import com.deviant.HueColorMatrixFilter; import flash.events.*; var HCMF = new HueColorMatrixFilter(); var H = 0; var I = 0; clip.addEventListener(Event.ENTER_FRAME, oEF); function oEF(e:Event) { HCMF.reset(); HCMF.Hue = H++; I += Math.PI/360; HCMF.Saturation = Math.sin(I); clip.filters = [HCMF.Filter]; } */ package com.deviant { import flash.filters.ColorMatrixFilter; public class HueColorMatrixFilter { private var matrix:Array; public function HueColorMatrixFilter() { Identity(); } private function Identity():void { matrix = [ 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0 ]; } public function reset():void { Identity(); } public function set Saturation(saturation:Number):void { saturation = (saturation > 1)?1:(saturation < 0)?0:saturation; var M1:Array = [ 0.213, 0.715, 0.072, 0.213, 0.715, 0.072, 0.213, 0.715, 0.072]; var M2:Array = [ 0.787, -0.715, -0.072, -0.212, 0.285, -0.072, -0.213, -0.715, 0.928]; var M3:Array = add(M1, multiply(saturation, M2)); concat([ M3[0], M3[1], M3[2], 0, 0, M3[3], M3[4], M3[5], 0, 0, M3[6], M3[7], M3[8], 0, 0, 0, 0, 0, 1, 0]); } private var _h:Number = 0; public function set Hue(hue:Number):void { _h = hue; // convert from Rad to Degrees hue = _h*0.0174532925; var M1:Array = [ 0.213, 0.715, 0.072, 0.213, 0.715, 0.072, 0.213, 0.715, 0.072]; var M2:Array = [ 0.787, -0.715, -0.072, -0.212, 0.285, -0.072, -0.213, -0.715, 0.928]; var M3:Array = [ -0.213, -0.715, 0.928, 0.143, 0.140, -0.283, -0.787, 0.715, 0.072]; var M4:Array = add(M1, add(multiply(Math.cos(hue), M2), multiply(Math.sin(hue), M3))); concat([ M4[0], M4[1], M4[2], 0, 0, M4[3], M4[4], M4[5], 0, 0, M4[6], M4[7], M4[8], 0, 0, 0, 0, 0, 1, 0]); } public function get Hue():Number { return _h; } private function add(A:Array, B:Array):Array { var C:Array = []; for(var i:uint=0; i