UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

50 lines (49 loc) 1.1 kB
"use strict"; import { NamedFunction2, NamedFunction4 } from "./_Base"; function _hsvToRgb(h, s, v, target) { const i = Math.floor(h * 6); const f = h * 6 - i; const p = v * (1 - s); const q = v * (1 - f * s); const t = v * (1 - (1 - f) * s); switch (i % 6) { case 0: target.r = v, target.g = t, target.b = p; break; case 1: target.r = q, target.g = v, target.b = p; break; case 2: target.r = p, target.g = v, target.b = t; break; case 3: target.r = p, target.g = q, target.b = v; break; case 4: target.r = t, target.g = p, target.b = v; break; case 5: target.r = v, target.g = p, target.b = q; break; } } export class colorSetRGB extends NamedFunction4 { static type() { return "colorSetRGB"; } func(color, r, g, b) { color.r = r; color.g = g; color.b = b; return color; } } export class hsvToRgb extends NamedFunction2 { static type() { return "hsvToRgb"; } func(hsv, target) { _hsvToRgb(hsv.x, hsv.y, hsv.z, target); return target; } }