0.1.5 • Published 5 years ago

cloop v0.1.5

Weekly downloads
10
License
ISC
Repository
-
Last release
5 years ago

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()
  }
})
0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago