Author Archives: Zevan

Image Airbrush

CLICK HERE TO COPY
Actionscript:

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

 

// draw an ugly gradient

var size:int = 500;

var pixNum:int = size * size;

var gradient:BitmapData = new BitmapData(size, size, true, 0xFF000000);

 

gradient.lock();

var xp:int, yp:int;

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

    xp = i % size;

    yp = i / size;

    gradient.setPixel(xp, yp, (yp /= 2) <<16 | (255 [...]

Posted in BitmapData, setPixel | Tagged , | 2 Comments

Script List Pattern

CLICK HERE TO COPY
Actionscript:

var currentState:String = "";

 

var functionList:Vector.<Function> = new Vector.<Function>();

 

function clearFunctions():void{

    functionList = new Vector.<Function>();

}

function addFunction(f:Function):Function {

    functionList.push(f);

    return addFunction;

}

 

function removeFunction(f:Function):void {

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

        if (f == functionList[i]){

            functionList.splice(i, 1);

        }

    }

}

 

function [...]

Posted in Vector, arrays, misc | Tagged , | 2 Comments

BitmapData lock() & unlock()

CLICK HERE TO COPY
Actionscript:

var size:Number = 400;

var pixelNum:Number = size * size;

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

var r:uint;

var g:uint;

var b:uint;

 

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

addChild(new Bitmap(canvas));

 

addEventListener(Event.ENTER_FRAME, onLoop);

function onLoop(evt:Event):void {

 

    canvas.lock();

 

    // do any kind of pixel manipulation here:

   

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

        // draw a [...]

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

BitmapData Trails

CLICK HERE TO COPY
Actionscript:

[SWF(width=400, height=400, backgroundColor=0xCCCCCC, frameRate=30)]

 

var canvas:BitmapData = new BitmapData(400, 400, true, 0xCCCCCC);

var eraser:BitmapData = new BitmapData(400, 400, true, 0x22CCCCCC);

addChild(new Bitmap(canvas));

 

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

with (circle.graphics) beginFill(0x000000), drawCircle(0,0,20);

 

addEventListener(Event.ENTER_FRAME, onLoop);

 

function onLoop(evt:Event):void {

    canvas.copyPixels(eraser, eraser.rect, new Point(0,0), null, null, true);

    circle.x = mouseX;

    circle.y = mouseY;

   

    canvas.draw(circle, circle.transform.matrix);

}

Create trails by [...]

Posted in BitmapData, misc | Tagged , | 1 Comment