363{
364 float r = rgb[0];
365 float g = rgb[1];
366 float b = rgb[2];
367
370 float delta = maxVal - minVal;
371
372 float h = 0, s = 0, v = maxVal;
373
374 if (maxVal != 0)
375 s = delta / maxVal;
376
377 if (delta != 0)
378 {
379 switch (maxVal)
380 {
381 case r:
382 {
383 h = (g - b) / delta;
384 if (g < b)
385 h += 6;
386 }
387 break;
388 case g:
389 h = (b - r) / delta + 2;
390 break;
391 case b:
392 h = (r - g) / delta + 4;
393 break;
394 }
395 h = h / 6;
396 }
397
398 return Vector(h * 360, s, v);
399}
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
static proto float Max(float x, float y)
Returns bigger of two given values.
static proto float Min(float x, float y)
Returns smaller of two given values.