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

filtered-vector

v1.2.5

Published

Filter an input vector valued curve

Downloads

116,103

Readme

filtered-vector

Applies cubic smoothing to a vector valued curve. This is useful for smoothing out inputs from the mouse or other input devices.

Example

var now = require('right-now')
var filterVector = require('filtered-vector')
var smoothPosition = filterVector([256, 256])

var canvas = document.createElement('canvas')
canvas.width = 512
canvas.height = 512
document.body.appendChild(canvas)
var context = canvas.getContext('2d')

canvas.addEventListener('mousemove', function(ev) {
  smoothPosition.push(now(), ev.x, ev.y)
})

function paint() {
  requestAnimationFrame(paint)
  var t = now()
  context.fillStyle = 'rgba(0,0,0,1)'
  context.fillRect(0,0,512,512)
  
  context.strokeStyle = '#0f0'
  context.lineWidth = 1
  context.beginPath()
  var x = smoothPosition.curve(t)
  context.moveTo(x[0], x[1])
  for(var i=0; i<2000; ++i) {
    var y = smoothPosition.curve(Math.floor(t - i))
    context.lineTo(y[0], y[1])
  }
  context.stroke()
}
paint()

Try out the demo in your browser.

Install

npm i filtered-vector

API

Constructor

var vec = require('filtered-vector')(initState[, initVelocity, initTime])

Creates a new smoothed vector with the given initial state, velocity and time.

  • initState is the initial state of the vector
  • initVelocity is the initial velocity of the vector
  • initTime is the initial time of the vector

Returns A new smoothed vector valued curve

Methods

vec.curve(t)

Computes the value of the curve at time t

  • t is the time parameter to sample the curve

Returns The value of the curve at time t

vec.dcurve(t)

Computes the derivative of the curve at time t

  • t is the time parameter

Returns The derivative of the curve at time t

vec.bounds

A pair of arrays giving the upper and lower bounds on the constraints of the vector. Default is [-Infinity,-Infinity, ...] and [Infinity,Infinity,...]

vec.push(t, ...)

Adds a new data point onto the end of the curve

  • t is the time the new data point was sampled
  • ... are the components of the curve vector

vec.move(t, ...)

Incrementally moves the curve from the last sampled position by an offset. This is useful with input devices that emit relative motion (for example scrolling, key press events, pointer lock)

  • t is the time at which the move event occured
  • ... are the components of the relative motion

vec.set(t, ...)

Sets the state of the curve at time t

  • t is the time parameter to sample
  • ... are the components of the state

vec.jump(t, ...)

Sets the state of the vector at time t with no smoothing.

  • t is the time parameter to sample
  • ... are the components of the vector

vec.idle(t)

Adds a stationary data point to the curve (ie notify the curve that no input state has changed)

  • t is the time at which the curve was idle

vec.flush(t)

Removes all samples in the buffer before time t

  • t is the cutoff time

vec.lastT()

Returns The time of the last sample in the curve

vec.stable()

Returns true is the vector is stationary as of the last event.

License

(c) 2015 Mikola Lysenko. MIT License