Showing posts with label step. Show all posts
Showing posts with label step. Show all posts

Wednesday, October 11, 2017

0 - 1 Remapping Functions: Compressor / Expander / Biramp

/* remapping functions */

v1=rnd();v2=rnd(); 

for(i=[-0:1/160:1])translate([i,0])square([1/160,  ((  comp(i,v1,v2)))]);
    function comp(i,c=0.5,s=0.75)=i<c? ramp(i,0,c,0,s) :ramp(i,c,1,s,1) ;
    function ramp(v,bi1=1/3,bi2=2/3,start=1/3, end=2/3) = 
        let(b1=min(bi1,bi2),b2=max(bi1,bi2))
        v<=b1?start:v<=b2?lerp(start,end,(v-b1)/(b2-b1))    :end;
     function lerp(start, end, bias) = (end * bias + start * (1 - bias));

function rnd(a = 1, b = 0, s = []) = 
  s == [] ? 
   (rands(min(a, b), max(   a, b), 1)[0]) 
  : 
   (rands(min(a, b), max(a, b), 1, s)[0])
  ; 



Saturday, October 7, 2017

0 - 1 Remapping Functions: Smooth Step 2

/* remapping functions */


for(i=[-0:1/160:1])translate([i,0])square([1/160,   ( (   smooth2(i) )) ]);
     function smooth2(x,k=5,n=4) =1- (exp( -k*pow(x,n) ));
 

Compared to smooth step

Friday, September 15, 2017

0 - 1 Remapping Functions: Step Ramp

/* remapping functions */

for(i=[-0:1/160:1])translate([i,0])square([1/160,   ( (  stepramp(i,bi1=1/5,bi2=4/5,start=1/3, end=2/3) )) ]);

function stepramp(v,bi1=1/5,bi2=4/5,start=1/3, end=2/3) = 
let(b1=min(bi1,bi2),b2=max(bi1,bi2))
v<=b1?ramp(v,0,b1,0,start):v<=b2?lerp(start,end,(v-b1)/(b2-b1))    :ramp(v,b2,1,end,1);

function ramp(v,bi1=1/3,bi2=2/3,start=1/3, end=2/3) = 
let(b1=min(bi1,bi2),b2=max(bi1,bi2))
v<=b1?start:v<=b2?lerp(start,end,(v-b1)/(b2-b1))    :end;


function lerp(start, end, bias) = (end * bias + start * (1 - bias));

 

Wednesday, September 13, 2017

0 - 1 Remapping Functions: Ramp

/* remapping functions */


for(i=[-0:1/160:1])translate([i,0])
        square([1/160, (ramp( (i),1/3,2/3,0.1)) ]);
function ramp(v,bi1=1/3,bi2=2/3,start=1/3, end=2/3) = 
        let(b1=min(bi1,bi2),b2=max(bi1,bi2))
        v<=b1?start:v<=b2?lerp(start,end,(v-b1)/(b2-b1))    :end;
function lerp(start, end, bias) = (end * bias + start * (1 - bias));
 

Thursday, September 7, 2017

0 - 1 Remapping Functions: Smooth Step

/* remapping functions */


for(i=[-0:1/160:1])translate([i,0])square([1/160, (smooth( (i),2/3,0.1))]);
    function smooth (a) =let (b = clamp(a))(b * b * (3 - 2 * b));
    function clamp(a, b = 0, c = 1) = min(max(a, b), c)
 

Sunday, September 3, 2017

0 - 1 Remapping Functions: Multi Step

/* remapping functions */


for(i=[-0:1/160:1])translate([i,0])square([1/160, (mstep( i,5))]);
    function mstep(v,steps=3) = (floor(v*steps)/steps );
 

Friday, September 1, 2017

0 - 1 Remapping Functions: Step

/* remapping functions */


for(i=[-0:1/160:1])translate([i,0])square([1/160, (step( (i),2/3,0.1))]);
    function step(v,bias,start=0, end=1) = v>=bias?end:start;