Skip to content

Instantly share code, notes, and snippets.

@jpg0
Created August 27, 2013 22:44
Show Gist options
  • Save jpg0/6360069 to your computer and use it in GitHub Desktop.
Save jpg0/6360069 to your computer and use it in GitHub Desktop.
Colours in Erlang
split_rgb(Count) ->
HueDelta = 1.0 / Count,
Hues = [HueDelta * Position || Position <- lists:seq(1, Count)],
lists:map(fun(Hue) -> convert_hsv_to_rgb(Hue, 0.8, 0.5) end, Hues).
convert_hsv_to_rgb({H, S, V}) ->
I = trunc(H * 6),
F = H * 6 - I,
P = V * (1 - S),
Q = V * (1 - F * S),
T = V * (1 - (1 - F) * S),
{R, G, B} = case I rem 6 of
0 -> {V, T, P};
1 -> {Q, V, P};
2 -> {P, V, T};
3 -> {P, Q, V};
4 -> {T, P, V};
5 -> {V, P, Q}
end,
{trunc(R * 255), trunc(G * 255), trunc(B * 255)}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment