Author Archives: Zevan

Dial UI, Record Scratch etc…

CLICK HERE TO COPY
Actionscript:

var angOffset:Number = 0;

var percent:Number  = 0;

 

var dial:Sprite = Sprite(addChild(new Sprite()));

with(dial.graphics) lineStyle(1, 0x000000), beginFill(0xCCCCCC), drawCircle(0,0,100), lineTo(0,0);

dial.x = stage.stageWidth / 2;

dial.y = stage.stageHeight / 2;

 

dial.addEventListener(MouseEvent.MOUSE_DOWN, onDialDown);

stage.addEventListener(MouseEvent.MOUSE_UP, onStageUp);

function onDialDown(evt:MouseEvent):void {

    calcOffset();

    dial.addEventListener(Event.ENTER_FRAME, onRotateDial);

}

 

function calcOffset():void {

    angOffset = Math.atan2(mouseY - dial.y, mouseX - dial.x) / Math.PI * 180 - dial.rotation;

}

 

function onRotateDial(evt:Event):void {

  [...]

Posted in UI | Tagged , | Leave a comment

lineTo() w/ drawCircle()

CLICK HERE TO COPY
Actionscript:

var dial:Sprite = Sprite(addChild(new Sprite()));

with(dial.graphics) lineStyle(1, 0x000000), beginFill(0xCCCCCC), drawCircle(0,0,100), lineTo(0,0);

dial.x = stage.stageWidth / 2;

dial.y = stage.stageHeight / 2;

This snippet shows how you can combine drawCircle() and lineTo() to quickly draw a clock/dial primitive shape. I'll use this in tomorrows snippet...

Posted in Graphics | Tagged , | Leave a comment

(HSV HSB) to RGB

CLICK HERE TO COPY
Actionscript:

[SWF(width=720,height=360,backgroundColor=0x000000,frameRate=30)]

 

// ported from here:

//http://www.cs.rit.edu/~ncs/color/t_convert.html

 

function hsv(h:Number, s:Number, v:Number):Array{

    var r:Number, g:Number, b:Number;

    var i:int;

    var f:Number, p:Number, q:Number, t:Number;

     

    if (s == 0){

        r = g = b = v;

        return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];

    [...]

Posted in BitmapData, color, graphics algorithms, pixel manipulation, setPixel | Tagged , , | 6 Comments

Math.min() Math.max() …rest

CLICK HERE TO COPY
Actionscript:

trace("min", Math.min(100, 99, 32, 75, 44, 90));

trace("max", Math.max(100, 99, 32, 75, 44, 90));

/*outputs:

32

100

*/

It's easy not to notice that Math.min() and Math.max() can take any number of arguments. I've seen people nest min/max calls instead of using the above option.... like this:
CLICK HERE TO COPY
Actionscript:

trace(Math.min(1, Math.min(2, 3)));

Posted in misc | Tagged , | Leave a comment