Skip to content

Instantly share code, notes, and snippets.

@MortalFlesh
Last active October 17, 2019 11:49
Show Gist options
  • Save MortalFlesh/77b1e53ff2904856df89883de83d22d4 to your computer and use it in GitHub Desktop.
Save MortalFlesh/77b1e53ff2904856df89883de83d22d4 to your computer and use it in GitHub Desktop.
Mix of functions, helpers, ...
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