Author Archives: Zevan

Isometric Voxels

CLICK HERE TO COPY
Actionscript:

// isometric conversion

var centerX:Number=stage.stageWidth/2;

var centerY:Number=stage.stageHeight/2;

var theta:Number=Math.PI/4;// 45 degrees;

var cosX:Number=Math.cos(theta);

var sinX:Number=Math.sin(theta);

var pnt:Point = new Point();

function iso3D(x:Number, y:Number, z:Number):Point {

    pnt.x = centerX + (x-z) *  cosX

    pnt.y = centerY -  (x+z) * 0.5 * sinX - y;

    return pnt;

}

// example:

var canvas:BitmapData=new BitmapData(stage.stageWidth,stage.stageHeight,true,0xFF000000);

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

var size:int=100;

var hs:int=size / 2;

var pen:Point = new [...]

Posted in 3D, BitmapData, color, pixel manipulation, setPixel | Tagged , , , | 3 Comments

Blendmode Emboss

CLICK HERE TO COPY
Actionscript:

var canvas:BitmapData = new BitmapData(500, 500, true, 0xFFFFFFFF);

var color:BitmapData= new BitmapData(500, 500, true, 0x81666666);

var over:BitmapData = new BitmapData(500, 500, true, 0xFF000000);

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

var circle:Shape = new Shape();

circle.graphics.beginFill(0xFFFFFF,1);

circle.graphics.drawCircle(0,0,50);

var m:Matrix = new Matrix();

m.tx = 0;

m.ty = 1;

addEventListener(Event.ENTER_FRAME, onLoop);

function onLoop(evt:Event):void {

    circle.x = mouseX;

    circle.y = mouseY;

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

    canvas.copyPixels(color, [...]

Posted in Uncategorized | Tagged , | Leave a comment

Dynamic Vars Dictionary

CLICK HERE TO COPY
Actionscript:

var vars:Dictionary = new Dictionary();

 

var sp:Sprite = new Sprite();

 

// associate variables with a sprite (or any non-dynamic class)

vars[sp] = {posX:100, posY:100, velX:1, velY:1};

 

// read

trace(vars[sp].posX);

I've heard people mention that they wish the sprite class were dynamic... meaning they wish they could add methods and properties to a Sprite instance at runtime. There's no [...]

Posted in Dictionary, arrays, dynamic | Tagged , | 1 Comment

Transparent copyPixels()

CLICK HERE TO COPY
Actionscript:

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

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

addChild(new Bitmap(canvas));

var redOval:Shape = new Shape();

with(redOval.graphics) lineStyle(0,0), beginFill(0xFF0000), drawEllipse(0,0,10,50);

 

// draw a background to emphasize transparency

createBackground();

 

addEventListener(Event.ENTER_FRAME, onLoop);

 

function onLoop(evt:Event):void {

    // clear canvas so that it is completely transparent

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

    redOval.x = mouseX;

    redOval.y = mouseY;

    redOval.rotation += 10

    [...]

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