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])
  ; 



Monday, October 9, 2017

0 - 1 Remapping Functions: Map / BiSignMap / InfMap

/* remapping functions */


for(i=[-1:1/160:1])translate([bisignmap(i),0])square([1/160,  map(infmap(i*12) )   ]);

// Map takes a number in some range 
// and remaps it into the desired range
function  map(  value,istart=-1, istop=1, ostart=0, ostop=1) =
ostart + (ostop - ostart) * ((value - istart) / (istop - istart));

// BiSignMap takes a number in the range -1 - 1
// and remaps it into the range 0 - 1.
function bisignmap(i)=(i+1)/2;

// InfMap takes a number in the range -inf - inf
// and remaps it into the range -1 - 1 . 
function infmap(i)=max(0,1-(1/(abs(i)+1)))*sign(i);

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

Thursday, October 5, 2017

0 - 1 Remapping Functions: Power Smooth / Inverse Power Smooth

/* remapping functions */



for(i=[-0:1/160:1])translate([i,0])square([1/160,   ( (   powersmooth(i) )) ]);
     function powersmooth(x) =       ((x+ x-ipowersmooth(x))-0.5)*0.9+0.5 ;

for(i=[-0:1/160:1])translate([i,0])square([1/160,   ( (   ipowersmooth(i) )) ]);
    function ipowersmooth(x) =  clamp(pow(x-0.5,3)*4+0.5);
    function clamp(a, b = 0, c = 1) = min(max(a, b), c);
 


Tuesday, October 3, 2017

0 - 1 Remapping Functions: Powers 10 to -10

/* remapping functions */



for(i=[-0:1/160:1])translate([i,0])square([1/160,   ( (   power(i,10) )) ]);
     function power(x,n) = n<0?pow(x,1/abs(min(-1,n-1) )):pow(x,max(1,n+1))   ;


for(i=[-0:1/160:1])translate([i,0])square([1/160,   ( (   power(i,-10) )) ]);
     function power(x,n) = n<0?pow(x,1/abs(min(-1,n-1) )):pow(x,max(1,n+1))   ;
 


Sunday, October 1, 2017

0 - 1 Remapping Functions: Multiple Smooth Steps

/* remapping functions */


for(i=[-0:1/160:1])translate([i,0])square([1/160,   (smooths(  smooth(i),3 )) ]);
    function smooths(v,steps) =smooth( smooth(mods(v,steps) ))/steps+mstep(v,steps);
    function smooth (a) =let (b = clamp(a))(b * b * (3 - 2 * b));
    function clamp(a, b = 0, c = 1) = min(max(a, b), c);
    function mstep(v,steps=3) = (floor(v*steps)/steps );
    function mods(v,steps=3) = ( (v*steps)%1);