Closed MichaelChirico closed 5 years ago
I think it's a simple implementation (on branch alpha
), and is only necessary where alpha
is a single value, since
colour_values(1:5, alpha = seq(0, 0.8, length.out = 5))
'just works' too.
However, what should colour_values(x, 1.0001)
return? Is this example a too nuanced edge-case?
@MichaelChirico If I were to implement this, should I change the accepted values of alpha from [0,255] to [1,256], so that it's more obvious that anything in [0,1] will be treated as a percentage?
@SymbolixAU I think no... only 1
is ambiguous since 0
is the same for both interpretations. And I think 0
should be 0
, not 1
...
Will come back to this again when I'm off vacation...
I've merged this into master in this commit, so now alpha is
optional. Single value in [0,255] applied to all colours, or a decimal in [0, 1) (to indicate a percentage, noting 1 is excluded), or a vector of numeric values the same length as x. The numeric vector will be scaled into the range [0,255]. If a matrix palette is supplied this argument is ignored.
I'm still not entirely 100% sure about this... and I don't know why...
Hopefully this is a case of the beauty of dynamically-typed languages... 😬
Thanks! Can't wait to give it a spin
On Mon, Jan 14, 2019 at 5:05 AM SymbolixAU notifications@github.com wrote:
Closed #37 https://github.com/SymbolixAU/colourvalues/issues/37 via 530a73a https://github.com/SymbolixAU/colourvalues/commit/530a73a245595bc7583e0707f3801ae127ebcb5d .
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/SymbolixAU/colourvalues/issues/37#event-2070718098, or mute the thread https://github.com/notifications/unsubscribe-auth/AHQQdT7ZhKu2s7hKjFRFoQF7TronTmffks5vC5-LgaJpZM4ZACbg .
I think it's more common for people to think of
alpha
as a percentage, so I think it's natural to expectcolourvalues(x, alpha = .5)
to "just work".From a design perspective, it's basically trivial to just detect fractions in
alpha
and multiply them by 255... simple truncation should be OK as I think the visual difference betweenalpha = 128
andalpha = 129
must be close to 0.Things get interesting at the edge cases like
alpha = c(0, 1, 1, 0)
... I guess very few people will be usingalpha = c(0, 1, 1, 0)
on the255
scale, so the logic to handle this requires some assumptions but I think they are pretty lightweight.I'm happy to implement this functionality as a PR if you see fit.