Hue Test
a hue test
/**
* Copyright Trinkschokolade ( http://wonderfl.net/user/Trinkschokolade )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/3qwC
*/
// forked from Trinkschokolade's Hue Test
package {
import flash.text.TextField;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.filters.*;
import flash.display.*;
import flash.geom.*;
import flash.events.*;
public class FlashTest extends Sprite {
private var hue:ColorMatrixFilter;
public var loader:Loader = new Loader()
private var tf:TextField = new TextField();
private var text:String="";
private var wind:Sprite = new Sprite();
public function FlashTest() {
addEventListener(Event.ADDED_TO_STAGE, init)
}
private function init(e:Event):void
{
addTF();
load();
stage.addEventListener(MouseEvent.MOUSE_MOVE, move)
drawWindow()
tf.x += 5
tf.y += 250
tf.width = 500
}
public function addTF():void
{
addChild(tf)
tf.text = text;
}
public function load():void
{
var toLoad:String = "http://upload.wikimedia.org/wikipedia/commons/d/d5/Sun_icon.png"
var urlReq:URLRequest = new URLRequest(toLoad)
loader.load(urlReq);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
}
public function onLoadComplete(e:Event=null):void
{
addChild(loader)
}
private function drawWindow():void
{
var matrix:Matrix = new Matrix();
matrix.createGradientBox(550,400,0,0,0);
wind.graphics.beginGradientFill(GradientType.LINEAR,[0xFF0000,0x0000FF],[1,1],[0,125],matrix)
wind.graphics.drawRect(5,400,350,25)
wind.graphics.endFill();
addChild(wind);
}
private function move(e:MouseEvent):void
{
// changeHue(mouseX);
changeHue(mouseX/stage.stageWidth)
//changeHue(mouseX*mouseY/stage.stageWidth/stage.stageHeight)
}
public function changeHue(hue:Number,type:int=1):void
{
var EffectMatrix:Array = new Array();
var r:Number,g:Number,b:Number;
var r2:Number,g2:Number,b2:Number;
var r3:Number,g3:Number,b3:Number;
var color:Number;
hue = hue-int(hue)
var cent:Number = 0xFFFFFF/1000
color = hue*0xFFFFFF;
r = int(color/cent)/1000;
g = (color/cent)-int(color/cent);
if (r+g>1){
g = 1-r
}
b = 1-r-g;
g2 = int(color/cent)/1000;
b2 = (color/cent)-int(color/cent);
if (g2+b2>1){
b2 = 1-g2
}
r2 = 1-g2-b2;
b3 = int(color/cent)/1000;
r3 = (color/cent)-int(color/cent);
if (b3+r3>1){
r3 = 1-b3
}
g3 = 1-b3-r3;
EffectMatrix = EffectMatrix.concat([r ,g ,b ,0,0]);
EffectMatrix = EffectMatrix.concat([b2 ,r2 ,g2 ,0,0]);
EffectMatrix = EffectMatrix.concat([g3 ,b3 ,r3 ,0,0]);
EffectMatrix = EffectMatrix.concat([0,0,0,1,0]);
tf.text = "R: "+r2+"\nG: "+g3+"\nB: "+b;
loader.filters = [new ColorMatrixFilter(EffectMatrix)]
}
}
}