npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@p2-es/sandbox

v1.2.3

Published

A demo renderer for p2-es

Downloads

6

Readme

@p2-es/sandbox

@p2-es/sandbox is a demo renderer for p2-es.

Note: This library is in early development, releases may not follow semver. For now this is more of an implementation detail of the p2-es website demos than a library you should use in serious projects.

Installation

npm install @p2-es/sandbox

Usage

import { Sandbox } from '@p2-es/sandbox'
import * as p2 from 'p2-es'

const sandbox = new Sandbox(({ frame }) => {
    const enablePositionNoise = true // Add some noise in circle positions
    const N = 15 // Number of circles in x direction
    const M = 15 // and in y
    const r = 0.07 // circle radius
    const d = 2.2 // Distance between circle centers

    // Create the world
    const world = new p2.World({
        gravity: [0, -5],
    })

    // Set stiffness of all contacts and constraints
    world.setGlobalStiffness(1e8)

    // Max number of solver iterations to do
    world.solver.iterations = 20

    // Solver error tolerance
    world.solver.tolerance = 0.02

    // Enables sleeping of bodies
    world.sleepMode = p2.World.BODY_SLEEPING

    // Create circle bodies
    for (let i = 0; i < N; i++) {
        for (let j = M - 1; j >= 0; j--) {
            const x = (i - N / 2) * r * d + (enablePositionNoise ? Math.random() * r : 0)
            const y = (j - M / 2) * r * d
            const p = new p2.Body({
                mass: 1,
                position: [x, y],
            })
            p.addShape(new p2.Circle({ radius: r }))
            p.allowSleep = true
            p.sleepSpeedLimit = 1 // Body will feel sleepy if speed<1 (speed is the norm of velocity)
            p.sleepTimeLimit = 1 // Body falls asleep after 1s of sleepiness
            world.addBody(p)
        }
    }

    // Compute max/min positions of circles
    const xmin = (-N / 2) * r * d
    const xmax = (N / 2) * r * d
    const ymin = (-M / 2) * r * d
    const ymax = (M / 2) * r * d

    // Create bottom plane
    const plane = new p2.Body({
        position: [0, ymin],
    })
    plane.addShape(new p2.Plane())
    world.addBody(plane)

    // Left plane
    const planeLeft = new p2.Body({
        angle: -Math.PI / 2,
        position: [xmin, 0],
    })
    planeLeft.addShape(new p2.Plane())
    world.addBody(planeLeft)

    // Right plane
    const planeRight = new p2.Body({
        angle: Math.PI / 2,
        position: [xmax, 0],
    })
    planeRight.addShape(new p2.Plane())
    world.addBody(planeRight)

    // Frame demo
    frame(0, 0, 4, 4)

    return { world }
})

const domElement = document.querySelector('#app')
domElement.style.width = '100%'
domElement.style.height = '100vh'

sandbox.mount(domElement)