npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

stam-stable-fluids

v1.0.3

Published

Real-Time Fluid Dynamics for Games, Jos Stam 2003

Downloads

6

Readme

Real-Time Fluid Dynamics for Games, Jos Stam 2003 [JS port]

This is a direct port from the C code presented in Stam's 2003 paper, with a small convenience wrapper.

Example:

const {Fluid} = require('stam-stable-fluids')
const size = 128
const f = new Fluid(size)
for (let y = 0; y < size; y++)
  for (let x = 0; x < size/2; x++)
    f.addDensity(x, y, 10)
for (let y = 0; y < size; y++)
  f.addForce(10, y, 10, 0)
f.step(1/60)

const [vx, vy] = f.velocityAt(0, 0)
const d = f.densityAt(0, 0)

API

new Fluid(size, viscosity = 0, diffusion = 0)

Make a new fluid simulation with width and height equal to size. If you want a goopier fluid, like honey, set viscosity to a small positive number, like 0.0001 (larger numbers will probably make the fluid so "thick" it will barely move). diffusion will make the "stuff" in the fluid spread out over time. The default for both viscosity and diffusion, if not provided, is 0.

Fluid.step(dt)

Step the simulation by dt (e.g. 1/60).

Fluid.velocityAt(x, y)

Returns [vx, vy] representing the velocity of the fluid at (x, y).

Fluid.densityAt(x, y)

Returns the density of "stuff" at (x, y).

Fluid.addForce(x, y, fx, fy)

Adds an external force to the fluid, e.g. from a UI or other system. The force field will be cleared after every step().

Fluid.addDensity(x, y, d)

Adds an external density flow to the fluid. d is the rate of flow. The density flow field will be cleared after every step().