Thread: Showimg HSL
View Single Post
  #8  
Old 01-26-2014, 05:08 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
converted the link fp4 has been posting into gs2 for lazy people

PHP Code:
function onCreated() {
  echo(
rgb2hsl(2342550));
  echo(
hsl2rgb(19610050));
}


function 
rgb2hsl(rgb) {
  
temp.min(max(temp.r0), 255) / 255;
  
temp.min(max(temp.g0), 255) / 255;
  
temp.min(max(temp.b0), 255) / 255;
  
  
temp.max max(temp.rmax(temp.gtemp.b));
  
temp.min min(temp.rmin(temp.gtemp.b));
  
  
temp.temp.temp.= (temp.max temp.min) / 2;
  
  if (
temp.max != temp.min) {
    
temp.temp.max temp.min;
    
temp.= (temp.0.5 temp./ (temp.max temp.min) : temp./ (temp.max temp.min));
    if (
temp.max == temp.r)
      
temp.= (temp.temp.b) / temp.+ (temp.temp.0);
    else if (
temp.max == temp.g)
      
temp.= (temp.temp.r) / temp.2;
    else
      
temp.= (temp.temp.g) / temp.4;
    
temp./= 6;
  }
  else 
temp.temp.0//achromatic
  
  
return {temp.h*360,temp.s*100,temp.l*100};
}

function 
hsl2rgb(hsl) {
  
temp.min(max(temp.h0), 360) / 360;
  
temp.min(max(temp.s0), 100) / 100;
  
temp.min(max(temp.l0), 100) / 100;
  if (
temp.0) {
    
temp.= (temp.0.5 ? (temp.* (temp.s)) : (temp.temp.- (temp.temp.s)));
    
temp.= (temp.l) - temp.q;
    
    
temp.hue2rgb(temp.ptemp.qtemp.1/3);
    
temp.hue2rgb(temp.ptemp.qtemp.h);
    
temp.hue2rgb(temp.ptemp.qtemp.1/3);
  }
  else 
temp.temp.temp.1//achromatic
  
  
return {temp.r*255temp.g*255temp.b*255};
}
function 
hue2rgb(pqt) {
  if (
temp.0temp.+= 1;
  if (
temp.1temp.-= 1;
  
  if (
temp.1/6) return (temp.+ (temp.temp.p) * temp.t);
  if (
temp.0.5) return temp.q;
  if (
temp.2/3) return (temp.+ (temp.temp.p) * (2/temp.t) * 6);
  return 
temp.p;

__________________
MEEP!
Reply With Quote