All pastes #29308 Raw Edit

hsl to rgb

public text v1 · immutable
#29308 ·published 2005-11-19 18:50 UTC
rendered paste body
//all in range 0-1
lum=0.5;
sat=d;
hue=r*invpi; 

if(bnot(sat),

red=lum;
blue=lum;
green=lum;

, //else

if(below(lum,0.5),
  temp2=lum*(sat+1)
,
  temp2=lum+sat-lum*sat
);

temp1=2*lum-temp2;

rgb=0;

loop(3,

  rgb=rgb+1;

  temp3 = if(equal(rgb,1),  hue+0.33333;  ,temp3);
  temp3 = if(equal(rgb,2),  hue;                 ,temp3);
  temp3 = if(equal(rgb,3),  hue-0.33333;  ,temp3);

  temp3=if(below(temp3,0),
    temp3+1,
    if(above(rtemp,1),
      temp3-1,
      temp3
    )
  );

  if( below(6*temp3,1) ,
    col=temp1+(temp2-temp1)*6*temp3;
  ,

    if(below(2*temp3,1) ,
      col=temp2;
    ,

      if(below(3*temp3,2) ,
        col=temp1+(temp2-temp1)*(0.66666-temp3)*6;
      ,
        col=temp1;
      );
    ); 
  );

  if(equal(rgb,1), red=col;   ,0);
  if(equal(rgb,2), green=col; ,0);
  if(equal(rgb,3), blue=col;  ,0);

);

);