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

morphr

v0.7.8

Published

Morphr - morphing numerical object values in a given time interval

Downloads

20

Readme

Morphr

Morphr is a tiny and lightweight javascript class for morphing numerical values of arbitrary, mostly plain javascript objects in a given time interval dt along a given range dval. Most often you will want to use it for animation. So it works excellently in combination with Html canvas.

Example

Morphr Example

(animated gif)
see example

<h1>Morphr Example</h1>
<canvas id="c" width="401" height="301"></canvas>
<script src='./g2.js'></script>
<script src='./morphr.js'></script>
<script>
// object value handlers ...
function value(obj,prop,dval) {
   var val0 = obj[prop];
   return function(q) { obj[prop] = val0 + q*dval; };
}
// render to canvas via g2 ..
function render() {
   g2().clr()
       .rec(rec.x,rec.y,rec.b,rec.h,{ls:"maroon",lw:2,fs:"transparent",ld:[4,4]})
       .exe(document.getElementById("c").getContext("2d"));
}
var rec = {x:100,y:100,b:20,h:100},               // plain javascript rectangle object ... 
    morphr = Morphr.create(4,0,"sinoid")          // create and configure Morphr object ...
                   .register(value(rec,"x",100))  // move along x-axis by 100 in 4 s.
                   .register(value(rec,"y",50))   // move along y-axis by 50 in 4 s.
                   .register(value(rec,"b",100))  // increase width by 100 in 4 s.
                   .register(value(rec,"h",-75))  // decrease height by 75 in 4 s.
                   .register(render)              // render to canvas.
                   .start();
</script>

Sequential morphing is easily achieved via multiple Morphr objects. DOM element attributes are morphable as well.

see sequential

Here is a more complex canvas based Crank-Rocker animation using a g2 command queue for vector graphics.

Maybe you want to learn a bit more about Crank-Rockers.

API Reference

Morphr is a tiny class for simultaneously morphing numerical object values in a given time interval. Use case is most often parameter animation of plain javascript objects. So it works excellently with canvas. Morphr depends on requestAnimationFrame.

Do not use new Morphr(), call Morphr.create() instead for creating instances.

Morphr.create([dt], [t0], [fn]) ⇒ object

Create a Morphr instance by start time, duration and timing function for morphing. A couple of predefined timing functions are available [s. VDI2143]:

  • linear
  • quadratic
  • sinoid
  • poly5

Kind: static method of Morphr
Returns: object - Morphr instance.

| Param | Type | Default | Description | | --- | --- | --- | --- | | [dt] | float | 2 | Duration in [s]. | | [t0] | float | 0 | Start time in [s] relative to first time call of start method. | | [fn] | function | string | "linear" | Timing function as function object or name of predefined function. |

morphr.register(hdl) ⇒ object

Register morphing handler function.

Kind: instance method of Morphr
Returns: object - this.

| Param | Type | Description | | --- | --- | --- | | hdl | function | Callback function hdl(q){}, where q is the - via fn - normalized time or the boolean value false to reset for a new start. |

morphr.start() ⇒ object

Start morphing process.

Kind: instance method of Morphr
Returns: object - this.

#Change Log

All notable changes to this project will be documented here. This project adheres to Semantic Versioning.

0.7.0 - 2016-03-27

First Commit to Github