# spin method

Color spin(
1. Node color,
2. Dimension amount
)

Rotate the hue angle of a color in either direction. While the angle range is 0-360, it applies a mod 360 operation, so you can pass in much larger (or negative) values and they will wrap around angles of 360 and 720 will produce the same result. Note that colors are passed through an RGB conversion, which doesn't retain hue value for greys (because hue has no meaning when there is no saturation), so make sure you apply functions in a way that preserves hue, for example don't do this:

@c: saturate(spin(#aaaaaa, 10), 10%);

Do this instead: @c: spin(saturate(#aaaaaa, 10%), 10);

Colors are always returned as RGB values, so applying spin to a grey value will do nothing. Parameters: color: A color object. angle: A number of degrees to rotate (+ or -). Returns: color Example: spin(hsl(10, 90%, 50%), 30) spin(hsl(10, 90%, 50%), -30) Output: #f2a60d // hsl(40, 90%, 50%) #f20d59 // hsl(340, 90%, 50%)

## Implementation

//
/// Parameters:
///   color: A color object.
///   angle: A number of degrees to rotate (+ or -).
///   Returns: color
/// Example:
///   spin(hsl(10, 90%, 50%), 30)
///   spin(hsl(10, 90%, 50%), -30)
///   Output:
///     #f2a60d // hsl(40, 90%, 50%)
///     #f20d59 // hsl(340, 90%, 50%)
///
Color spin(Node color, Dimension amount) {
final hsl = toHSL(color);
final hue = (hsl.h + amount.value) % 360;

hsl.h = hue < 0 ? 360 + hue : hue;

return hslaColorSpace(color, hsl);

// 3.9.0 20190711
//  spin: function (color, amount) {
//    var hsl = toHSL(color);
//    var hue = (hsl.h + amount.value) % 360;
//
//    hsl.h = hue < 0 ? 360 + hue : hue;
//
//    return hsla(color, hsl);
//  },
}