Author Archives: Zevan

Utils3D.projectVectors() Lathe

CLICK HERE TO COPY
Actionscript:

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

var halfWidth:Number = stage.stageWidth / 2;

var halfHeight:Number = stage.stageHeight / 2;

var loc:Vector.<Number>;

 

graphics.lineStyle(0, 0xFF0000);

graphics.moveTo(halfWidth, 0);

graphics.lineTo(halfWidth, stage.stageHeight);

graphics.moveTo(0, halfHeight);

graphics.lineTo(stage.stageWidth, halfHeight);

 

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

line.x = halfWidth;

 

var idle:Function = function(){};

var currentMode:Function = idle;

stage.addEventListener(MouseEvent.MOUSE_DOWN, onDown);

stage.addEventListener(MouseEvent.MOUSE_UP, onUp);

addEventListener(Event.ENTER_FRAME, onLoop);

function onDown(evt:MouseEvent):void{

    if (contains(frame)){

        removeChild(frame);

        currentMode [...]

Posted in 3D, BitmapData, Math, Vector, graphics algorithms, matrix, setPixel | Tagged , , | 3 Comments

FileReference.load()

CLICK HERE TO COPY
Actionscript:

var txt:TextField = TextField(addChild(new TextField()));

txt.autoSize = TextFieldAutoSize.LEFT;

txt.x = txt.y = 20;

txt.text = "click anywhere to load an image file...";

 

var fileRef:FileReference= new FileReference();

stage.addEventListener(MouseEvent.MOUSE_DOWN, onDown);

function onDown(evt:MouseEvent):void{

    fileRef.browse([new FileFilter("Images", "*.jpg;*.gif;*.png")]);

    fileRef.addEventListener(Event.SELECT, onSelected);

    stage.removeEventListener(MouseEvent.MOUSE_DOWN, onDown);

}

function onSelected(evt:Event):void{

    fileRef.addEventListener(Event.COMPLETE, onLoaded);

    fileRef.load();

    fileRef.removeEventListener(Event.SELECT, onSelected);

}

function onLoaded(evt:Event):void{

    var loader:Loader = new Loader();

    loader.loadBytes(evt.target.data);

  [...]

Posted in external data, misc | Tagged , , | Leave a comment

Counter Function

CLICK HERE TO COPY
Actionscript:

var counter:Function = function(count:Array):Function{

    var leng:int = count.length;

    var index:int = 0;

    return counter = function(reset:*=""):Function{

        if (reset=="reset"){

            index = 0;

            return counter;

        }else

        if (reset is Array){

      [...]

Posted in dynamic, functions | Tagged , , | Leave a comment

Better BitmapData Brush

CLICK HERE TO COPY
Actionscript:

var canvas:BitmapData = new BitmapData(stage.stageWidth,stage.stageHeight,false, 0xCCCCCC);

addChild(new Bitmap(canvas));

var prevX:Number;

var prevY:Number;

var brush:Shape = new Shape();

 

stage.addEventListener(MouseEvent.MOUSE_DOWN, onDown);

stage.addEventListener(MouseEvent.MOUSE_UP, onUp);

function onDown(evt:MouseEvent):void{

    prevX = mouseX;

    prevY = mouseY;

    addEventListener(Event.ENTER_FRAME, onLoop);

}

 

function onUp(evt:MouseEvent):void{

    removeEventListener(Event.ENTER_FRAME, onLoop);

}

 

function onLoop(evt:Event):void {

      brush.x = mouseX;

      brush.y = mouseY;

      with (brush.graphics){

          clear();

  [...]

Posted in BitmapData, Graphics | Tagged , , | 1 Comment