项目作者: vasturiano

项目描述 :
A multi-surface elastic collision force type for the d3-force simulation engine
高级语言: JavaScript
项目地址: git://github.com/vasturiano/d3-force-surface.git
创建时间: 2017-05-05T18:36:46Z
项目社区:https://github.com/vasturiano/d3-force-surface

开源协议:MIT License

下载


d3.forceSurface

NPM package
Build Size
NPM Downloads

A multi-surface elastic collision force type for the d3-force simulation engine.

It can be used, for example to @vasturiano/entropy">keep nodes within boundaries or in a @vasturiano/quad-pong">game of Pong.

See also d3.forceBounce.

Quick start

  1. import d3ForceSurface from 'd3-force-surface';

or using a script tag

  1. <script src="//cdn.jsdelivr.net/npm/d3-force-surface"></script>

then

  1. d3.forceSimulation()
  2. .nodes(<myNodes>)
  3. .force('surface', d3.forceSurface()
  4. .surfaces(<mySurfaces>)
  5. );

API reference

Method Description Default
surfaces([array]) Getter/setter for the list of surface lines []
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
from([fn]) Getter/setter for the surface object starting point accessor function fn(surface). It should return a two coordinate object: {x,y} surface.from
to([fn]) Getter/setter for the surface object ending point accessor function fn(surface). It should return a two coordinate object: {x,y} surface.to
oneWay([bool or fn]) Getter/setter for the surface object “one-way” flag accessor function (fn(surface)) or a constant for all surfaces. This flag indicates whether collisions of nodes against the surface should occur in both directions of movement or only in one (when the node is moving in a N>S orientation according to the W>E line axis), effectively ignoring collisions in the other direction. false
onImpact([fn]) Callback function triggered at every collision, with the signature onImpact(node, surface)

❤️ Support This Project

If you find this module useful and would like to support its development, you can buy me a ☕. Your contributions help keep open-source sustainable!
paypal