GithubHelp home page GithubHelp logo

andybui01 / d3-force-bounce Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vasturiano/d3-force-bounce

0.0 0.0 0.0 51 KB

Fork of vasturiano's force-bounce, with no velocity if node velocity zero.

License: MIT License

JavaScript 100.00%

d3-force-bounce's Introduction

d3.forceBounce

NPM package Build Size Dependencies

An elastic collision force type for the d3-force simulation engine.

This force is similar to d3.forceCollide, but allows for fully elastic collisions that conserve kinetic energy. This makes d3.forceCollide appropriate for preventing the overlap of nodes, and d3.forceBounce better suited when the intent is to achieve an elastic collision effect, with varying degrees of elasticity (coefficient of restitution).

Here's a visual comparison between the two forces.

It can be used, for example to simulate particle collisions or in a Newton's cradle.

See also d3.forceSurface.

Quick start

import d3ForceBounce from 'd3-force-bounce';

or

d3.forceBounce = require('d3-force-bounce');

or even

<script src="//unpkg.com/d3-force-bounce/dist/d3-force-bounce.min.js"></script>

then

d3.forceSimulation()
    .nodes(<myNodes>)
    .force('bounce', d3.forceBounce()
        .radius(5)   
    );

API reference

Method Description Default
elasticity([number]) Getter/setter for every collision's coefficient of restitution, aka elasticity. A value of 1 represents a purely elastic collision with no energy loss, while a 0 will fully eliminate the bounce in the collision direction. Values >1 can be used to introduce acceleration at each collision. Values <0 are not recommended. 1
radius([num or fn]) Getter/setter for the node object radius accessor function (fn(node)) or a constant (num) for all nodes. 1
mass([num or fn]) Getter/setter for the node object mass accessor function (fn(node)) or a constant (num) for all nodes. Mass affects the symmetry of the energy transfer between two colliding nodes. By default it is proportional to the node's area. Math.pow(radius(node), 2)
onImpact([fn]) Callback function triggered at every collision, with the signature onImpact(node1, node2)

Giving Back

paypal If this project has helped you and you'd like to contribute back, you can always buy me a โ˜•!

d3-force-bounce's People

Contributors

vasturiano avatar andybui01 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.