JavaScript Map Function with Interpolatable Curves (Composition by dust)

Author: dust
License: MIT
Date: 2010.03.26
Compatibility: 10.4, 10.5, 10.6
Categories:
Required plugins:
(none)

here is a javascript interpolator or mapping function. it doesn't have its own time base as this is just to scale numbers. so it will not generate but it does map. why do you need this if apple interpolator works fine. maybe your inquisitive like i am as i seem to do a lot of interpolating plus the curve feature is exposed so you can interpolate a curve overtime. does that make since interpolate your interpolator curve ?

well maybe you want ease out or in a little longer for a specific period of time or more or less than you can draw a cubic or quadratic curve etc... if you set the curve to zero it is linear. so ironically i'm using an interpolator to generate a range of 0-127 integers so i can map that range down to a -1 to 1 float range with some simple javascript logic based on powers of 10.

im thinking i will do a javascript smooth later with its own time base so it will smooth and generate numbers ? maybe a hermite interpolator or something is not in QC. paul bourke has lots of wonderful interpolation examples on his site is this stuff interests you.

PreviewAttachmentSize
f(map).qtz25.5 KB

usefuldesign.au's picture
Re: JavaScript Map Function with Interpolatable Curves ...

Hey dust, did you know you can output from the JS patch to an interpolator and then input the result of interpolator back into the JS patch. Kind of like an external map function call, but you can draw your own graph in the settings panel (or use std quad, cubic, sin with tension etc).

Can't remember what I used it for but I was exploring feedback amongst various patches and what happens when a patch eats-itself. TO use a PoP analogy.

dust's picture
Re: JavaScript Map Function with Interpolatable Curves ...

yeah i like doing recursive feedback functions as well. some people have a real hard time with recursion i found it easier to grasp than some other types of lets say sorting methods or graph traversals etc..

recursions funny look it up in the dictionary it says. "see recursion"

basically i explain recursion as finite components used to define an infinite statement defined within itself like this code.

well its late im being to lazy to check or compile this arbitrary function to make sure its infinite... if you have no idea whats going (see recursion) just kidding. this function is normally bad as it never hits its base.

x=3
 
f(x)
{
if(f(x)>f(x-1)){f(x+1)/f(x+1)}else{x+3}
}

if you still don't get see recursion.

that jokes only funny till someone gets it.

toneburst's picture
Re: JavaScript Map Function with Interpolatable Curves ...

dust wrote:
im thinking i will do a javascript smooth later with its own time base so it will smooth and generate numbers ? maybe a hermite interpolator or something is not in QC. paul bourke has lots of wonderful interpolation examples on his site is this stuff interests you.

Sounds intriguing. Looking forward to trying this later (and your Trackball one, too).

Paul Bourke is a Curves Guru- I've been mining his site for a couple of years now :D

a|x

usefuldesign.au's picture
Re: JavaScript Map Function with Interpolatable Curves ...

dust wrote:
recursions funny look it up in the dictionary it says. "see recursion"

I'll pay that, dust. Who's writing your material, dude?

I got a max call stack exceeded error in QC JS with that code btw!

function fun(x)
{
if(fun(x)>f(x-1)){f(x+1)/f(x+1)}else{x+3}
return x
}
 
x = 3;
function (__number X) main (__number inputNumber[2])
{
   var result = new Object();
   fun(x);
   result.X = x
   return result;
}

cybero's picture
Re: JavaScript Map Function with Interpolatable Curves ...

That's a nice script, here's how it works with some Mesh macros I whipped up.

They can be found in the Composition Repository.

Uses TaffGoch's GeorgeHart.dae

PreviewAttachmentSize
f_map_mesh_.qtz106.08 KB

dust's picture
Re: JavaScript Map Function with Interpolatable Curves ...

yeah that was me who wrote that. it was another recursion joke, as that code keeps pushing to the stack because it returns the same thing you put in meaning if x=recursion it returns recursion. QC says NO infinite loop stack overflow.

actually doing augmented or tail recursion sometimes forces the compiler to allocate constant heap space instead of stacking every iteration which qc js seems to like.

function recur(x,y)
{
  if (y == 0)
     return x;
  else
     return recur(y, x % y);
}
 
q = []
 
var x=1;
var y=3;
 
function (__number recursion, __structure iteration) main ()
{
   var result = new Object();
 
   q.push(recur(x,y))
   if (q.length > y) q.shift()
 
   result.recursion=recur(x,y);
   result.iteration=q;
 
 
   return result;
}

dust's picture
Re: JavaScript Map Function with Interpolatable Curves ...

yeah the geodesic model looks nice at first i plopped in a model of mr. brainwash i'm working on for a game and it didn't look as nice as the dome but did have a cool mesh x-ray. i have been meaning to investigate your new mesh files in the repository and comment. its not till this week that i'm working with some dae exports. actually i have been thinking about mesh iteration and hit testing lately as i have been using inertia momentum and forces as of late but want to see about making some sort of little physics engine rigid body kind of thing. so pretty soon once all my models are done i will be taking a closer look at your mesh iterations.