Giter Site home page Giter Site logo

flow-field.js's Introduction

flow-field

npm version

A library for generating flow fields.

Demo: Codesandbox Demo

Resources for learning more about flow fields and noise:

Table of contents

Usage

Install

npm

npm i @romellogoodman/flow-field

yarn

yarn add @romellogoodman/flow-field

unpkg

<script src="https://unpkg.com/@romellogoodman/flow-field"></script>

Use

JavaScript

import {generateField} from '@romellogoodman/flow-field';

const field = generateField({count: 100, height: 1000, width: 1000});

TypeScript

import {generateField} from '@romellogoodman/flow-field';
import type {Particle} from '@romellogoodman/flow-field';

const field = generateField({count: 100, height: 1000, width: 1000});

TypeScript

Particle is available for using in your sketches, with Line typings to come.

type Particle = {
  x: Number;
  y: Number;
  vx: Number;
  vy: Number;
  line: any[];
};

API

generateParticles

Creates the particles for a flow field.

  • @param {Number} count Number of particles in the field.
  • @param {Number} height Height of space.
  • @param {Number} margin Percent of height/width to create a padding.
  • @param {String} seed Random (random-js) seed.
  • @param {Number} width Width of space.
  • @return {Array} List of particle objects containing the starting x and y coordinates.

moveParticle

Computes the new position for a particle and adds it to the particle.line array.

  • @param {Number} amplitude Controls the range of values we get from the noise function.
  • @param {Number} damping Slows down the particle (think friction).
  • @param {Number} frequency Controls how quickly/slowly the noise function is "evolving over time".
  • @param {Number} lengthOfStep Amount to move the coordinate.
  • @param {Object} particle Particle object containing the.
  • @return {Void} Operates on the particle and returns nothing.

generateField

Creates a flow field with particles and lines.

  • @param {Number} amplitude Controls the range of values we get from the noise function. Default to 5.
  • @param {Number} count Number of particles in the field. Default to 1000.
  • @param {Number} damping Percentage that slows down the particle (think friction). Default to 0.1.
  • @param {Number} height Height of space.
  • @param {Number} margin Percent of height/width to create a padding. Default to 0.1.
  • @param {Object} particles List of particles to use instead of generating them.
  • @param {String} scale Used to compute frequency, number of steps and step length. Default to 1.
  • @param {String} seed Random (random-js) seed.
  • @param {Number} width Width of space.
  • @return {Array} List of particle objects containing the line coordinates.

Contributing

All contributors and all contributions both big and small are welcome in this project.

flow-field.js's People

Contributors

romellogoodman avatar joeyfigaro avatar

Watchers

James Cloos 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.