Author Archives: Zevan

XML Node Parents

CLICK HERE TO COPY
Actionscript:

function numParents(e:XML):int {

    var num:int = 0;

    while (e.parent()!= null) {

        num++;

        e = e.parent();

    }

    return num;

}

Sometimes when reading through XML it's helpful to know how many parents a given node has. This function will do that. I recently used this [...]

Posted in XML | Tagged , | Leave a comment

Web Cam

CLICK HERE TO COPY
Actionscript:

var cam:Camera =  Camera.getCamera();

var video:Video = new Video(320, 240);

video.attachCamera(cam);

addChild(video);

Adds the feed from your webcam to the stage.

Posted in Video | Tagged , | 1 Comment

BitmapData.setVector()

CLICK HERE TO COPY
Actionscript:

var canvas:BitmapData=new BitmapData(255,255,false,0x000000);

addChild(new Bitmap(canvas, "auto", true));

 

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

 

var pixels:Vector.<uint> = new Vector.<uint>(size);

 

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

    var ox:uint= i % canvas.width;

    var oy:uint= i / canvas.width;

    pixels[i] = oy <<16 | ox;

}

   

canvas.setVector(canvas.rect, pixels);

setVector() is used to set a group of pixels. [...]

Posted in BitmapData, Vector, pixel manipulation, setPixel | Tagged , | Leave a comment

Hidden Sierpiński

CLICK HERE TO COPY
Actionscript:

var canvas:BitmapData=new BitmapData(255,255,false,0x000000);

addChild(new Bitmap(canvas, "auto", true));

 

scaleX = scaleY = 1.5;

 

addEventListener(Event.ENTER_FRAME, onLoop);

function onLoop(evt:Event):void {

    for (var i:int  = 0; i<canvas.width * canvas.height; i++) {

        var ox:int= i % canvas.width;

        var oy:int= i / canvas.width;

        var col =  (ox | oy) * mouseX % [...]

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