All pastes #29311 Raw Edit

Stuff

public text v1 · immutable
#29311 ·published 2005-11-19 19:00 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);

);

);



//another working code: h s b are 0...1;


h=360*(h-floor(h));
hi=floor(h/60);
f=h/60-hi;
p=b*(1-s);
q=b*(1-(s*f));
t=b*(1-(s*(1-f)));
red=equal(hi,0)*b+equal(hi,1)*q+equal(hi,2)*p+equal(hi,3)*p+equal(hi,4)*t+equal(hi,5)*b;
blue=equal(hi,0)*p+equal(hi,1)*p+equal(hi,2)*t+equal(hi,3)*b+equal(hi,4)*b+equal(hi,5)*q;
green=equal(hi,0)*t+equal(hi,1)*b+equal(hi,2)*b+equal(hi,3)*q+equal(hi,4)*p+equal(hi,5)*p;