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

phsim

v0.3.0-alpha

Published

A matter-js library that allows one to easily create web simulations.

Downloads

7

Readme

phsim

PhSim (which stands for "Physics Simulator") is a library built by @mjduniverse that runs on top of Matter.js. PhSim allows one to easily create a physics simulation without much hassle. PhSim could be used to create games as well..

Demos

To get a clearer picture of what PhSim is and what it does, I have provided you demos. Here is an example of a PhSim simulation's code:

var o = {
    "objUniverse": [

        // Platform

        {
            "shape": "rectangle",
            "x": 25,
            "y": 528,
            "w": 749,
            "h": 47,
            "strokeStyle": "#0000ff",
            "lineWidth": 4,
            "fillStyle": "#333333",
            "locked": true
        },

        // Green rectangle

        {
            "shape": "rectangle",
            "x": 367,
            "y": 231,
            "w": 91,
            "h": 93,
            "strokeStyle": "#000000",
            "lineWidth": 4,
            "fillStyle": "#33cf33",
            "widgets": [
                {
                    "type": "keyboardControls",
                    "up": 10,
                    "down": 10,
                    "left": 10,
                    "right": 10
                }
            ]
        }
    ],
    "name": "Untitled Layer"
};

var phSim = new PhSim(o);

phSim.play();

To see it in action, you can view the demo here (it is the second simulation): https://mjduniverse.github.io/phsim/docs/tutorial-Creating%20PhSim%20Simulation.html

Installation

PhSim requires the libaries Matter.js and poly-decomp. Download them and then include them in your page. After doing that, look for a release to download. However, you could also download the bleeding edge build, which might be unstable.

After downloading it, you should include it into your desired HTML file. If you put the files in a directory named js, then include these tags in the html page:


<script src="./js/decomp.min.js"></script>
<script src="./js/matter.min.js"></script>
<script src="./js/phsim.min.js"></script>

If you are using PhSim in a project, including phsim.js instead might make it easier to develop, as it retains the JSDoc comments and the code is not minified.

In addition, the latest stable build is avaliable as an NPM module: https://www.npmjs.com/package/phsim. One can install PhSim by executing npm install phsim if they have NPM installed on their computer.

Some of the features:

Rendering

PhSim has a in-built renderer known as PhRender. It allows one to add gradients and sprites to objects. Sprites are stored in a catche object called PhSim.Sprites.spriteImgObj.

Widgets

A widget is something that extends the functionality of widgets and simulations. There are widgets that make objects undergo various forms of motion. The PhSim.Widgets namespace contains the built in widgets of the library. Here are some widgets that are built into the library:

  • Constraints: Constraints make objects constrained to an object or a point. They can be added using the constraint widget.

  • Circular Constraints: Circular Constraints can be added using the circularConstraints widget

  • Motion Widgets: Various forms of motion, such as rotation, velocity, position change, accelration, force and more can be triggered by widgets.

  • Audio: Audio can be played using the playAudio widget.

  • wFunctions: Special functions known as wFunctions that allow one to deal with events and time in an easier way.

  • Draggable Objects:: Objects can be dragged by the mouse using the draggable widget

Making games

One can create basic games on PhSim using the PhSim.Game object. The library provides widgets that make objects act as coins, health and hazards. However, one can build their own game engine if they do not like the in built one.