physics-engine

1.0.5 • Public • Published

physics-engine

Physics engine that I made with the stuff we learned in school

Used lots of trig functions and "Newton"s equations

Click to view old preview

Click to view new preview

Importing

Just add this to your HTML to import it!

<script src="https://unpkg.com/physics-engine"></script>

Example

Add a canvas to your body, so you can use it for rendering

<body>
    <canvas></canvas>
</body>

Initializing physics engine

<script>
    window.Phygic.then(Phygic => {
        // your code goes here!
        console.log("Phygic has been loaded! ", Phygic);
    });
</script>

Getting canvas

const canvas = document.querySelector("canvas");

Creating a physics world

Note: If you don't want the renderer you don't have to enter the canvas element

const world = new Phygic.World(canvas);

Rendering

Just run this function and done!

world.createAnimators();

Adding camera movement, tile dragging etc.

Again, just one line!

world.addHelpers();

Adding a box

Still one line!

new Phygic.Tile(50, 0, world);

Adding a static tile so our box doesn't fall to the nothingness

You get the idea everything is one line.

new Phygic.Tile(50, 500, {world, isStatic: true});

Final product:

Preview

<body>
    <canvas></canvas>
</body>
<script src="https://unpkg.com/physics-engine"></script>
<script>
    window.Phygic.then(Phygic => {
        const canvas = document.querySelector("canvas");

        const world = new Phygic.World(canvas);

        world.createAnimators();

        world.addHelpers();

        new Phygic.Tile(50, 0, world);
        
        new Phygic.Tile(50, 500, {world, isStatic: true});
    });
</script>

Package Sidebar

Install

npm i physics-engine

Weekly Downloads

1

Version

1.0.5

License

MIT

Unpacked Size

132 kB

Total Files

7

Last publish

Collaborators

  • oguzhanumutlu