Global.helma.Color.fromHsl (H, S, L)
transform a hsl representation of a color to the equivalent decimal value

  • Parameter Integer:
    the hue fraction
  • Parameter Integer:
    the saturation fraction
  • Parameter Integer:
    the lightness fraction
  • Returns
    Object the resulting color object note: this function is adapted from the HSLtoRGB conversion method as described at http://www1.tip.nl/~t876506/ColorDesign.html#hr (thanks!)
Sourcecode in /home/hannes/helma/modules/helma/Color.js:
132:   helma.Color.fromHsl = function(H,S,L) {
133:       function H1(H,S,L) {
134:           var R = 1; var G = 6*H; var B = 0;
135:           G = G*S + 1 - S; B = B*S + 1 - S;
136:           R = R*L; G = G*L; B = B*L;
137:           return [R,G,B];
138:       }
139:       
140:       function H2(H,S,L) {
141:          var R = 1-6*(H - 1/6); var G = 1; var B = 0;
142:          R = R*S + 1 - S; B = B*S + 1 - S;
143:          R = R*L; G = G*L; B = B*L;
144:          return [R,G,B];
145:      }
146:      
147:      function H3(H,S,L) {
148:          var R = 0; var G = 1; var B = 6*(H - 1/3);
149:          R = R*S + 1 - S; B = B*S + 1 - S;
150:          R = R*L; G = G*L; B = B*L
151:          return [R,G,B];
152:      }
153:      
154:      function H4(H,S,L) {
155:          var R = 0; var G = 1-6*(H - 1/2); var B = 1;
156:          R = R*S + 1 - S; G = G*S + 1 - S;
157:          R = R*L; G = G*L; B = B*L;
158:          return [R,G,B];
159:      }
160:      
161:      function H5(H,S,L) {
162:          var R = 6*(H - 2/3); var G = 0; var B = 1;
163:          R = R*S + 1 - S; G = G*S + 1 - S;
164:          R = R*L; G = G*L; B = B*L;
165:          return [R,G,B];
166:      }
167:      
168:      function H6(H,S,L) {
169:          var R = 1; var G = 0; var B = 1-6*(H - 5/6);
170:          G = G*S + 1 - S; B = B*S + 1 - S;
171:          R = R*L; G = G*L; B = B*L;
172:          return [R,G,B];
173:      }
174:      
175:      // H  [0-1] is divided into 6 equal sectors.
176:      // From within each sector the proper conversion function is called.
177:      var rgb;
178:      if (H < 1/6)        rgb = H1(H,S,L);
179:      else if (H < 1/3) rgb = H2(H,S,L);
180:      else if (H < 1/2) rgb = H3(H,S,L);
181:      else if (H < 2/3) rgb = H4(H,S,L);
182:      else if (H < 5/6) rgb = H5(H,S,L);
183:      else                  rgb = H6(H,S,L);
184:  
185:      return new Color(
186:          Math.round(rgb[0]*255),
187:          Math.round(rgb[1]*255),
188:          Math.round(rgb[2]*255)
189:      );
190:  }