Author Archives: Zevan

Dynamic Graphics and Function.apply()

CLICK HERE TO COPY
Actionscript:

var cmds:Array = [["lineStyle", 0, 0xFF0000], ["drawCircle",100, 100, 50], ["drawRect", 50, 50, 100, 100]];

cmds.push(["drawCircle", 100, 100, 70]);

cmds.push(["beginFill",  0x555555]);

cmds.push(["drawRoundRect", 80, 80, 40, 40, 10, 10]);

cmds.push(["endFill"]);

 

render(cmds);

 

function render(p:Array):void {

    for (var i:int = 0; i<p.length; i++) {

        graphics[p[i][0]].apply(graphics,p[i].splice(1));

    }

}

The above creates a function called render() that takes a 2D array [...]

Posted in Graphics, dynamic, functions | Tagged , | 2 Comments

Visualizing Binary Numbers Part 2

CLICK HERE TO COPY
Actionscript:

[SWF(width=900,height=390,backgroundColor=0x000000,frameRate=30)]

 

var canvas:BitmapData=new BitmapData(4,8,false,0xFFFFFFFF);

var pixNum:int = canvas.width * canvas.height;

 

var frame:Bitmap = Bitmap(addChild(new Bitmap(canvas)));

frame.scaleX = frame.scaleY = canvas.width * 10;

frame.x = stage.stageWidth / 2 - frame.width / 2;

frame.y =20;

 

var txt:TextField = TextField(addChild(new TextField()));

txt.autoSize = TextFieldAutoSize.LEFT;

txt.defaultTextFormat = new TextFormat("Verdana", 8, 0xFFFFFF);

txt.x = frame.x - 3;

txt.y = frame.y + frame.height + 10;

 

var s:String, a:Number = 0, [...]

Posted in BitmapData, setPixel | Tagged , | Leave a comment

Visualizing Binary Numbers

CLICK HERE TO COPY
Actionscript:

[SWF(width=320,height=512,backgroundColor=0x000000,frameRate=30)]

 

var canvas:BitmapData=new BitmapData(32,512,false,0xFFFFFF);

addChild(new Bitmap(canvas)).scaleX = 10;

 

var a:uint ;

var s:String;

var m:Number = 0;

var d:Number = 0;

var mi:int ;

var r:Number = 0xFFFFFF / stage.stageWidth;

 

addEventListener(Event.ENTER_FRAME, onLoop);

 

function onLoop(evt:Event):void {

   

    d = mouseX * r;

    m += (d - m) / 30;

   

    mi = int(m);

 

    canvas.lock();

    canvas.fillRect(canvas.rect, 0xFFFFFF);

 

  [...]

Posted in BitmapData, misc, pixel manipulation | Tagged , | 3 Comments

Snippet Template (imports)

CLICK HERE TO COPY
Actionscript:

package {

    import adobe.utils.*;

    import flash.accessibility.*;

    import flash.display.*;

    import flash.errors.*;

    import flash.events.*;

    import flash.external.*;

    import flash.filters.*;

    import flash.geom.*;

    import flash.media.*;

    import flash.net.*;

    import flash.printing.*;

    import flash.profiler.*;

    import flash.sampler.*;

    import flash.system.*;

    import flash.text.*;

    import flash.ui.*;

    import [...]

Posted in OOP, dynamic, misc, timeline | Tagged , | 4 Comments