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

vector-field

v2.1.3

Published

A data structure and lookup for 3D vector fields (flow fields).

Downloads

62

Readme

vector-field

npm version stability-stable npm minzipped size dependencies types Conventional Commits styled with prettier linted with eslint license

A data structure and lookup for 3D vector fields (flow fields).

paypal coinbase twitter

See the example and its source.

Installation

npm install vector-field

Usage

import VectorField from "vector-field";

let time = 0;
const directionFn = ([x, y, z]) => {
  const n = myNoise4D(x, y, z, time);
  const theta = n;
  const phi = n;

  return [
    Math.sin(theta) * Math.cos(phi),
    Math.sin(theta) * Math.sin(phi),
    Math.cos(theta),
  ];
};
const vectorField = new VectorField(directionFn, [12, 6, 6], 1);

const frame = () => {
  time += 0.001;
  vectorField.update();
  requestAnimationFrame(frame);
};

requestAnimationFrame(() => {
  frame();
});

API

Classes

Typedefs

VectorField

A data structure and lookup for 3D vector fields (flow fields).

Kind: global class Properties

| Name | Type | | ----------- | -------------------------------------------------------------- | | directionFn | VectorFieldDirectionFn | | steps | vec3 | | bounds | vec3 | | halfBounds | vec3 | | field | Array.<VectorFieldCell> |

new VectorField(directionFn, [steps], [bounds])

Creates an instance of VectorField.

| Param | Type | Default | Description | | ----------- | -------------------------------------------------------------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | | directionFn | VectorFieldDirectionFn | | The custom function to compute the cell direction (often a noise function) | | [steps] | number | vec3 | 10 | The number of steps on each dimension (all positive integer). Use integer for identical dimensions. | | [bounds] | number | vec3 | 1 | The size of a containing box for the field. Is divided into steps for each dimension (all positive). Use integer for identical dimensions. |

vectorField.update()

Create/update the field according to the provided noise function.

Kind: instance method of VectorField

vectorField.lookup(cell) ⇒ VectorFieldCell | undefined

Find a VectorFieldCell at specified position. Useful to compute a particle's velocity for instance.

Kind: instance method of VectorField

| Param | Type | Description | | ----- | -------------------------- | ------------ | | cell | vec3 | [cx, cy, cz] |

vec3 : Array.<number>

Kind: global typedef

VectorFieldCell : object

Kind: global typedef Properties

| Name | Type | | --------- | -------------------------- | | position | vec3 | | direction | vec3 |

VectorFieldDirectionFn : function

The custom function to compute the cell direction (often a noise function)

Kind: global typedef

| Param | Type | | ------------ | -------------------------- | | position | vec3 | | stepPosition | vec3 |

License

MIT. See license file.