Author Archives: Zevan

QuickBox2D Tetris Pieces

CLICK HERE TO COPY
Actionscript:

import com.actionsnippet.qbox.*;

 

[SWF(backgroundColor=0x000000, width=700, height=600, frameRate=60)]

 

var sim:QuickBox2D = new QuickBox2D(this);

 

sim.setDefault({fillColor:0x003366, lineColor:0x2B80D5, isBullet:true});

sim.createStageWalls();

 

var shapes:Array = [];

shapes[0] = [[1,1,1,1]];

shapes[1] = [[1, 0, 0], [1, 1, 1]];

shapes[2] = [[0, 0, 1], [1, 1, 1]];

shapes[3] = [[1, 1], [1, 1]];

shapes[4] = [[0, 1, 1], [1, 1, 0]];

shapes[5] = [[0, 1, 0], [1, 1, 1]];

shapes[6] = [[1, 1, [...]

Posted in Box2D, QuickBox2D, misc | Tagged , , , | 3 Comments

Tetris Sand CA

CLICK HERE TO COPY
Actionscript:

stage.frameRate = 30;

scaleX = scaleY = 2.5;

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

addChild(new Bitmap(canvas));

var w:int = canvas.width;

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

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

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

 

read = canvas.getVector(canvas.rect);

var loc:int = 199*w;

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

       read[loc+i]=0xFFFFFFFF;

}

write = read.concat();

 

var shapes:Array = [];

shapes[0] = [[1,1],[1,1]];

shapes[1] = [...]

Posted in BitmapData, Vector, misc | Tagged , , | Leave a comment

Distance Line Gradient

CLICK HERE TO COPY
Actionscript:

[SWF(width=600,height=500,frameRate=30)]

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

addChild(new Bitmap(canvas));

 

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

var w:Number=canvas.width;

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

 

addEventListener(Event.ENTER_FRAME, onLoop);

function onLoop(evt:Event):void {

    canvas.lock();

       

    var i:int = size;

    var x1:Number=mouseX;

    var y1:Number=mouseY;

    var x2:Number=250;

    var y2:Number=250;

    var dx:Number=x2-x1;

    var dy:Number=y2-y1;

    var denom:Number =  1/(dx * dx + dy * [...]

Posted in BitmapData, Vector, graphics algorithms | Tagged , , | Leave a comment

Distance Between Point and Line (optimized)

CLICK HERE TO COPY
Actionscript:

/**

Original function by Pieter Iserbyt:

http://local.wasp.uwa.edu.au/~pbourke/geometry/pointline/DistancePoint.java

from Paul Bourke's website:

http://local.wasp.uwa.edu.au/~pbourke/geometry/pointline/

*/

function pointToLineDist(x1:Number, y1:Number, x2:Number, y2:Number,x3:Number, y3:Number):Number {

    var dx:Number=x2-x1;

    var dy:Number=y2-y1;

    if (dx==0&&dy==0) {

        x2+=1;

        y2+=1;

        dx=dy=1;

    }

    var u:Number = ((x3 - x1) * dx + (y3 - y1) * [...]

Posted in Math, graphics algorithms, misc | Tagged , , | 1 Comment