Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@darkroom.engineering/elastica

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@darkroom.engineering/elastica

### ⚠️ Still in development mode - API might change ⚠️

  • 0.0.13
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
36
increased by3500%
Maintainers
0
Weekly downloads
 
Created
Source

Elastica

⚠️ Still in development mode - API might change ⚠️

Demo

Introduction

Elastica is a JavaScript library providing a physics engine for simulating elastic collision using Aligned axis bounding boxes (AABBs) and grid hash for efficient collision detection. It has a React wrapper which provides hooks and components for managing the state and interactions of your elements. Apply your own Cinematic equation for position and velocity of particles.

Installation

npm i @darkroom.engineering/elastica

Setup

import Elastica, {
  AxisAlignedBoundaryBox,
  initalConditionsPresets,
  updatePresets,
} from '@darkroom.engineering/elastica/react'

Elastica will wrap your component getting the dimensions for borders calculations and the grid size for collisions.

<Elastica
  config={{
    collisions: true,
    borders: 'rigid',
  }}
  initialCondition={initalConditionsPresets.random}
  update={updatePresets.dvdScreenSaver}
>
  {[{ name: 'DVD' }].map(({ name }, index) => (
    <AxisAlignedBoundaryBox key={index}>{name}</AxisAlignedBoundaryBox>
  ))}
</Elastica>

AxisAlignedBoundaryBox will wray your elements getting their size for collisions and positioning.

API

ReactElastica

PropTypeDefaultDescription
childrenReactNodeN/ARepresents the child elements or components rendered within the ReactElastica component. These elements are part of the elastic collision simulation.
classNamestringN/ASpecifies a CSS class for styling the ReactElastica container, allowing custom styling and theming.
showHashGridbooleanfalseShows the hash grid for measuing correct grid size.
configobjectSee belowConfiguration object controlling various aspects of the physics simulation.
└─ gridSizenumber8Defines the size of the hash grid, bigger grid reduces number of computation by collisions but should not be smaller than biggest element.
└─ collisionsbooleantrueEnables or disables collision detection between elements.
└─ bordersstring'rigid'Defines the border behavior. 'rigid' indicates immovable borders, preventing objects from passing through the container's edges. 'Periodic' translates elements to opposite border when reaching limit.
└─ containerOffsetsobjectSee belowSpecifies the offsets from the container's edges for the simulation area, allowing for padding or margins.
└── topnumber0Top offset.
└── bottomnumber0Bottom offset.
└── leftnumber0Left offset.
└── rightnumber0Right offset.
initialConditionfunction() => {}Function to set the initial conditions of the simulation, such as starting positions and velocities of elements. It is called once when the component mounts. Engine instance Class passed as props
updatefunction() => {}Callback function called on each simulation update, where cinematic equations have to be applied to each element. Engine instance Class passed as props.

Aligned Axis Boundary Box

PropTypeDefaultDescription
classNamestringN/ASpecifies a CSS class for styling the boundary box. This allows for custom styling of the container holding the children elements.
childrenReactNodeN/ARepresents the child elements or components that will be enclosed within the boundary box. These children are subject to the constraints of the boundary box.
...propsobjectN/AAdditional props that can be passed to the component. These props can include any other attributes or handlers needed for the custom behavior of the boundary box.

useElastica

Hook that exposes the Elastica instance and provides a set of functions for managing the simulation.

initalConditionsPresets

Object containing preset functions for setting initial conditions of the simulation.

updatePresets

Object containing preset functions for updating the simulation.


Examples

For more examples check demo github

Keywords

FAQs

Package last updated on 01 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc