cloop
A minimal frame loop library.
Last updated 2 months ago by conlanpatrek .
ISC · Original npm · Tarball · package.json
$ cnpm install cloop 
SYNC missed versions from official npm registry.

cloop

A minimal frame looper.

Installation

npm install cloop

Usage

import { loop } from 'cloop'

let target = {
  x: 100,
  y: 50
}

let particle = {
  pixelsPerSecond: 10,
  x: 0,
  y: 50
}

let cancel = cloop.loop(ms => {
  // Move the particle to the right towards the target
  particle.x = Math.min(
    particle.x + particle.pixelsPerSecond * ms / 1000,
    target.x
  )

  console.log(particle.x, particle.y)
  // If the particle has made it to the target, stop looping
  if (particle.x === target.x) {
    console.log('made it')
    cancel()
  }
})

Current Tags

  • 0.1.3                                ...           latest (2 months ago)

4 Versions

  • 0.1.3                                ...           2 months ago
  • 0.1.2                                ...           2 years ago
  • 0.1.1                                ...           2 years ago
  • 0.1.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 7
Dependencies (3)
Dev Dependencies (0)
None
Dependents (1)

Copyright 2014 - 2017 © taobao.org |