Interpolations

Here are all the interpolation functions included in Chelsea.js
Interpolation is a type of estimation, a method of constructing new data points based on the range of a discrete set of known data points.
In all the interpolation functions we use here, we provide a starting point, an ending point and estimate a number between them.

Linear Interpolation

Linear interpolation is the simplest method of getting values at positions in between the data points. The points are simply joined by straight line segments.

        
    lerp(start, end, amt)
    

Parameters

start Number : The starting point of the interpolation
end Number : The ending point of the interpolation
amt Number : The point at which the interpolation is t be calculated. 0 is start point, 1 is end point.

Examples

            
    for(i=0; i<WIDTH; i+=10){

        y=lerp(0,WIDTH,i/WIDTH);
        new point(i,HEIGHT-y,'#695fe6',4);

    }


Cosine Interpolation

Cosine Interpolation is almost like Linear Interpolation, but instead of joining the points by straight lines, it joins them by a modified cosine curve.

    
    cosrp(start, end, amt);

Parameters

start Number : The starting point of the interpolation
end Number : The ending point of the interpolation
amt Number : The point at which the interpolation is t be calculated. 0 is start point, 1 is end point.

Examples

        
    for(i=0; i<WIDTH; i+=10){

        y=cosrp(0,HEIGHT,i/WIDTH);
        new point(i,HEIGHT-y,'#695fe6',4);

    }
    

Smoothstep Interpolation

Smoothstep Interpolation is a sigmoid-like interpolation function. It is used to smooth the transition between two values. It uses Hermite polynomials to calculate the interpolation.

    
    smoothstep(start, end, amt);

Parameters

start Number : The starting point of the interpolation
end Number : The ending point of the interpolation
amt Number : The point at which the interpolation is t be calculated. 0 is start point, 1 is end point.

Examples

        
    for(i=0; i<WIDTH; i+=10){
    
        ic=clamp(i,0,1);
        y=smoothstep(0,WIDTH,i);
        
        new point(i,HEIGHT-HEIGHT*y,'#695fe6',4);
        
    }
    

Smootherstep Interpolation

Its understandable from the name, Its same as Smoothstep Interpolation, but it uses a different Hermite polynomial that is apparently smoother.

    
    smootherstep(start, end, amt);

Parameters

start Number : The starting point of the interpolation
end Number : The ending point of the interpolation
amt Number : The point at which the interpolation is t be calculated. 0 is start point, 1 is end point.

Examples

        
    for(i=0; i<WIDTH; i+=10){
    
        ic=clamp(i,0,1);
        y=smootherstep(0,WIDTH,i);
        
        new point(i,HEIGHT-HEIGHT*y,'#695fe6',4);
        
    }
    

Comparison of all Interpolation Functions