examples\control\Box2D\worlds\pendulum.ck
if(me.args() == 0)
{
    <<<"This script is intended for use by Box2D. Bailing...", me.id()>>>;
    1::second => now;
    me.exit();
}
// We use the first argument to find our Box2D context.
// checkout twitter:@pendulum_bot!

me.arg(0).toInt() => int boxId;
Box2D.Boxes[boxId] @=> Box2D boxO;
boxO.dbBox2D @=> DbBox2D box2D; // handle onto chugin

// define our world
#(0, 0) => complex zeroPt;
zeroPt => complex pPt;
3* #(-2.49, 3.15) => complex c1Pt; // distance from origin
3* #(-1.97, 1.42) => complex c2Pt;
4 => float w1;
2 => float w2;
.75 => float rad1; // aesthetic choice
rad1 * w2/w1 => float rad2;

15 => float density;

box2D.worldBegin(#(0, -10), true);  // gravity points down
20 => float h;
box2D.newEdge(#(-h, h), #(h, h)); // ceiling: p1, p2
box2D.newEdge(#(-h, -h), #(h, -h)); // floor: p1, p2

box2D.newCircle(pPt, .5, 0, box2D.staticType) => int pivot; // p, radius, density
box2D.newCircle(c1Pt, rad1, density, box2D.dynamicType) => int c1; // p, radius, density
box2D.newCircle(c2Pt, rad2, 2*density, box2D.dynamicType) => int c2; // p, radius, density
box2D.setRestitution(c2, 1.3);
box2D.newDistanceJoint(pivot, c1, pPt, c1Pt, 0, 0);
box2D.newDistanceJoint(c1, c2, c1Pt, c2Pt, 0, 0);
box2D.worldEnd();

<<<"pendulum created",  box2D.getNumBodies(), "bodies", rad1, rad2>>>;
home .. topics .. interface .. reference .. examples .. tipjar