Git Product home page Git Product logo

easy-physics's Introduction

Easy-Physics

Easy Physics library for easily making physics based animations on the HTML5 Canvas!

Springs

alt text

Each letter will be propelled away from the mouse when it gets close to them, and they will spring back into place when the mouse leaves. You can choose the text, font, color, spring strength, and more!

Floating

alt text

Each letter is a solid object that floats in water. You can choose the letters, font, color, mass, liquid density, and more!

Flocking

alt text

It's a simple implementation of Reynolds' 1987 paper "Flocks, Herds, and Shcools: A Distributed Behavioral Model". It creates a flock of objects that move around. Those objects can be images, and you can tweak their behaviour.

Steering

alt text

Another implementation of a Reynold's paper: "Steering Behaviours for Autonomous Characters". There are 2 agents and a prize. Agent A tries to reach the prize while avoiding Agent B, whose goal is to reach Agent A. You can tweak their behaviour and decide which elements you want in the scene.

How to use

You can use Easy Physics as a Javascript library, but there is also a visual editor if you prefer.

Creating a simple Springs animation

Add a Canvas element to your HTML file:

<canvas id="EasyPhysics" width="480" height="360"></canvas>

Download the file EasyPhysics.js and add <script src="EasyPhysics.js"></script> to your HTML file before the </body> tag.

After that, add:

<script>
var canvas = document.getElementById("EasyPhysics");
var springsAnimation = new SpringsAnimation (canvas);

(function animationLoop()
{
   springsAnimation.draw();
   window.requestAnimationFrame (animationLoop);
})();
</script>

This will create an animation with the default parameters.

Customizing the Springs animation

You can create a settings object and pass it to springsAnimation before starting the animation loop:

<script>
var settings = [];
settings.text = "Hello, World!";
settings.font = "Times New Roman";

var canvas = document.getElementById("EasyPhysics");
var springsAnimation = new SpringsAnimation (canvas);
springsAnimation.initParams (false, settings);
springsAnimation.initSimulation(); //If you call initParams, you must call initSimulation after.

(function animationLoop()
{
   springsAnimation.draw();
   window.requestAnimationFrame (animationLoop);
})();
</script>

Check out the documentation for a full list of all the settings for each scene.

How to install

  1. Download the file EasyPhysics.js.
  2. Place the file in your website directory.
  3. Add <script src="EasyPhysics.js"></script> to your page, make sure it loads before the animation script.

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.