In principle, what you’re looking for is an envelope, to modify the main wave. To simplify things, you can create a function that takes a linear value, and turns it into a curve.
Here’s a simple example:
function Easing( i ) {
i *= 2;
if (i<1) return 1/(2-i)-.5;
return 1.5-1/i;
};
If you feed this formula linearly with a value of 0
to 1
, will receive back a value also from 0
to 1
, only nonlinear.
What you need to do, in this case is take the amplitude of the main wave, and multiply by the result of the formula.
Here is a very basic example of use. The extensive code is for drawing the canvas, but what matters is just applying the formula:
function Easing( i ) {
i *= 2;
if (i<1) return 1/(2-i)-.5;
return 1.5-1/i;
};
//demonstração:
var canvas = document.getElementById("out");
var context = canvas.getContext("2d");
var width = canvas.width;
var height = canvas.height;
var data;
context.beginPath();
context.moveTo(0,height);
context.strokeStyle = 'red';
for(i=0; i<=100; i++)
{
data = i/100; //linear
context.lineTo(i/100*width,height-data*height);
context.stroke();
}
context.beginPath();
context.moveTo(0,height);
context.strokeStyle = 'blue';
for(i=0; i<100; i++)
{
data = Easing( i/100 ); //usando função
context.lineTo(i/100*width,height-data*height);
context.stroke();
}
#out {width:300px; height:200px; border:1px dotted #999}
<canvas id="out"></canvas>
Test also on CODEPEN.
Remember that jQuery itself has functions of easing
, that already make similar thing. Usually they are used for animations, but nothing prevents to apply in graphics:
https://jqueryui.com/easing/
This site has a number of formulas that may interest you:
http://www.gizma.com/easing/
If you can make a [mcve] or at least [Edit] your question and paste the code piece that generates the straight ramp, it is easier for us to help with the "easing" of the curve. There are several ways to do it, but it would help a lot from your existing code. It is worth noting that jQuery’s "easing" library (the same used for animations) is a good reference (and perhaps even the case of reuse). Basically these formulas use the ramp as input (from 0 to 1, for example), and return a logarithmic curve.
– Bacco
I edited my question. Please see the example code in fiddle https://jsfiddle.net/Yamamila/5zmxc5Lu/40/
– Camila Yamamoto