Function Signature
js
adjustHue(hex: string, degrees: number): stringParameters
hex(string): A HEX color string (e.g.,#ff6600).degrees(number): The number of degrees to rotate the hue. Can be positive or negative.
Return Value
Returns a HEX color string with the hue rotated by the specified degree value, always in the format #rrggbb.
js
adjustHue("#ff6600", 180);
// "#0099ff"
adjustHue("#00aaff", -90);
// "#aaff00"Examples
js
// Rotate hue by +120° (orange → green)
console.log(adjustHue("#ff6600", 120));
// "#66ff00"
// Rotate hue by -120° (orange → magenta)
console.log(adjustHue("#ff6600", -120));
// "#cc00ff"Implementation Details
- Converts the HEX input to RGB values using
hexToRgb. - Transforms RGB into HSL using
rgbToHsl. - Adjusts the hue by the given degree value and normalizes it with
mod360. - Converts back to RGB via
hslToRgb, then returns HEX withrgbToHex.
Usage Notes
- Hue rotation wraps around the color wheel, ensuring values remain within 0–360 degrees.
- Negative values rotate the hue counter-clockwise, positive values clockwise.
- Often used in generating complementary, triadic, or analogous color schemes.