cloop
A minimal frame loop library.
Last updated 7 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.5                                ...           latest (7 months ago)

6 Versions

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

Copyright 2014 - 2016 © taobao.org |