Coder Social home page Coder Social logo

webphysicengine's Introduction

Web Physic Engine

Web Physic Engine is a physic engine make in JavaScript for website. Test it on my website https://linuxhat.net/webPhysicEngine

How to Use

Config file

A config file is build like this for a simple gravity simulation :

/config.json

{
  "meterSize": 100,
  "speed": 1,
  "gravityX": 0,
  "gravityY": 9.81,
  "objects": {
    "obj1": {
      "type": "ball",
      "x": 50,
      "y": 200,
      "vx": 0,
      "vy": -200,
      "radius": 20,
      "color": "#0000FF",
      "mass": 10,
      "freeze": false,
      "restitution_coef": 0.8,
      "collision": true
    },
    "border1": {
      "type": "ball",
      "x": 0,
      "y": 800,
      "vx": 0,
      "vy": 0,
      "radius": 400,
      "color": "#FF0000",
      "mass": 100,
      "freeze": true,
      "restitution_coef": 0.5,
      "collision": true
    },
    "border2": {
      "type": "ball",
      "x": 800,
      "y": 800,
      "vx": 0,
      "vy": 0,
      "radius": 400,
      "color": "#FF0000",
      "mass": 100,
      "freeze": true,
      "restitution_coef": 0.5,
      "collision": true
    }
  }
}

Create you game with

Add your code in the main loop.
Exemple of a simple simulation with fps :

function mainLoop() {
  var fps = 1000 / (new Date().getTime() - Timer);
  document.getElementById("tps").innerText = fps.toFixed(0);
  updateObjectsPosition(objects);
  updateObjectsVelocity(objects);
  collideObjects(objects);
  Timer = new Date().getTime();
}

License

Photocasio © 2024 by Linux_Hat is licensed under
Attribution-NonCommercial-ShareAlike 4.0 International

Project maintained by Linux_Hat

webphysicengine's People

Contributors

linux0hat avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.