kantholtz / norne

A storytelling engine
MIT License
0 stars 0 forks source link

util.range #10

Open kantholtz opened 10 years ago

kantholtz commented 10 years ago

To have a (linear) range of values only defined by start and end value is not only a requirement for core.story.storyline but can also be applied to a bigger array of problems.

If this functionality gets implemented, gradients and randomized color values can easily be created in conjunction with #8

kantholtz commented 10 years ago

This would perfectly work with different objects that handle the actual interpolation. This could completely replace util.bezier, can be used by the character and physics-integration for the lanes ground information and makes working with color ranges easier.

The interface may look like this:


define('util.range.*')
  .as({

      // f(x) must be overwritten
      f: function (x) {
          // ...
      }

  });

/*
 *  The second parameter is one util.range.*
 */
var range = create('util.range', 'linear');

/*
 * Set delimiter. Not sure how to handle
 * non-set delimiter yet...
 */
range.start(0);
range.end(200);

/* 
 * simply retrieve f(20)
 * (which is 20 'linear')
 */
var y = range.get(20);

/*
 * The first parameter is the stepsize,
 * the second parameter the minimum threshold
 * between to consecutive y-values.
 *
 * Returns an array that contains f(x), where
 * x = 1, 2, 3, ..., 200
 * and
 * f(x) < f(x+1) - 5
 */ 
var seq = range.sequence(1, 5);

/** 
 *  Returns f(x) where x is a
 *  random value between 0 and 200.
 */
var rand = range.random();

// ...