variation

Description

Compute values that change with time (or some independent variable), using various transitions (immediate, linear, sigmoid) between values.

Features

A variety of transitions:

* immediate
* linear
* sigmoid (s-shaped)

Examples

require 'variation'
include Variation

p = Profile.new(
  :start_value => 1,
  :changes => {
    3 => ImmediateChange.new(:end_value => 3),
    5 => SigmoidChange.new(:end_value => 4, :length => 2),
    6 => LinearChange.new(:end_value => 1, :length => 1)
  }
)

# generate a function to calculate profile values
f = p.function
f.call(0) # should return 1
f.call(3 - 1e-5) # should return 1
f.call(3) # should return 3
f.call(4) # should return 3.5
f.call(5) # should return 4
f.call(5.5) # should return 2.5
f.call(6) # should return 1
f.call(99) # should return 1

Requirements

Install

$ gem install variation

Copyright © 2013 James Tunnell

See LICENSE.txt for details.