* Converts a HSL color to RGB. Conversion formula adapted from * https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB_alternative. * * @returns An RGBColor object.
()
| 720 | * @returns An RGBColor object. |
| 721 | */ |
| 722 | private toRGB(): IColor { |
| 723 | let hue = this.hue; |
| 724 | let saturation = this.saturation / 100; |
| 725 | let lightness = this.lightness / 100; |
| 726 | let a = saturation * Math.min(lightness, 1 - lightness); |
| 727 | let fn = (n: number, k = (n + hue / 30) % 12) => |
| 728 | lightness - a * Math.max(Math.min(k - 3, 9 - k, 1), -1); |
| 729 | return new RGBColor( |
| 730 | Math.round(fn(0) * 255), |
| 731 | Math.round(fn(8) * 255), |
| 732 | Math.round(fn(4) * 255), |
| 733 | this.alpha |
| 734 | ); |
| 735 | } |
| 736 | |
| 737 | clone(): IColor { |
| 738 | return new HSLColor(this.hue, this.saturation, this.lightness, this.alpha); |