Author Archives: Zevan

QuickBox2D Polys

CLICK HERE TO COPY
Actionscript:

import com.actionsnippet.qbox.*;

 

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

 

var sim:QuickBox2D = new QuickBox2D(this);

 

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

sim.createStageWalls();

 

var i:int = 0;

for (i= 0; i<10; i++){

  sim.addCircle({x:5 + i, y:7, radius:0.3, linearDamping:1, angularDamping:1, fillColor:0x78B4C2, isBullet:true}); 

}

 

for (i= 0; i<2; i++){

    var poly:Array = [];

    var r:Number = 3;

    var step:Number = Math.PI / 6;

    for (var t:Number = [...]

Posted in Box2D, QuickBox2D, motion | Tagged , | 7 Comments

Polygon Triangulation

CLICK HERE TO COPY
Actionscript:

var triangulate:Triangulate = new Triangulate();

 

var poly:Array=[];

 

stage.addEventListener(MouseEvent.MOUSE_DOWN, onDown);

function onDown(evt:MouseEvent):void {

    poly.push(new Pnt(mouseX, mouseY));

}

 

addEventListener(Event.ENTER_FRAME, onLoop);

function onLoop(evt:Event):void {

    var i:int;

    graphics.clear();

    var verts:Array=triangulate.process(poly);

 

    if (verts==null) {

        // draw a red polygon if there is some kind of error,

        // or if there are too [...]

Posted in 3D, Math, graphics algorithms, misc | Tagged , | 6 Comments

Odd Even Classic

CLICK HERE TO COPY
Actionscript:

// from http://www.bit-101.com/blog/?p=729

var number:Number = 10.5;

 

// for numbers

var isEven:Boolean = (number % 2) == 0;

trace(isEven);

 

// for ints

var integer:int = 10;

isEven = (integer & 1) == 0;

trace(isEven);

This is a classic that I've seen all over the place online... found myself needing it today and figured I should post it. It just an easy [...]

Posted in Math, Operators | Tagged , | Leave a comment

Difference Between Two Angles

CLICK HERE TO COPY
Actionscript:

// from http://codebase.dbp-site.com/code/find-difference-between-two-angles-25

function angleDifference(angle0:Number, angle1:Number):Number{

    return Math.abs((angle0 + 180 -  angle1) % 360 - 180);

}

 

trace("get the angle between:");

trace("350 and 10 =", angleDifference(350, 10));

trace("180 and -1 =", angleDifference(180, -1));

trace("-10 and 5 =", angleDifference(-10, 5));

trace("725 and -45 =", angleDifference(725, -45));

/* outputs:

get the angle between:

350 and 10 =  20

180 and -1 =  179

-10 and [...]

Posted in Math, misc, motion | Tagged , | 9 Comments