This adds a "curve" section feature to the break-point-function (bpf) library. Note that the bias value must be a compile-time constant. I'd like to find a way to improve that. Demo:
os = library("oscillators.lib");
it = library("interpolators.lib");
ba = library("basics.lib");
if = ba.if;
bpf = environment
{
// Start a break-point function
start(x0,y0) = \(x).(x0,y0,x,y0);
// Add a break-point
point(x1,y1) = \(x0,y0,x,y).(x1, y1, x, if(x < x0, y, if(x < x1, y0 + (x-x0)*(y1-y0)/(x1-x0), y1)));
// End a break-point function
end(x1,y1) = \(x0,y0,x,y).(if(x < x0, y, if(x < x1, y0 + (x-x0)*(y1-y0)/(x1-x0), y1)));
// Add a curve-point. `B` (compile-time constant) must be in range (0,1]
curve(B,x1,y1) = \(x0,y0,x,y).(x1, y1, x, if(x < x0, y, if(x < x1, _curve_util(x0,x1,y0,y1,B,x), y1)));
// End with a curve-point. `B` (compile-time constant) must be in range (0,1]
curve_end(B,x1,y1) = \(x0,y0,x,y).(if(x < x0, y, if(x < x1, _curve_util(x0,x1,y0,y1,B,x), y1)));
/*
In the functions below, we use the equation `y=bias_curve(b,x)`.
* `b`: bias in range (0,1]. Bias of 0.5 results in `y=x`. Bias above 0.5 pulls y upward. Bias below 0.5 pulls y downward.
* `x`: input between 0 and 1 that needs to be remapped/biased into `y`
* `y`: `x` after it has been biased. Note that `(y==0 iff x==0) AND (y==1 iff x==1)`.
*/
_bias_curve(b,x) = (x / ((((1.0/b) - 2.0)*(1.0 - x))+1.0));
_curve_util(x0,x1,y0,y1,b,x) = y
with {
x_norm = (x-x0)/(x1-x0); // x_norm is in [0-1]
y_norm = _bias_curve(b, x_norm); // y_norm is in [0-1]
y = (1-y_norm)*y0 + y_norm*y1; // linear interpolation between y0 and y1
};
};
// bias = hslider("bias", 0.5, .0001, 1, .001) : si.smoo;
bias = 0.2;
// bias = 0.5;
// bias = 0.8;
f = bpf.start(0,0) : bpf.curve_end(bias,1,1);
// f = bpf.start(0,0) : bpf.curve(.15,.5,.5) : bpf.curve_end(.85,1,1);
process = os.lf_triangle(10) : it.remap(-1,1,0,1) : f;
This adds a "curve" section feature to the break-point-function (
bpf
) library. Note that thebias
value must be a compile-time constant. I'd like to find a way to improve that. Demo: