How to use planck-js - 6 common examples

To help you get started, we’ve selected a few planck-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github grtlr / bubble-treemaps / src / implementation / algorithm / layoutplanck.js View on Github external
function layoutClusters(layerClusters, centroid) {
    // Create world with zero gravity.
    let world = planck.World({
        gravity: planck.Vec2(0,0)
    });

    // Create bodies for groups.
    let layerClusterBodies = [];
    layerClusters.forEach(function(layerCluster) {
        layerClusterBodies.push(createClusterBody(layerCluster, world));
    });

    // Create attractor.
    let attractorBody = world.createBody(planck.Vec2(centroid.x, centroid.y));

    // Create joints between layerClusterBodies and attractor.
    layerClusterBodies.forEach(function(layerClusterBody) {
        let distanceJoint = planck.DistanceJoint( {
                frequencyHz : 0.9, // TODO: Try to avoid overlapping in large datasets!
                dampingRatio : 0.001 // TODO: ''
github grtlr / bubble-treemaps / src / implementation / algorithm / layoutplanck.js View on Github external
function layoutClusters(layerClusters, centroid) {
    // Create world with zero gravity.
    let world = planck.World({
        gravity: planck.Vec2(0,0)
    });

    // Create bodies for groups.
    let layerClusterBodies = [];
    layerClusters.forEach(function(layerCluster) {
        layerClusterBodies.push(createClusterBody(layerCluster, world));
    });

    // Create attractor.
    let attractorBody = world.createBody(planck.Vec2(centroid.x, centroid.y));

    // Create joints between layerClusterBodies and attractor.
    layerClusterBodies.forEach(function(layerClusterBody) {
        let distanceJoint = planck.DistanceJoint( {
                frequencyHz : 0.9, // TODO: Try to avoid overlapping in large datasets!
                dampingRatio : 0.001 // TODO: ''
            },
            attractorBody,
            attractorBody.getPosition(),
            layerClusterBody,
            layerClusterBody.getPosition()
        );
        distanceJoint.m_length = 0; // Set the length to zero as it's calculated as the distance between the anchors. TODO: PR on planck-js repo to fix bug.

        world.createJoint(distanceJoint);
    });
github grtlr / bubble-treemaps / src / implementation / algorithm / layoutplanck.js View on Github external
function layoutClusters(layerClusters, centroid) {
    // Create world with zero gravity.
    let world = planck.World({
        gravity: planck.Vec2(0,0)
    });

    // Create bodies for groups.
    let layerClusterBodies = [];
    layerClusters.forEach(function(layerCluster) {
        layerClusterBodies.push(createClusterBody(layerCluster, world));
    });

    // Create attractor.
    let attractorBody = world.createBody(planck.Vec2(centroid.x, centroid.y));

    // Create joints between layerClusterBodies and attractor.
    layerClusterBodies.forEach(function(layerClusterBody) {
        let distanceJoint = planck.DistanceJoint( {
                frequencyHz : 0.9, // TODO: Try to avoid overlapping in large datasets!
github grtlr / bubble-treemaps / src / implementation / algorithm / layoutplanck.js View on Github external
layerClusterBodies.forEach(function(layerClusterBody) {
        let distanceJoint = planck.DistanceJoint( {
                frequencyHz : 0.9, // TODO: Try to avoid overlapping in large datasets!
                dampingRatio : 0.001 // TODO: ''
            },
            attractorBody,
            attractorBody.getPosition(),
            layerClusterBody,
            layerClusterBody.getPosition()
        );
        distanceJoint.m_length = 0; // Set the length to zero as it's calculated as the distance between the anchors. TODO: PR on planck-js repo to fix bug.

        world.createJoint(distanceJoint);
    });
github grtlr / bubble-treemaps / src / implementation / algorithm / layoutplanck.js View on Github external
layerCluster.nodes.forEach(function(circle) {
        let centerGlobal = planck.Vec2(circle.x, circle.y);
        let centerLocal = centerGlobal.sub(bodyCentroid);
        let fixture = body.createFixture(planck.Circle(centerLocal, circle.r + circle.planckPadding), circleFD);
        fixture.setUserData(circle);
    });
github grtlr / bubble-treemaps / src / implementation / algorithm / layoutplanck.js View on Github external
layerCluster.nodes.forEach(function(circle) {
        let centerGlobal = planck.Vec2(circle.x, circle.y);
        let centerLocal = centerGlobal.sub(bodyCentroid);
        let fixture = body.createFixture(planck.Circle(centerLocal, circle.r + circle.planckPadding), circleFD);
        fixture.setUserData(circle);
    });

planck-js

2D JavaScript physics engine for cross-platform HTML5 game development

MIT
Latest version published 4 years ago

Package Health Score

62 / 100
Full package analysis