Author Archives: Zevan

Alphabet with Base36 and Binary

CLICK HERE TO COPY
Actionscript:

var canvas:BitmapData=new BitmapData(280,100,false,0xefefef);

addChild(new Bitmap(canvas));

 

// pixel alphbet in base36

var alphabet:Array=["", "67erkgi", "e3j6dss", "75rue4u", "c5ltok8", "75s2tji", "75s2tjk", "75rugj2", "95yfnf6", "21blls4", "10nt5xo", "973it1u", "85aef4u", "59lu6nl", "cnz0hbn", "67ej51o", "67eq49c", "67ej53e", "67eq7gy", "66978m4", "6ywdqpw", "95y780c", "53b00as", "8nmdpyi", "5374thm", "53avnus", "6xsfdam"];

 

function drawBase36(num:String, xp:int, yp:int):void {

    // convert base36 to binary

    num=parseInt(num,36).toString(2);

    while (num.length <35) {

  [...]

Posted in BitmapData, pixel manipulation, strings | Tagged , , , , | 2 Comments

2D Z-Sort

CLICK HERE TO COPY
Actionscript:

var shapes:Array = new Array();

 

for (var i:int = 0; i<300; i++){

    var s:Shape = new Shape();

    s.x = Math.random()* stage.stageWidth;

    s.y = Math.random()* stage.stageHeight;

    s.graphics.lineStyle(0,0x000000);

    s.graphics.beginFill(0xCCCCCC);

    s.graphics.drawCircle(0,0, Math.random()*s.y / 5);

    shapes.push(s);

}

 

// comment this out to remove sorting

shapes.sortOn("width", Array.NUMERIC);

 

for (i = 0; i<shapes.length; i++){

    addChild(shapes[i]);

}

This [...]

Posted in arrays, sortOn | Tagged , | Leave a comment

Set Multiple Properties

CLICK HERE TO COPY
Actionscript:

// set multiple properties of an Object

function setProps(o:*, props:Object):void{

    for (var key:String in props){

         o[key] = props[key];

    }

}

 

// example:

 

var s:Sprite = new Sprite();

s.graphics.beginFill(0);

s.graphics.drawRect(0,0,10,10);

addChild(s);

 

// set some properties

setProps(s, {x:100, y:100, scaleX:2, scaleY:2, rotation:45});

This was inspired by tweening engines like TweenLite.
Basically the same thing using a with [...]

Posted in Object, properties | Leave a comment

10,000 35 ways, .toString(radix);

CLICK HERE TO COPY
Actionscript:

for(var i:int = 2; i<37; i++){

    trace((10000).toString(i));

}

/*

outputs:

10011100010000

111201101

2130100

310000

114144

41104

23420

14641

10000

7571

5954

4723

3904

2e6a

2710

20a4

1cfa

18d6

1500

11e4

kec

iki

h8g

g00

ekg

dja

cl4

bpo

b3a

aci

9og

961

8m4

85p

7ps

*/

I had either totally forgotten about or never known about the Number, uint, int etc... .toString() radix argument. Brock mentioned it to me in conversation and I've been having fun with it ever since. It's especially nice for tracing out hex numbers:
CLICK HERE TO COPY
Actionscript:

var [...]

Posted in Number, strings | Tagged , , | Leave a comment