purescript-contrib / purescript-colors

Convert, manipulate, analyze, blend, color scales, color schemes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Should we take short path in interpolateAngle?

safareli opened this issue · 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

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 😄).

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

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°.

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

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 ;-)

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