Author Archives: Zevan

Gesture Capture

CLICK HERE TO COPY
Actionscript:

var canvas:Shape = Shape(addChild(new Shape()));

var gestures:Array=[];

var gestureNum:int = 0;

var capGesture:Array;

stage.addEventListener(MouseEvent.MOUSE_DOWN, onDown);

stage.addEventListener(MouseEvent.MOUSE_UP, onUp);

function onDown(evt:MouseEvent):void{

     capGesture=[];

     addEventListener(Event.ENTER_FRAME, onCapture);

   

     canvas.graphics.lineStyle(3, 0xFF0000);

     canvas.x = mouseX;

     canvas.y = mouseY;

     canvas.graphics.moveTo(0, 0);

}

function onUp(evt:MouseEvent):void{

    gestures.push(capGesture.concat());

    gestureNum++;

     canvas.graphics.clear();

    removeEventListener(Event.ENTER_FRAME, onCapture);

}

function onCapture(evt:Event):void{

    capGesture.push(new Point(canvas.mouseX, canvas.mouseY));

    canvas.graphics.lineTo(canvas.mouseX, canvas.mouseY);

}

 

var [...]

Posted in Graphics, misc, motion | Tagged , , | Leave a comment

setVector() CA Texture

CLICK HERE TO COPY
Actionscript:

[SWF(width=500, height=500)]

var canvasSize:int=stage.stageWidth;

var canvas:BitmapData=new BitmapData(canvasSize,canvasSize,false,0x000001);

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

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

var pixels:Vector.<uint>=canvas.getVector(canvas.rect);

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

    var xp:int=int(Math.random()*canvasSize);

    var yp:int=int(Math.random()*canvasSize);

    pixels[xp+yp*canvasSize]=0xFF000000;

}

var targetCol:uint=0xFF000000;

var buffer:Vector.<uint>=pixels.concat();

var fade:uint=1;

 

addEventListener(Event.ENTER_FRAME, onLoop);

function onLoop(evt:Event):void {

    var curr:uint=targetCol;

    var r:int = (curr>> 16) & 0xFF;

    var g:int = (curr>> 8) & 0xFF;

  [...]

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

Bresenham’s Circle and setVector()

CLICK HERE TO COPY
Actionscript:

var canvasSize:int = 400;

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

addChild(new Bitmap(canvas));

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

var pixels:Vector.<uint> = canvas.getVector(canvas.rect);

 

addEventListener(Event.ENTER_FRAME, onLoop);

function onLoop(evt:Event):void {

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

      fillCircle(int(Math.random() * canvasSize),

                      int(Math.random() * canvasSize),

        [...]

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

2D Map Avoid

CLICK HERE TO COPY
Actionscript:

[SWF(width=401,height=401,background=0xEFEFEF)]

 

var w:Number = stage.stageWidth-1;

var h:Number = stage.stageHeight-1;

var tileSize:Number = 20;

var halfTileSize:Number = 20;

var hTiles:Number = w / tileSize;

var vTiles:Number = h / tileSize;

var world:Shape = Shape(addChild(new Shape()));

var map:Array=[];

populateMap();

var gridColor:uint = 0xCCCCCC;

grid(tileSize,  gridColor);

 

vTiles -= 1;

var movers:Array = [];

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

    movers.push(makeMover(i % hTiles, int( i / hTiles),0x000000))

    [...]

Posted in arrays, motion, random | Tagged , , | Leave a comment