purescript-colors icon indicating copy to clipboard operation
purescript-colors copied to clipboard

Should we take short path in interpolateAngle?

Open safareli opened this issue 8 years ago • 6 comments

I came to this question lately when I saw gradient which was going over hue cycle 5 times here screen shot 2017-08-31 at 9 33 49 pm as we can't have similar scale because of the "short path" thing

safareli avatar Aug 31 '17 17:08 safareli

Well, using mixCubehelix, this should work, right?

Concerning mix, I'm not sure if it's a good idea. We would loose the symmetry mix a b n = mix b a (1 - n) (or similar :smile:).

sharkdp avatar Aug 31 '17 18:08 sharkdp

using custom interpolation function it will work. if a.hue = 0 and b.hue = 720 and interpolateAngle is just a linear interpolation then mix a b n = mix b a (1 - n) isn't it? how would we loose that symmetry

safareli avatar Aug 31 '17 20:08 safareli

True.

But we would certainly loose the ability to interpolate between two colors in the shortest possible way (in HSL space).

Right now:

> midpoint = mix HSL (hsl 10.0 1.0 0.5) (hsl 350.0 1.0 0.5) 0.5
> (toHSLA midpoint).h
360.0

If we would use normal linear interpolation, we would get a hue of 180°.

sharkdp avatar Aug 31 '17 21:08 sharkdp

Yes but is short path always desired?

If I want short path mix I would have done this: mix HSL (hsl 10.0 1.0 0.5) (hsl -10.0 1.0 0.5)

but by restricting to always use short path now i can't do mix HSL (hsl 10.0 1.0 0.5) (hsl 350.0 1.0 0.5) such it that it contains 180

safareli avatar Aug 31 '17 21:08 safareli

Good points.

This is pretty much the question whether we treat the HSL space as being periodic (in the hue-dimension) or as being infinite (also allowing multiple turns, as illustrated below).

One possible option could be to add a HSLNonPeriodic color space that would have the desired mix implementation.. not sure if that's a good idea ;-)

sharkdp avatar Aug 31 '17 21:08 sharkdp

btw if toHSLA returned unclipped hue, an if a.hue as 0 and b.hue 720 then short path found by current algorithm will have been { from: a + 360.0, to: b}.

not sure,

also in complementary = rotateHue 180.0 we might want to get same color if we do it twice but we wouldn't.

maybe we can add normalize function which clips hue to 360 range.

will think on it a bit more

safareli avatar Sep 01 '17 08:09 safareli