Giter Club home page Giter Club logo

timingmanager's Introduction

TimingManager: A Library for Managing Animation Timing Information

Introduction

This JavaScript library is aimed to work in conjunction with the animaker package for R. For more information about the animaker package, a technical report describes it.

Note: Underscore is a required dependency.

It has three main responsibilities:

  • Import timing information and assign a unit to exported times.
  • Register actions to atomic animations (using JavaScript functions).
  • Play an animation sequence.

Importing Timing Information

To begin, we assume a JavaScript variable holds the relevant timing information necessary for TimingManager to work. In our example, this will be called timingData. We will first instantiate a new TimingManager instance.

var tm = new TimingManager(timingData, "s");

The first parameter is simply passing in the data, but the second is specifying that the exported data refers to time in seconds. Currently valid values are ms, s and m. The second parameter is optional, by default it is ms.

Registering Actions

When creating an animation sequence and timing information in R with animaker, we were not particularly concerned with the actions that an animation is supposed to take. We will now assign an action to atomic animation labelled "Alpha":

// Creating a simple action function
var alphaAction = function(info) {
    console.log("Alpha was called at " info.start + "s");
};

// Registering the action to the 'Alpha' atomic animation
tm.register({
    Alpha: alphaAction
});

Although this does not represent an animation (see D3), merely a simple logging function, the JavaScript function could do anything we like. In this case all the function does is print out its name and when it was called (in seconds).

Playing an Animation Sequence

Declarative Animation

Now that we have an action registered to our animation "Alpha", we can play it.

tm.play()

This simply plays the animation sequence, and if we observe the browser's console, we can see messages being printed out. This occurs once each time the atomic animation is called.

Frame-based Animation

In cases where we cannot use a library like D3 to perform animations for us, we may need to use a frame-based approach to animation. In this case we need to draw at regular intervals in time. Using HTML, a typical use case for this would be to create animations using the <canvas> element.

To perform a frame-based animation, we will use the frameApply method.

tm.frameApply(10);

The parameter that has been given here is the number of frames per second that the animation sequence is going to draw at. When we encounter the "Alpha" animation, the same animation function will be run 10 times for each second of its duration.

After calling the frameApply method, we should observe a lot more messages in the console than we get with the play method. The reason for this is because it is now being called every frame, rather than once for the atomic animation.

timingmanager's People

Contributors

sjp avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.