forked from: Color wheel
// forked from flex_axis's Color wheel
package
{
import flash.display.BitmapData;
import flash.display.CapsStyle;
import flash.display.GradientType;
import flash.display.Graphics;
import flash.display.LineScaleMode;
import flash.display.Sprite;
import flash.geom.Matrix;
public class ColorWheel extends Sprite
{
public function ColorWheel()
{
init();
}
private var _bitmapData:BitmapData;
[Bindable]
public function get bitmapData():BitmapData
{
return _bitmapData;
}
public function set bitmapData(value:BitmapData):void
{
_bitmapData=value;
}
public function init():void
{
var radians:Number, red:Number, green:Number, blue:Number, color:Number, matrix:Matrix, _x:Number, _y:Number,
thickness:int;
var i:int=0;
var radius:Number=100;
var offset:Number = radius/2;
var g:Graphics=graphics;
g.clear();
thickness=1 + int(radius / 50);
while (i < 360)
{
radians=i * (Math.PI / 180);
red=(Math.cos(radians) * 127) + 128 << 16;
green=(Math.cos(radians + 2 * Math.PI / 3) * 127) + 128 << 8;
blue=(Math.cos(radians + 4 * Math.PI / 3) * 127) + 128;
color=(red | green | blue);
_x=(radius * Math.cos(radians));
_y=(radius * Math.sin(radians));
g.lineStyle(2, color, 1, false, LineScaleMode.NONE, CapsStyle.NONE);
g.moveTo(offset, offset);
g.lineTo(_x + (offset), _y + (offset));
i++;
}
var m:Matrix = new Matrix();
m.createGradientBox(radius,radius,0,0,0);
g.lineStyle();
g.beginGradientFill(GradientType.RADIAL,[0xFFFFFF,0xFFFFFF,0,0],[1,0,0,1],[0,140,140,255],m);
g.drawCircle(offset,offset,offset);
g.endFill();
bitmapData=new BitmapData(radius, radius, false, 0);
bitmapData.draw(this, null, null, null, null, true);
}
}
}