Author Archives: Zevan

2x mod 1 map

CLICK HERE TO COPY
Actionscript:

[SWF(width=800, height=600)]

var xn1:Number;

var xn:Number = Math.random() * Math.random() * .2;

var inc:int = 0;

var xp:Number = 10;

var yp:Number = 10;

var count:int = 1;

scaleX = scaleY = 2;

graphics.lineStyle(0,0x00000);

addEventListener(Event.ENTER_FRAME, onLoop);

function onLoop(evt:Event):void {

   

     xn1 = 2 * xn % 1;

     xn = xn1;

     if (inc == 0){

          [...]

Posted in Math, misc, motion | Tagged , , | Leave a comment

Math.random() * Math.random()

CLICK HERE TO COPY
Actionscript:

var rand:Number = Math.random() * Math.random() * Math.random();

This is a trick I use when I need more contrast in my random numbers. In this case, the variable rand will get closer to the number 1 significantly less frequently than if you just used Math.random() once.
To illustrate this I created this snippet:
CLICK [...]

Posted in one-liners, random | Tagged , , | 2 Comments

QuickBox2D Skinning

CLICK HERE TO COPY
Actionscript:

import com.actionsnippet.qbox.*;

 

var sim:QuickBox2D = new QuickBox2D(this);

 

sim.createStageWalls({lineAlpha:0,fillColor:0x000000})

sim.addBox({x:3, y:3, width:3, height:3, skin:BoxSkin});

sim.addCircle({x:3, y:8,radius:1.5,  skin:CircleSkin});

sim.addPoly({x:6, y:3, verts:[[1.5,0,3,3,0,3,1.5,0]], skin:TriangleSkin});

 

sim.addBox({x:6, y:3, width:3, height:3, skin:BoxSkin});

sim.addCircle({x:6, y:8,radius:1.5,  skin:CircleSkin});

sim.addPoly({x:12, y:3, verts:[[1.5,0,3,3,0,3,1.5,0]], skin:TriangleSkin});

 

sim.start();

sim.mouseDrag();

You'll need this fla to run this snippet since the graphics are in the library. This snippet shows how to easily use linkage classes as the graphics for your [...]

Posted in Box2D, MovieClip, QuickBox2D, motion | Tagged , , , , | 33 Comments

QuickBox2D groupIndex

CLICK HERE TO COPY
Actionscript:

import com.actionsnippet.qbox.*;

import Box2D.Common.Math.*;

 

stage.frameRate = 60;

 

var sim:QuickBox2D = new QuickBox2D(this);

 

sim.createStageWalls();

 

createTraveler(3, 3);

 

addObstacles();

 

function addObstacles():void{

    sim.setDefault({groupIndex:-1, density:0, height:0.4});

    sim.addBox({x:6, y:5, width:8, angle:0.17})

    sim.addBox({x:7, y:7.1, width:8, angle:-0.17})

    sim.addBox({x:5, y:9.1, width:8,  angle:0.10})

    sim.addBox({x:6, y:11.5, width:8.9,  angle:-0.20})

    sim.addBox({x:5.5, y:16, width:9, angle:0.20})

    sim.addBox({x:5.5, y:18, width:9})

    sim.addCircle({x:11, y:20, radius:2.5, groupIndex:1});

    sim.addBox({x:16, y:19, [...]

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