varying-0.1.4.0: Automaton based varying values, event streams and tweening.

Copyright(c) 2015 Schell Scivally
LicenseMIT
MaintainerSchell Scivally <schell.scivally@synapsegroup.com>
Safe HaskellNone
LanguageHaskell2010

Control.Varying.Tween

Contents

Description

Tweening is a technique of generating intermediate samples of a type between a start and end value. By sampling a running tween each frame we get a smooth animation of a value over time.

At first release varying is only capable of tweening numerical values of type (Fractional t, Ord t) => t that match the type of time you use. At some point it would be great to be able to tween arbitrary types, and possibly tween one type into another (pipe dreams).

Synopsis

Creating tweens

The standard way to start tweening values is to use tween along with an interpolation function such as easeInOutExpo. For example, tween easeInOutExpo 0 100 10, this will create an event stream that produces Event ts where t is tweened from 0 to 100 over 10 seconds. Once the 10 seconds are up, the stream will inhibit (produce NoEvent) forever. To create a stream of t that is tweened from 0 to 100 and then stays at 100 forever after requires you to use a combinator from the Event module, like so:

tween easeInOutExpo 0 100 10 `andThen` 100

The andThen combinator "disolves" our Events by switching to another stream once the first inhibits.

tween :: (Applicative m, Monad m, Fractional t, Ord t) => Easing t -> t -> t -> t -> Var m t (Event t) Source

Creates an event stream that produces an event value interpolated between a start and end value using an easing equation (Easing) over a duration. The resulting Var will take a time delta as input. For example:

testWhile_ isEvent v
   where v :: Var IO a (Event Double)
         v = deltaUTC ~> tween easeOutExpo 0 100 5

Keep in mind tween must be fed time deltas, not absolute time or duration. This is mentioned because the author has made that mistake more than once ;)

constant :: (Applicative m, Monad m, Num t, Ord t) => a -> t -> Var m t (Event a) Source

Interpolation functions

These pure functions take a c (total change in value, ie end - start), t (percent of duration completion) and b (start value) and result in and interpolation of a value. To see what these look like please check out http://www.gizma.com/easing/.

linear :: Num t => Easing t Source

Ease linear.

easeInCirc :: Floating t => Easing t Source

Ease in circular.

easeOutCirc :: Floating t => Easing t Source

Ease out circular.

easeInOutCirc :: (Ord t, Floating t) => Easing t Source

Ease in and out circular.

easeInExpo :: Floating t => Easing t Source

Ease in exponential.

easeOutExpo :: Floating t => Easing t Source

Ease out exponential.

easeInOutExpo :: (Ord t, Floating t) => Easing t Source

Ease in and out exponential.

easeInSine :: Floating t => Easing t Source

Ease in sinusoidal.

easeOutSine :: Floating t => Easing t Source

Ease out sinusoidal.

easeInOutSine :: Floating t => Easing t Source

Ease in and out sinusoidal.

easeInPow :: Num t => Int -> Easing t Source

Ease in by some power.

easeOutPow :: Num t => Int -> Easing t Source

Ease out by some power.

easeInOutPow :: (Fractional t, Ord t) => Int -> Easing t Source

Ease in and out by some power.

easeInCubic :: Num t => Easing t Source

Ease in cubic.

easeOutCubic :: Num t => Easing t Source

Ease out cubic.

easeInOutCubic :: (Ord t, Fractional t) => Easing t Source

Ease in and out cubic.

easeInQuad :: Num t => Easing t Source

Ease in quadratic.

easeOutQuad :: Num t => Easing t Source

Ease out quadratic.

easeInOutQuad :: (Ord t, Fractional t) => Easing t Source

Ease in and out quadratic.

Interpolation helpers

easeInOut :: (Ord t, Num t, Fractional t) => Easing t -> Easing t -> Easing t Source

Ease in and out using the given easing equations.

Writing your own tweens

type Tween m t = t -> t -> t -> Var m t (Event t) Source

A linear interpolation between two values over some duration. A Tween takes three values - a start value, an end value and a duration.

type Easing t = t -> t -> t -> t Source

An easing function. The parameters or often named c, t and b, where c is the total change in value over the complete duration (endValue - startValue), t is the current percentage of the duration that has elapsed and b is the start value.

To make things simple only numerical values can be tweened and the type of time deltas much match the tween's value type. This may change in the future :)