Last active
October 17, 2019 11:49
-
-
Save MortalFlesh/77b1e53ff2904856df89883de83d22d4 to your computer and use it in GitHub Desktop.
Mix of functions, helpers, ...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Color = | |
/// Transform GUID into a color RGBA hex | |
let ofGuid (guid: Guid) = | |
let hash = function | |
| minimum when minimum <= 0 -> "00" | |
| maximum when maximum >= 255 -> "FF" | |
| number -> | |
match number.ToString("X") with | |
| short when short.Length < 2 -> sprintf "0%s" short | |
| hex -> hex | |
guid.GetHashCode() | |
|> System.Drawing.Color.FromArgb | |
|> fun color -> [ color.R; color.G; color.B; color.A ] | |
|> List.map (int >> hash) | |
|> String.concat "" | |
|> (+) "#" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment