Code Monkey home page Code Monkey logo

sps.js's Introduction

Spring Particle Systems in Javascript

Synopsis

sps.js is a minimal & modular library for simulating particles on the cpu. In addition to core elements, like particles, springs, angular springs, it provides extensible behaviors aka "forces" (vortex, attraction, homing, etc), and physics solvers (Euler, Runge Kutta, and Verlet).

Code Example

Creating a particle system is as simple as:

var sps = require('sps');
var ParticleSystem = sps.ParticleSystem;
var Particle = sps.Particle;

var ps = new ParticleSystem();

for( var i = 0; i < 1000; i++ ) {
    var pos = [
      Math.random() * 2.0 - 1.0,
      Math.random() * 2.0 - 1.0,
      Math.random() * 2.0 - 1.0
    ];    
    var particle = ps.addParticle();
    particle.setPos( pos );     
}

To update the particle system we created above:

function update() {
  ps.update();
}

By default, there are no "behaviors" on the particle system. You can add some to the particle system by:

var sps = require("sps");

var homing = new sps.HomingBehavior();
homing.magnitude = 0.75;
ps.addBehavior( homing );

var damper = new sps.DamperBehavior();
damper.magnitude = 0.9;
ps.addBehavior( damper );

var attractor = new sps.AttractorBehavior();
attractor.magnitude = 2.0;
attractor.fallOff = 1.0;
ps.addBehavior( attractor );

To add a spring between two particles in the system:

var particles = ps.getParticles();
var p0 = particles[ 0 ];
var p1 = particles[ 1 ];
var s0 = new Spring( p0, p1, { length: 1, k: 2 } );

Note that you don't have to manage the spring. Internally the spring calls "addSpring" on the particle and gets attached to the particle.

Motivation

This library is part of a larger project / series of libraries that aspires to bring computational and parametric design to the web. This library aspires to be the particle simulation engine that enables all types of generative / computational design applications. My hope is that this library enables higher level computational design, form generation for 3d printing, cnc milling and laser cutting.

Build Requirements

node.js (4.4.0+) & npm

Installation

You can add this library to your project by running:

npm install --save https://github.com/YCAMInterlab/sps.js.git

or via npm:

npm install --save sps

Examples

See https://github.com/rezaali/webgl-sketches/tree/master/springs

Contribution

Copyright 2015-2016 Reza Ali co-developed by YCAMInterLab during the Guest Research Project v.3

License

Apache-2.0

sps.js's People

Contributors

rezaali avatar konnokeina avatar

Stargazers

Bharath Devalla avatar Paul G avatar Rob Sawyer avatar Ethan Priest avatar Alexander Rulkens avatar Fabio Dias Rollo avatar Philipp avatar 子龙 avatar Lucas Alberto avatar Yannick Assogba avatar  avatar AKA avatar  avatar Marshall Jones avatar Fábio Azevedo avatar Will Alpine avatar mactkg avatar

Watchers

Lucas Alberto avatar James Cloos avatar  avatar  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.