Author Archives: Zevan

Flowing Leaves (optical illusion)

Saw this optical illusion today... figured I'd make a snippet to create a few variations on the illusion...
CLICK HERE TO COPY
Actionscript:

[SWF( backgroundColor=0x2E7999, width=780, height = 600) ]

 

var leafNum:Number = 375;

var spacing:Number = 12;

var cols:Number = 25;

var hh:Number = stage.stageHeight / 2;

var hw:Number = stage.stageWidth / 2;

 

for (var i:Number = 0; i<leafNum; i++){

    var leaf:Shape [...]

Posted in Graphics, Math, Vector, misc, motion, pixel manipulation | Tagged , , , | 5 Comments

ByteArray.readUTFBytes()

CLICK HERE TO COPY
Actionscript:

var m:ByteArray = new ByteArray();

var bytes:Array = [0x41, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x20,

                   0x53, 0x6E, 0x69, 0x70, 0x70, 0x65, 0x74]

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

    m.writeByte(bytes[i]);

}

 

m.position = 0;

 

trace(m.readUTFBytes(bytes.length));

I was messing around with a hex editor today and decided to [...]

Posted in Uncategorized | Tagged , , , | 2 Comments

Bitwise OR | and Variable Function Arguments (bitwise flags)

CLICK HERE TO COPY
Actionscript:

const A:uint = 1;

const B:uint = 2;

const C:uint = 4;

const D:uint = 8;

const E:uint = 16;

 

function orArgs(args:uint):void{

    if (args & A){

        trace("A");

    }

    if (args & B){

        trace("B");

    }

    if (args & C){

        trace("C");

    }

    if [...]

Posted in Math, Operators, binary, misc | Tagged , , , | 1 Comment

Bad PI Approximation

CLICK HERE TO COPY
Actionscript:

var inside:Number = 0

var precision:Number = 1000000;

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

       var xp:Number = 0.5 - Math.random();

       var yp:Number = 0.5 - Math.random();

       if (Math.sqrt(xp * xp + yp * yp) <0.5){

               inside++;

       }

}

trace(inside / precision [...]

Posted in Math | Tagged , , | 3 Comments