This site requires flash player 9 or later.
/**
* 色相のトゥイーン
*
*
*/
var container:Shape = new Shape(); //塗り
var count:Number = 0; //カウント
//--------------------------------------------------------------------------
//
// 関数
//
//--------------------------------------------------------------------------
/**
* 初期設定
*
*/
function init():void {
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
container.graphics.beginFill(0x000000);
container.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
container.graphics.endFill();
addChild(container);
}
/**
* 色相環の色を取得
*
* @param per - 取得する位置(0~1)
* @return 色(16進数)
*/
function getColorWheel(per:Number):uint {
var div:Number = 1 / 6; //6分の1≒0.166666...
var r:uint; //赤
var g:uint; //緑
var b:uint; //青
//perを0~1の値に補正する
if(per < 0) per = 1 - (per % 1 * -1);
else if(1 < per) per %= 1;
if(per < div) {
//赤⇔黄色
r = 255;
g = 255 * per / div;
b = 0;
}
else if(per < div * 2) {
//黄色⇔緑
r = 255 * (1 - ((per - div) / div));
g = 255;
b = 0;
}
else if(per < div * 3) {
//緑⇔水色
r = 0;
g = 255
b = 255 * (per - div * 2) / div;
}
else if(per < div * 4) {
//水色⇔青
r = 0;
g = 255 * (1 - ((per - div * 3) / div));
b = 255;
}
else if(per < div * 5) {
//青⇔紫
r = 255 * (per - div * 4) / div;
g = 0;
b = 255;
}
else if(per < div * 6) {
//紫⇔赤
r = 255;
g = 0;
b = 255 * (1 - ((per - div * 5) / div));
}
r = r << 16;
g = g << 8;
return r + b + g;
}
/**
* ループ処理
*
* @param e - イベント
*/
function onUpdate(e:Event):void {
var color:uint = getColorWheel(count);
var r:uint = (color & 0xff0000) >> 16;
var g:uint = (color & 0xff00) >> 8;
var b:uint = (color & 0xff);
canvas.transform.colorTransform = new ColorTransform(0, 0, 0, 1, r, g, b, 1);
count += .005;
}
//--------------------------------------------------------------------------
//
// 処理
//
//--------------------------------------------------------------------------
init();
addEventListener(Event.ENTER_FRAME, onUpdate);
trace(getColorWheel(0).toString(16)); //ff0000(赤)
trace(getColorWheel(0.1666).toString(16)); //fffe00(ほぼ黄色)
trace(getColorWheel(1 / 6).toString(16)); //ffff00(黄色)
trace(getColorWheel(0.3333).toString(16)); //ff00(青)
trace(getColorWheel(.5).toString(16)); //ffff(水色)
trace(getColorWheel(0.6666).toString(16)); //ff(青)
trace(getColorWheel(0.8333).toString(16)); //fe00ff(ほぼ紫)
trace(getColorWheel(1 / 6 * 5).toString(16)); //ff00ff(紫)
trace(getColorWheel(-0.1666).toString(16)); //ff00fe(ほぼ紫)